112 lines
4.6 KiB
Python
112 lines
4.6 KiB
Python
import discord
|
|
import asyncio
|
|
from config import BLACKLISTED_USERS, BUCKET_REACT_USERS, AUTO_DELETE_USERS, SPECIAL_RESPONSES
|
|
from bot.commands.afk_commands import AfkCommands
|
|
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
|
|
|
|
class MessageHandler:
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
# Initialize command handlers
|
|
self.afk_commands = AfkCommands(bot)
|
|
self.utility_commands = UtilityCommands(bot)
|
|
self.fun_commands = FunCommands(bot)
|
|
self.admin_commands = AdminCommands(bot)
|
|
self.test_commands = TestCommands(bot)
|
|
|
|
# Attach command handlers to the bot for easier access from tests
|
|
bot.afk_commands = self.afk_commands
|
|
bot.utility_commands = self.utility_commands
|
|
bot.fun_commands = self.fun_commands
|
|
bot.admin_commands = self.admin_commands
|
|
bot.test_commands = self.test_commands
|
|
|
|
async def handle_message(self, message):
|
|
# Handle special responses
|
|
for user_id, data in SPECIAL_RESPONSES.items():
|
|
if message.author.id == user_id and data["trigger"] in message.content:
|
|
await message.reply(data["response"])
|
|
|
|
# Handle automatic reactions
|
|
if message.channel.id in self.bot.horsin:
|
|
await message.add_reaction("🐴")
|
|
|
|
if message.author.id in BUCKET_REACT_USERS:
|
|
await message.add_reaction("🪣")
|
|
|
|
# Handle auto-delete for specific users
|
|
if message.author.id in AUTO_DELETE_USERS:
|
|
try:
|
|
await message.delete()
|
|
except:
|
|
pass
|
|
|
|
# Handle DM if in AFK mode
|
|
if isinstance(message.channel, discord.DMChannel) and message.author != self.bot.user:
|
|
await self.afk_commands.handle_afk_dm(message)
|
|
|
|
# Don't process further if the message is not from the bot user
|
|
if message.author != self.bot.user:
|
|
return
|
|
|
|
# Handle commands
|
|
await self.handle_commands(message)
|
|
|
|
async def handle_blacklist(self, message):
|
|
"""Handle blacklisted users"""
|
|
if message.author.id in BLACKLISTED_USERS:
|
|
await message.reply("no")
|
|
return True
|
|
return False
|
|
|
|
async def handle_commands(self, message):
|
|
"""Handle commands issued by the bot user"""
|
|
content = message.content
|
|
|
|
# AFK Commands
|
|
if content.startswith(".afk"):
|
|
await self.afk_commands.cmd_afk(message)
|
|
elif content.startswith(".unafk"):
|
|
await self.afk_commands.cmd_unafk(message)
|
|
|
|
# Fun Commands
|
|
elif content.startswith(".horse"):
|
|
await self.fun_commands.cmd_horse(message)
|
|
elif content.startswith(".rps "):
|
|
if not await self.handle_blacklist(message):
|
|
await self.fun_commands.cmd_rps(message)
|
|
elif content.startswith(".repeat29"):
|
|
await self.fun_commands.cmd_repeat(message)
|
|
|
|
# Utility Commands
|
|
elif content.startswith(".remindme "):
|
|
if not await self.handle_blacklist(message):
|
|
await self.utility_commands.cmd_remindme(message)
|
|
elif content.startswith(".fmt "):
|
|
await self.utility_commands.cmd_fmt(message)
|
|
elif content.startswith(".eval "):
|
|
await self.utility_commands.cmd_eval(message)
|
|
elif content.startswith(".delrecent "):
|
|
await self.utility_commands.cmd_delrecent(message)
|
|
elif content.startswith(".nuke"):
|
|
await self.utility_commands.cmd_nuke_server(message)
|
|
elif content.startswith(".savechannel"):
|
|
await self.utility_commands.cmd_savechannel(message)
|
|
|
|
# Admin Commands
|
|
elif content.startswith(".addcmd "):
|
|
await self.admin_commands.cmd_addcmd(message)
|
|
elif content.startswith(".delcmd "):
|
|
await self.admin_commands.cmd_delcmd(message)
|
|
elif content.startswith(".listcmds"):
|
|
await self.admin_commands.cmd_listcmds(message)
|
|
elif content.startswith(".trackmessages"):
|
|
await self.admin_commands.cmd_trackmessages(message)
|
|
elif content.startswith(".untrackmessages"):
|
|
await self.admin_commands.cmd_untrackmessages(message)
|
|
elif content.startswith(".test"):
|
|
await self.test_commands.cmd_test(message)
|