added channel/user management commands

This commit is contained in:
Xargana 2025-05-09 21:53:48 +03:00
parent c5c0fcf187
commit c0d5dd5249
3 changed files with 190 additions and 1 deletions

View file

@ -8,6 +8,7 @@ from bot.commands.utility_commands import UtilityCommands
from bot.commands.fun_commands import FunCommands
from bot.commands.admin_commands import AdminCommands
from bot.commands.test_commands import TestCommands
from bot.commands.user_management_commands import UserManagementCommands
from utils.time_parser import parse_time
class MessageHandler:
@ -19,6 +20,7 @@ class MessageHandler:
self.fun_commands = FunCommands(bot)
self.admin_commands = AdminCommands(bot)
self.test_commands = TestCommands(bot)
self.user_management_commands = UserManagementCommands(bot)
# Attach command handlers to the bot for easier access from tests
bot.afk_commands = self.afk_commands
@ -26,6 +28,7 @@ class MessageHandler:
bot.fun_commands = self.fun_commands
bot.admin_commands = self.admin_commands
bot.test_commands = self.test_commands
bot.user_management_commands = self.user_management_commands
# Regex for detecting "in X time" patterns
self.time_pattern = re.compile(
@ -77,6 +80,12 @@ class MessageHandler:
if message.author.bot:
return
# Check if the channel is in ignored channels list and message is not from bot user
if (message.author != self.bot.user and
hasattr(self, 'user_management_commands') and
self.user_management_commands.is_channel_ignored(message.channel.id)):
return
# Look for and replace time patterns (only for non-command messages)
if not message.content.startswith('.'):
original_content = message.content
@ -131,8 +140,39 @@ class MessageHandler:
"""Handle commands issued by the bot user"""
content = message.content
# Check for custom commands first
if content.startswith('.'):
cmd = content.split()[0][1:] # Remove the '.' and get the command name
if hasattr(self.bot, 'loaded_commands') and cmd in self.bot.loaded_commands:
# Execute the custom command
try:
# Extract arguments from the command
args = content.split(' ')[1:] if ' ' in content else []
await self.bot.loaded_commands[cmd](self.bot, message, args)
return
except Exception as e:
print(f"Error executing custom command {cmd}: {e}")
await message.channel.send(f"Error executing command: {e}")
return
# User Management Commands
if content.startswith(".ignore"):
await self.user_management_commands.cmd_ignore(message)
elif content.startswith(".unignore"):
await self.user_management_commands.cmd_unignore(message)
elif content.startswith(".close"):
await self.user_management_commands.cmd_close(message)
elif content.startswith(".mute"):
await self.user_management_commands.cmd_mute(message)
elif content.startswith(".unmute"):
await self.user_management_commands.cmd_unmute(message)
elif content.startswith(".block"):
await self.user_management_commands.cmd_block(message)
elif content.startswith(".unblock"):
await self.user_management_commands.cmd_unblock(message)
# AFK Commands
if content.startswith(".afk"):
elif content.startswith(".afk"):
await self.afk_commands.cmd_afk(message)
elif content.startswith(".unafk"):
await self.afk_commands.cmd_unafk(message)