Initial commit v2 (token free)

This commit is contained in:
Xargana 2025-05-07 17:44:50 +03:00
parent 93235081ea
commit 0cd926b9a7
19 changed files with 1458 additions and 0 deletions

1
bot/handlers/__init__.py Normal file
View file

@ -0,0 +1 @@
# Empty init to make directory a package

View file

@ -0,0 +1,109 @@
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(".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)

View file

@ -0,0 +1,19 @@
import discord
from config import WELCOME_BACK_CHANNEL_ID
class PresenceHandler:
def __init__(self, bot):
self.bot = bot
async def handle_presence_update(self, before, after):
"""Handle user presence updates"""
if after.id == 627566973869359104:
old_status = self.bot.last_status.get(after.id, discord.Status.offline)
self.bot.last_status[after.id] = after.status
if old_status == discord.Status.offline and after.status == discord.Status.online:
channel = self.bot.get_channel(WELCOME_BACK_CHANNEL_ID)
if channel:
# Commented out for now as in original code
# await channel.send(f"[BOT] Welcome back, {after.mention}!", silent=True)
pass

View file

@ -0,0 +1,51 @@
import discord
import io
import difflib
class TrackingHandler:
def __init__(self, bot):
self.bot = bot
async def process_log_whitelist(self, message):
"""Process whitelist for logging"""
if message.author.id == 627566973869359104:
return True
return False
async def handle_message_delete(self, message):
"""Handle when messages are deleted"""
if await self.process_log_whitelist(message):
return
if message.channel.id in self.bot.tracked_channels:
member = message.author
if member != self.bot.user:
await message.channel.send(
f"<@{member.id}> deleted {message.content}",
silent=True
)
async def handle_message_edit(self, before, after):
"""Handle when messages are edited"""
if await self.process_log_whitelist(before):
return
if before.channel.id in self.bot.tracked_channels:
member = after.author
if member == self.bot.user:
return
if before.content == after.content:
return
diff = difflib.unified_diff(before.content.splitlines(), after.content.splitlines())
diff_result = '\n'.join(diff)
with io.BytesIO(diff_result.encode('utf-8')) as diff_file:
diff_file.seek(0)
await after.channel.send(
f"<@{member.id}> edited a message",
file=discord.File(diff_file, "cutie.diff"),
silent=True
)