diff --git a/cogs/autoreact_cog.py b/cogs/autoreact_cog.py index a88e3ab..89b6417 100644 --- a/cogs/autoreact_cog.py +++ b/cogs/autoreact_cog.py @@ -17,17 +17,18 @@ async def react(self, ctx, user_ids: commands.Greedy[int], *emojis): for user_id in user_ids: if user_id not in self.user_reactions: self.user_reactions[user_id] = set() - self.user_reactions[user_id].update(emojis) - - await ctx.send(f"Auto-react enabled for users: {', '.join(map(str, user_ids))} with emojis: {', '.join(emojis)}") - - @commands.command(name='reactstop') - async def react_stop(self, ctx, user_id: int): - if user_id in self.user_reactions: - del self.user_reactions[user_id] - await ctx.send(f"Auto-react disabled for user: {user_id}") + if emojis: + self.user_reactions[user_id].update(emojis) + else: + if user_id in self.user_reactions: + del self.user_reactions[user_id] + await ctx.send(f"Auto-react disabled for user: {user_id}") + return + + if emojis: + await ctx.send(f"Auto-react enabled for users: {', '.join(map(str, user_ids))} with emojis: {', '.join(emojis)}") else: - await ctx.send(f"No auto-react found for user: {user_id}") + await ctx.send(f"No emojis provided. Auto-react disabled for users: {', '.join(map(str, user_ids))}") @commands.command(name='reactlist') async def react_list(self, ctx): diff --git a/cogs/help_cog.py b/cogs/help_cog.py index e26cc90..032c119 100644 --- a/cogs/help_cog.py +++ b/cogs/help_cog.py @@ -19,23 +19,27 @@ async def help_command(self, ctx, *input): return if not input: - # No input, show all categories and commands - help_message = "Help\nUse `{prefix}help ` to get more information on a category.\n\nCategories:\n" - for cog in self.bot.cogs: - help_message += f'`{cog}` {self.bot.cogs[cog].__doc__}\n' - await ctx.send(f"```{help_message}```") + await self.send_all_categories(ctx, prefix) elif len(input) == 1: - # One input, show commands in the category - cog = self.bot.get_cog(input[0]) - if cog: - help_message = f"{input[0]} - Commands\n{cog.__doc__}\n\n" - for command in cog.get_commands(): - help_message += f"`{prefix}{command.name}`: {command.help}\n" - await ctx.send(f"```{help_message}```") - else: - await ctx.send(f"Category `{input[0]}` not found.") + await self.send_category_commands(ctx, input[0], prefix) else: await ctx.send("Invalid input. Use `!help` to see all categories.") + async def send_all_categories(self, ctx, prefix): + help_message = "Help\nUse `{prefix}help ` to get more information on a category.\n\nCategories:\n" + for cog in self.bot.cogs: + help_message += f'`{cog}` {self.bot.cogs[cog].__doc__}\n' + await ctx.send(f"```{help_message}```") + + async def send_category_commands(self, ctx, category, prefix): + cog = self.bot.get_cog(category) + if cog: + help_message = f"{category} - Commands\n{cog.__doc__}\n\n" + for command in cog.get_commands(): + help_message += f"`{prefix}{command.name}`: {command.help}\n" + await ctx.send(f"```{help_message}```") + else: + await ctx.send(f"Category `{category}` not found.") + def setup(bot): bot.add_cog(HelpCog(bot)) diff --git a/cogs/reactstop_cog.py b/cogs/reactstop_cog.py deleted file mode 100644 index 829ca72..0000000 --- a/cogs/reactstop_cog.py +++ /dev/null @@ -1,21 +0,0 @@ -import discord -from discord.ext import commands - -class ReactStopCog(commands.Cog): - def __init__(self, bot): - self.bot = bot - - @commands.command(name='reactstop') - async def react_stop(self, ctx, user_id: int): - autoreact_cog = self.bot.get_cog('AutoReactCog') - if autoreact_cog: - if user_id in autoreact_cog.user_reactions: - del autoreact_cog.user_reactions[user_id] - await ctx.send(f"Auto-react disabled for user: {user_id}") - else: - await ctx.send(f"No auto-react found for user: {user_id}") - else: - await ctx.send("AutoReactCog is not loaded.") - -def setup(bot): - bot.add_cog(ReactStopCog(bot)) diff --git a/utils/command_handler.py b/utils/command_handler.py index 917cf59..4594012 100644 --- a/utils/command_handler.py +++ b/utils/command_handler.py @@ -45,11 +45,10 @@ def __init__(self): self.rate_limiter = RateLimiter() def load_cogs(self): - for filename in os.listdir('./cogs'): - if filename.endswith('.py'): - cog_name = filename[:-3] - cog_module = importlib.import_module(f'cogs.{cog_name}') - self.add_cog(cog_module.setup(self)) + cog_files = [f[:-3] for f in os.listdir('./cogs') if f.endswith('.py')] + for cog_name in cog_files: + cog_module = importlib.import_module(f'cogs.{cog_name}') + self.add_cog(cog_module.setup(self)) async def on_ready(self): print(f'Logged in as {self.user}') diff --git a/utils/database.py b/utils/database.py index 9f3fe00..f30f079 100644 --- a/utils/database.py +++ b/utils/database.py @@ -7,53 +7,35 @@ load_dotenv() -def connect_sqlite(): +def connect_database(db_type): try: - if os.getenv("LOCAL_DB_PATH"): + if db_type == "sqlite" and os.getenv("LOCAL_DB_PATH"): return sqlite3.connect(os.getenv("LOCAL_DB_PATH")) - except sqlite3.Error as e: - print(f"SQLite error: {e}") - return None - -def connect_mongodb(): - try: - if os.getenv("MONGODB_URI"): + elif db_type == "mongodb" and os.getenv("MONGODB_URI"): return pymongo.MongoClient(os.getenv("MONGODB_URI")) - except pymongo.errors.PyMongoError as e: - print(f"MongoDB error: {e}") - return None - -def connect_mysql(): - try: - if os.getenv("MYSQL_HOST"): + elif db_type == "mysql" and os.getenv("MYSQL_HOST"): return mysql.connector.connect( host=os.getenv("MYSQL_HOST"), user=os.getenv("MYSQL_USER"), password=os.getenv("MYSQL_PASSWORD"), database=os.getenv("MYSQL_DATABASE") ) - except mysql.connector.Error as e: - print(f"MySQL error: {e}") - return None - -def connect_redis(): - try: - if os.getenv("REDIS_HOST"): + elif db_type == "redis" and os.getenv("REDIS_HOST"): return redis.StrictRedis( host=os.getenv("REDIS_HOST"), port=os.getenv("REDIS_PORT"), password=os.getenv("REDIS_PASSWORD"), decode_responses=True ) - except redis.RedisError as e: - print(f"Redis error: {e}") + except (sqlite3.Error, pymongo.errors.PyMongoError, mysql.connector.Error, redis.RedisError) as e: + print(f"{db_type.capitalize()} error: {e}") return None def determine_database(): - local_db_conn = connect_sqlite() - mongo_client = connect_mongodb() - mysql_conn = connect_mysql() - redis_client = connect_redis() + local_db_conn = connect_database("sqlite") + mongo_client = connect_database("mongodb") + mysql_conn = connect_database("mysql") + redis_client = connect_database("redis") if not any([local_db_conn, mongo_client, mysql_conn, redis_client]): print("No external databases configured. Setting up a local database.")