65 lines
2.8 KiB
Python
65 lines
2.8 KiB
Python
![]() |
import os
|
||
|
from config import COMMANDS_DIR
|
||
|
from utils.storage import save_tracked_channels
|
||
|
|
||
|
class AdminCommands:
|
||
|
def __init__(self, bot):
|
||
|
self.bot = bot
|
||
|
|
||
|
async def cmd_addcmd(self, message):
|
||
|
"""Add a custom command"""
|
||
|
try:
|
||
|
parts = message.content.split(" ", 2)
|
||
|
if len(parts) < 3:
|
||
|
await message.reply("Usage: .addcmd <name> <code>", silent=True)
|
||
|
return
|
||
|
|
||
|
cmd_name, code = parts[1], parts[2]
|
||
|
cmd_path = os.path.join(COMMANDS_DIR, f"{cmd_name}.py")
|
||
|
|
||
|
with open(cmd_path, "w") as f:
|
||
|
f.write("async def run(msg):\n")
|
||
|
for line in code.split("\n"):
|
||
|
f.write(f" {line}\n")
|
||
|
|
||
|
self.bot.reload_commands()
|
||
|
await message.reply(f"Command {cmd_name} saved.", silent=True)
|
||
|
except Exception as e:
|
||
|
await message.reply(f"Error: {e}", silent=True)
|
||
|
|
||
|
async def cmd_delcmd(self, message):
|
||
|
"""Delete a custom command"""
|
||
|
cmd_name = message.content.split(" ", 1)[1]
|
||
|
cmd_path = os.path.join(COMMANDS_DIR, f"{cmd_name}.py")
|
||
|
|
||
|
if os.path.exists(cmd_path):
|
||
|
os.remove(cmd_path)
|
||
|
self.bot.reload_commands()
|
||
|
await message.reply(f"Command {cmd_name} deleted.", silent=True)
|
||
|
else:
|
||
|
await message.reply(f"Command {cmd_name} not found.", silent=True)
|
||
|
|
||
|
async def cmd_listcmds(self, message):
|
||
|
"""List all custom commands"""
|
||
|
cmds = list(self.bot.loaded_commands.keys())
|
||
|
await message.reply("Saved commands:\n" + ", ".join(cmds) if cmds else "No saved commands.", silent=True)
|
||
|
|
||
|
async def cmd_trackmessages(self, message):
|
||
|
"""Start tracking messages in the current channel"""
|
||
|
channel_id = message.channel.id
|
||
|
if channel_id not in self.bot.tracked_channels:
|
||
|
self.bot.tracked_channels.append(channel_id)
|
||
|
save_tracked_channels(self.bot.tracked_channels)
|
||
|
await message.reply(f"Tracking messages in this channel {message.channel.name}.", silent=True)
|
||
|
else:
|
||
|
await message.reply("This channel is already being tracked.", silent=True)
|
||
|
|
||
|
async def cmd_untrackmessages(self, message):
|
||
|
"""Stop tracking messages in the current channel"""
|
||
|
channel_id = message.channel.id
|
||
|
if channel_id in self.bot.tracked_channels:
|
||
|
self.bot.tracked_channels.remove(channel_id)
|
||
|
save_tracked_channels(self.bot.tracked_channels)
|
||
|
await message.reply(f"Stopped tracking messages in {message.channel.name}.", silent=True)
|
||
|
else:
|
||
|
await message.reply("This channel is not being tracked.", silent=True)
|