Attempting to remove hardcoded values by adding commands
This commit is contained in:
parent
28bfd52e29
commit
2d1f7495a3
@ -26,17 +26,34 @@ class ReginaldCog(commands.Cog):
|
|||||||
self.config.register_global(**default_global)
|
self.config.register_global(**default_global)
|
||||||
self.config.register_guild(**default_guild)
|
self.config.register_guild(**default_guild)
|
||||||
|
|
||||||
def has_allowed_role():
|
async def has_admin_role(self, ctx):
|
||||||
async def predicate(ctx):
|
return ctx.author.guild_permissions.administrator
|
||||||
kanium_role_id = 280260875678515200
|
|
||||||
return any(role.id == kanium_role_id for role in ctx.author.roles)
|
|
||||||
return commands.check(predicate)
|
|
||||||
|
|
||||||
def has_admin_role():
|
async def has_allowed_role(self, ctx):
|
||||||
async def predicate(ctx):
|
allowed_roles = await self.config.guild(ctx.guild).allowed_roles()
|
||||||
has_admin_permission = ctx.author.guild_permissions.administrator
|
return any(role.id in allowed_roles for role in ctx.author.roles)
|
||||||
return has_admin_permission
|
|
||||||
return commands.check(predicate)
|
@commands.guild_only()
|
||||||
|
@commands.command(name="reginald_allowrole", help="Allow a role to use the Reginald command")
|
||||||
|
async def allowrole(self, ctx, role: discord.Role):
|
||||||
|
if not await self.has_admin_role(ctx):
|
||||||
|
await ctx.send("You do not have the required permissions to use this command.")
|
||||||
|
return
|
||||||
|
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} is now allowed to use the Reginald command.")
|
||||||
|
|
||||||
|
@commands.guild_only()
|
||||||
|
@commands.command(name="reginald_disallowrole", help="Remove a role's ability to use the Reginald command")
|
||||||
|
async def disallowrole(self, ctx, role: discord.Role):
|
||||||
|
if not await self.has_admin_role(ctx):
|
||||||
|
await ctx.send("You do not have the required permissions to use this command.")
|
||||||
|
return
|
||||||
|
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} is no longer allowed to use the Reginald command.")
|
||||||
|
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@commands.has_permissions(manage_guild=True)
|
@commands.has_permissions(manage_guild=True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user