Attempting to refactor list_allowed_roles out to permissions.py

This commit is contained in:
AllfatherHatt 2025-03-11 15:46:55 +01:00
parent c7dec31d5f
commit 8ea91a6f16
2 changed files with 18 additions and 16 deletions

View File

@ -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)}")

View File

@ -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."""