From 8ea91a6f16d52965dc02de030b10900fc471fc48 Mon Sep 17 00:00:00 2001 From: AllfatherHatt Date: Tue, 11 Mar 2025 15:46:55 +0100 Subject: [PATCH] Attempting to refactor list_allowed_roles out to permissions.py --- reginaldCog/permissions.py | 16 ++++++++++++++++ reginaldCog/reginald.py | 18 ++---------------- 2 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 reginaldCog/permissions.py diff --git a/reginaldCog/permissions.py b/reginaldCog/permissions.py new file mode 100644 index 0000000..b08dfce --- /dev/null +++ b/reginaldCog/permissions.py @@ -0,0 +1,16 @@ +from redbot.core import commands + +async def list_allowed_roles_logic(ctx): + """Handles the logic for listing allowed roles.""" + allowed_roles = await ctx.cog.config.guild(ctx.guild).allowed_roles() or [] + + # Ensure roles still exist in the server + valid_roles = [role_id for role_id in allowed_roles if ctx.guild.get_role(role_id)] + await ctx.cog.config.guild(ctx.guild).allowed_roles.set(valid_roles) + + if not valid_roles: + await ctx.send("⚠️ No roles are currently allowed to interact with Reginald.") + return + + role_mentions = [f"<@&{role_id}>" for role_id in valid_roles] + await ctx.send(f"✅ **Roles with access to Reginald:**\n{', '.join(role_mentions)}") diff --git a/reginaldCog/reginald.py b/reginaldCog/reginald.py index b69643b..34aa5dd 100644 --- a/reginaldCog/reginald.py +++ b/reginaldCog/reginald.py @@ -8,6 +8,7 @@ import traceback from collections import Counter from redbot.core import Config, commands from openai import OpenAIError +from permissions import list_allowed_roles_logic class ReginaldCog(commands.Cog): def __init__(self, bot): @@ -48,19 +49,7 @@ class ReginaldCog(commands.Cog): @commands.command(name="reginald_list_roles", help="List roles that can interact with Reginald.") @commands.has_permissions(administrator=True) async def list_allowed_roles(self, ctx): - allowed_roles = await self.config.guild(ctx.guild).allowed_roles() or [] - print(f"DEBUG: Retrieved allowed_roles: {allowed_roles}") # ✅ Print Debug Info - - valid_roles = [role_id for role_id in allowed_roles if ctx.guild.get_role(role_id)] - - await self.config.guild(ctx.guild).allowed_roles.set(valid_roles) # Save cleaned list - - if not valid_roles: - await ctx.send("⚠️ No roles are currently allowed to interact with Reginald.") - return - - role_mentions = [f"<@&{role_id}>" for role_id in valid_roles] - await ctx.send(f"✅ **Roles with access to Reginald:**\n{', '.join(role_mentions)}") + await list_allowed_roles_logic(ctx) async def is_blacklisted(self, user: discord.Member) -> bool: blacklisted_users = await self.config.guild(user.guild).blacklisted_users() @@ -273,9 +262,6 @@ class ReginaldCog(commands.Cog): ] return random.choice(reginald_responses) - - - def extract_topics_from_summary(self, summary): """Dynamically extracts the most important topics from a summary."""