development #1
@ -1,16 +1,45 @@
|
|||||||
from redbot.core import commands
|
from redbot.core import commands
|
||||||
|
import discord
|
||||||
|
|
||||||
async def list_allowed_roles_logic(ctx):
|
class PermissionsMixin:
|
||||||
"""Handles the logic for listing allowed roles."""
|
"""Handles role-based access control for Reginald."""
|
||||||
allowed_roles = await ctx.cog.config.guild(ctx.guild).allowed_roles() or []
|
|
||||||
|
|
||||||
# Ensure roles still exist in the server
|
@commands.command(name="reginald_list_roles", help="List roles that can interact with Reginald.")
|
||||||
valid_roles = [role_id for role_id in allowed_roles if ctx.guild.get_role(role_id)]
|
@commands.has_permissions(administrator=True)
|
||||||
await ctx.cog.config.guild(ctx.guild).allowed_roles.set(valid_roles)
|
async def list_allowed_roles(self, ctx: commands.Context):
|
||||||
|
"""Lists all roles that are allowed to interact with Reginald."""
|
||||||
|
allowed_roles = await self.config.guild(ctx.guild).allowed_roles() or []
|
||||||
|
|
||||||
if not valid_roles:
|
# Ensure all roles still exist in the server
|
||||||
await ctx.send("⚠️ No roles are currently allowed to interact with Reginald.")
|
valid_roles = [role_id for role_id in allowed_roles if ctx.guild.get_role(role_id)]
|
||||||
return
|
if valid_roles != allowed_roles: # Update config only if there's a difference
|
||||||
|
await self.config.guild(ctx.guild).allowed_roles.set(valid_roles)
|
||||||
|
|
||||||
role_mentions = [f"<@&{role_id}>" for role_id in valid_roles]
|
if not valid_roles:
|
||||||
await ctx.send(f"✅ **Roles with access to Reginald:**\n{', '.join(role_mentions)}")
|
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)}")
|
||||||
|
|
||||||
|
@commands.command(name="reginald_allowrole", help="Grant a role permission to interact with Reginald.")
|
||||||
|
@commands.has_permissions(administrator=True)
|
||||||
|
async def allow_role(self, ctx: commands.Context, role: discord.Role):
|
||||||
|
"""Grants a role permission to interact with Reginald."""
|
||||||
|
async with self.config.guild(ctx.guild).allowed_roles() as allowed_roles:
|
||||||
|
if role.id not in allowed_roles:
|
||||||
|
allowed_roles.append(role.id)
|
||||||
|
await ctx.send(f"✅ Role **{role.name}** has been granted access to Reginald.")
|
||||||
|
else:
|
||||||
|
await ctx.send(f"⚠️ Role **{role.name}** already has access.")
|
||||||
|
|
||||||
|
@commands.command(name="reginald_disallowrole", help="Revoke a role's access to interact with Reginald.")
|
||||||
|
@commands.has_permissions(administrator=True)
|
||||||
|
async def disallow_role(self, ctx: commands.Context, role: discord.Role):
|
||||||
|
"""Revokes a role's permission to interact with Reginald."""
|
||||||
|
async with self.config.guild(ctx.guild).allowed_roles() as allowed_roles:
|
||||||
|
if role.id in allowed_roles:
|
||||||
|
allowed_roles.remove(role.id)
|
||||||
|
await ctx.send(f"❌ Role **{role.name}** has been removed from Reginald's access list.")
|
||||||
|
else:
|
||||||
|
await ctx.send(f"⚠️ Role **{role.name}** was not in the access list.")
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import traceback
|
|||||||
from collections import Counter
|
from collections import Counter
|
||||||
from redbot.core import Config, commands
|
from redbot.core import Config, commands
|
||||||
from openai import OpenAIError
|
from openai import OpenAIError
|
||||||
from .permissions import list_allowed_roles_logic
|
from .permissions import PermissionsMixin
|
||||||
|
|
||||||
class ReginaldCog(commands.Cog):
|
class ReginaldCog(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
@ -45,12 +45,6 @@ class ReginaldCog(commands.Cog):
|
|||||||
allowed_roles = await self.config.guild(user.guild).allowed_roles() or [] # Ensure it's always a list
|
allowed_roles = await self.config.guild(user.guild).allowed_roles() or [] # Ensure it's always a list
|
||||||
return any(role.id in allowed_roles for role in user.roles)
|
return any(role.id in allowed_roles for role in user.roles)
|
||||||
|
|
||||||
|
|
||||||
@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):
|
|
||||||
await list_allowed_roles_logic(ctx)
|
|
||||||
|
|
||||||
async def is_blacklisted(self, user: discord.Member) -> bool:
|
async def is_blacklisted(self, user: discord.Member) -> bool:
|
||||||
blacklisted_users = await self.config.guild(user.guild).blacklisted_users()
|
blacklisted_users = await self.config.guild(user.guild).blacklisted_users()
|
||||||
return str(user.id) in blacklisted_users
|
return str(user.id) in blacklisted_users
|
||||||
@ -473,34 +467,6 @@ class ReginaldCog(commands.Cog):
|
|||||||
else:
|
else:
|
||||||
await ctx.send(f"No stored knowledge about {user.display_name} to delete.")
|
await ctx.send(f"No stored knowledge about {user.display_name} to delete.")
|
||||||
|
|
||||||
@commands.command(name="reginald_allowrole", help="Grant a role permission to interact with Reginald.")
|
|
||||||
@commands.has_permissions(administrator=True)
|
|
||||||
async def allow_role(self, ctx, role: discord.Role):
|
|
||||||
async with self.config.guild(ctx.guild).allowed_roles() as allowed_roles:
|
|
||||||
# ✅ Clean list of invalid roles before adding new one
|
|
||||||
valid_roles = [role_id for role_id in allowed_roles if ctx.guild.get_role(role_id)]
|
|
||||||
|
|
||||||
if role.id not in valid_roles:
|
|
||||||
valid_roles.append(role.id)
|
|
||||||
await self.config.guild(ctx.guild).allowed_roles.set(valid_roles) # Save change
|
|
||||||
await ctx.send(f"✅ Role {role.name} has been granted access to Reginald.")
|
|
||||||
else:
|
|
||||||
await ctx.send(f"⚠️ Role {role.name} already has access.")
|
|
||||||
|
|
||||||
@commands.command(name="reginald_disallowrole", help="Revoke a role's access to interact with Reginald.")
|
|
||||||
@commands.has_permissions(administrator=True)
|
|
||||||
async def disallow_role(self, ctx, role: discord.Role):
|
|
||||||
async with self.config.guild(ctx.guild).allowed_roles() as allowed_roles:
|
|
||||||
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)
|
|
||||||
|
|
||||||
if role.id in valid_roles:
|
|
||||||
valid_roles.remove(role.id)
|
|
||||||
await self.config.guild(ctx.guild).allowed_roles.set(valid_roles)
|
|
||||||
await ctx.send(f"❌ Role {role.name} has been removed from Reginald's access list.")
|
|
||||||
else:
|
|
||||||
await ctx.send(f"⚠️ Role {role.name} was not in the access list.")
|
|
||||||
|
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@commands.has_permissions(manage_guild=True)
|
@commands.has_permissions(manage_guild=True)
|
||||||
@commands.command(help="Set the OpenAI API key")
|
@commands.command(help="Set the OpenAI API key")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user