129 lines
4.1 KiB
Python
129 lines
4.1 KiB
Python
from bot.cogs.cog_manager import BaseCog
|
|
import discord
|
|
import os
|
|
import importlib.util
|
|
|
|
class AdminCog(BaseCog):
|
|
def __init__(self, bot):
|
|
super().__init__(bot)
|
|
self.bot = bot
|
|
# Initialize tracked channels if not already present
|
|
if not hasattr(self.bot, 'tracked_channels'):
|
|
self.bot.tracked_channels = []
|
|
|
|
async def cmd_addcmd(self, message):
|
|
"""
|
|
Add a custom command
|
|
Usage: .addcmd <name> <code>
|
|
"""
|
|
content = message.content.strip()
|
|
parts = content.split(None, 2)
|
|
|
|
if len(parts) < 3:
|
|
await message.edit(content="❌ Usage: `.addcmd <name> <code>`")
|
|
return
|
|
|
|
cmd_name = parts[1]
|
|
cmd_code = parts[2]
|
|
|
|
# Create commands directory if it doesn't exist
|
|
commands_dir = os.path.join("bot", "commands", "custom")
|
|
os.makedirs(commands_dir, exist_ok=True)
|
|
|
|
# Create command file
|
|
cmd_path = os.path.join(commands_dir, f"{cmd_name}.py")
|
|
|
|
with open(cmd_path, "w") as f:
|
|
f.write(f"""
|
|
async def run(bot, message, args):
|
|
\"\"\"
|
|
Custom command: {cmd_name}
|
|
\"\"\"
|
|
try:
|
|
{cmd_code.replace(chr(10), chr(10) + ' ' * 8)}
|
|
except Exception as e:
|
|
await message.channel.send(f"Error executing command: {{str(e)}}")
|
|
""")
|
|
|
|
# Reload commands
|
|
self.bot.reload_commands()
|
|
|
|
await message.edit(content=f"✅ Added command: `{cmd_name}`")
|
|
|
|
async def cmd_delcmd(self, message):
|
|
"""
|
|
Delete a custom command
|
|
Usage: .delcmd <name>
|
|
"""
|
|
content = message.content.strip()
|
|
parts = content.split()
|
|
|
|
if len(parts) != 2:
|
|
await message.edit(content="❌ Usage: `.delcmd <name>`")
|
|
return
|
|
|
|
cmd_name = parts[1]
|
|
|
|
# Check if command exists
|
|
commands_dir = os.path.join("bot", "commands", "custom")
|
|
cmd_path = os.path.join(commands_dir, f"{cmd_name}.py")
|
|
|
|
if not os.path.exists(cmd_path):
|
|
await message.edit(content=f"❌ Command `{cmd_name}` does not exist")
|
|
return
|
|
|
|
# Delete command
|
|
os.remove(cmd_path)
|
|
|
|
# Reload commands
|
|
self.bot.reload_commands()
|
|
|
|
await message.edit(content=f"✅ Deleted command: `{cmd_name}`")
|
|
|
|
async def cmd_listcmds(self, message):
|
|
"""
|
|
List all custom commands
|
|
Usage: .listcmds
|
|
"""
|
|
commands_dir = os.path.join("bot", "commands", "custom")
|
|
os.makedirs(commands_dir, exist_ok=True)
|
|
|
|
cmds = []
|
|
for filename in os.listdir(commands_dir):
|
|
if filename.endswith(".py"):
|
|
cmds.append(filename[:-3])
|
|
|
|
if not cmds:
|
|
await message.edit(content="No custom commands found.")
|
|
return
|
|
|
|
cmd_list = "\n".join(f"• {cmd}" for cmd in sorted(cmds))
|
|
await message.edit(content=f"**Custom Commands:**\n{cmd_list}")
|
|
|
|
async def cmd_trackmessages(self, message):
|
|
"""
|
|
Track message edits and deletions in a channel
|
|
Usage: .trackmessages
|
|
"""
|
|
channel_id = message.channel.id
|
|
|
|
if channel_id in self.bot.tracked_channels:
|
|
await message.edit(content="❌ This channel is already being tracked.")
|
|
return
|
|
|
|
self.bot.tracked_channels.append(channel_id)
|
|
await message.edit(content=f"✅ Now tracking message edits and deletions in <#{channel_id}>")
|
|
|
|
async def cmd_untrackmessages(self, message):
|
|
"""
|
|
Stop tracking message edits and deletions in a channel
|
|
Usage: .untrackmessages
|
|
"""
|
|
channel_id = message.channel.id
|
|
|
|
if channel_id not in self.bot.tracked_channels:
|
|
await message.edit(content="❌ This channel is not being tracked.")
|
|
return
|
|
|
|
self.bot.tracked_channels.remove(channel_id)
|
|
await message.edit(content=f"✅ No longer tracking message edits and deletions in <#{channel_id}>") |