diff --git a/.gitignore b/.gitignore index 0d4e151..ec13038 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ __pycache__/ *.py[cod] *$py.class +.ruff_cache/ # C extensions *.so @@ -148,7 +149,5 @@ cython_debug/ # Log file discord.log - cogs/media/files/ - logs.txt \ No newline at end of file diff --git a/bot.py b/bot.py index c55bfdb..2840600 100644 --- a/bot.py +++ b/bot.py @@ -1,11 +1,6 @@ -import asyncio -import json -import logging import os import platform import random -import signal -import sys import time import aiosqlite @@ -198,30 +193,6 @@ class DiscordBot(commands.Bot): except Exception as e: self.logger.error(f"Error during bot shutdown: {e}") - async def on_message(self, message: discord.Message) -> None: - if message.author == self.user or message.author.bot: - return - - if self.user in message.mentions: - try: - emoji_string = "" - self.logger.debug( - f"Attempting to react with PandaPing emoji: {emoji_string}" - ) - await message.add_reaction(emoji_string) - self.logger.debug("Successfully reacted with PandaPing emoji") - except Exception as e: - self.logger.debug(f"Failed to react with PandaPing emoji: {e}") - try: - self.logger.debug("Falling back to wave emoji") - await message.add_reaction("👋") - self.logger.debug("Successfully reacted with wave emoji") - except Exception as fallback_error: - self.logger.debug( - f"Failed to react with fallback emoji: {fallback_error}" - ) - await self.process_commands(message) - async def on_command_completion(self, context: Context) -> None: full_command_name = context.command.qualified_name split = full_command_name.split(" ") @@ -310,5 +281,5 @@ if __name__ == "__main__": bot.run(os.getenv("TOKEN")) except KeyboardInterrupt: pass - except: + except Exception: pass diff --git a/cogs/events/__init__.py b/cogs/events/__init__.py index 191c2b9..418d808 100644 --- a/cogs/events/__init__.py +++ b/cogs/events/__init__.py @@ -4,6 +4,7 @@ from discord.ext import commands from discord.ext.commands import Context from .baitbot import baitbot_command, BaitBotListener, has_protected_role +from .mention import MentionListener def _require_group_prefix(context: Context) -> bool: @@ -65,4 +66,8 @@ async def setup(bot) -> None: listener = BaitBotListener(bot) await bot.add_cog(listener) + mention_listener = MentionListener(bot) + await bot.add_cog(mention_listener) + bot.logger.info("Loaded extension 'events.baitbot'") + bot.logger.info("Loaded extension 'events.mention'") diff --git a/cogs/events/mention.py b/cogs/events/mention.py new file mode 100644 index 0000000..e3c5748 --- /dev/null +++ b/cogs/events/mention.py @@ -0,0 +1,41 @@ +import discord +import random +from discord.ext import commands + + +class MentionListener(commands.Cog): + def __init__(self, bot) -> None: + self.bot = bot + + @commands.Cog.listener() + async def on_message(self, message: discord.Message) -> None: + if message.author == self.bot.user or message.author.bot: + return + + if self.bot.user in message.mentions: + try: + emoji_options = [ + "", + "<:PandaPing2:1434998389451395224>", + "<:PandaPing3:1434998524696723466>", + ] + selected_emoji = random.choice(emoji_options) + self.bot.logger.debug( + f"Attempting to react with emoji: {selected_emoji}" + ) + await message.add_reaction(selected_emoji) + self.bot.logger.debug("Successfully reacted with mention emoji") + except Exception as e: + self.bot.logger.debug(f"Failed to react with mention emoji: {e}") + try: + self.bot.logger.debug("Falling back to wave emoji") + await message.add_reaction("👋") + self.bot.logger.debug("Successfully reacted with wave emoji") + except Exception as fallback_error: + self.bot.logger.debug( + f"Failed to react with fallback emoji: {fallback_error}" + ) + + await self.bot.process_commands(message) + +