More commands

This commit is contained in:
unknown 2023-06-03 18:02:59 +02:00
parent 2d1f7495a3
commit 133048120f

View File

@ -33,27 +33,34 @@ class ReginaldCog(commands.Cog):
allowed_roles = await self.config.guild(ctx.guild).allowed_roles() allowed_roles = await self.config.guild(ctx.guild).allowed_roles()
return any(role.id in allowed_roles for role in ctx.author.roles) return any(role.id in allowed_roles for role in ctx.author.roles)
@commands.guild_only() @commands.command(name="allowrole")
@commands.command(name="reginald_allowrole", help="Allow a role to use the Reginald command") @commands.has_permissions(administrator=True)
async def allowrole(self, ctx, role: discord.Role): async def allow_role(self, ctx, role: discord.Role):
if not await self.has_admin_role(ctx): """Allows a role to use the reginald command"""
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: async with self.config.guild(ctx.guild).allowed_roles() as allowed_roles:
if role.id not in allowed_roles: if role.id not in allowed_roles:
allowed_roles.append(role.id) allowed_roles.append(role.id)
await ctx.send(f"Role {role.name} is now allowed to use the Reginald command.") await ctx.send(f"The {role.name} role is now allowed to use the Reginald command.")
else:
await ctx.send(f"The {role.name} role is already 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") @commands.command(name="disallowrole")
async def disallowrole(self, ctx, role: discord.Role): @commands.has_permissions(administrator=True)
if not await self.has_admin_role(ctx): async def disallow_role(self, ctx, role: discord.Role):
await ctx.send("You do not have the required permissions to use this command.") """Revokes a role's permission to use the reginald command"""
return
async with self.config.guild(ctx.guild).allowed_roles() as allowed_roles: async with self.config.guild(ctx.guild).allowed_roles() as allowed_roles:
if role.id in allowed_roles: if role.id in allowed_roles:
allowed_roles.remove(role.id) allowed_roles.remove(role.id)
await ctx.send(f"Role {role.name} is no longer allowed to use the Reginald command.") await ctx.send(f"The {role.name} role is no longer allowed to use the Reginald command.")
else:
await ctx.send(f"The {role.name} role is not currently allowed to use the Reginald command.")
def role_check():
async def predicate(ctx):
allowed_roles = await ctx.bot.get_cog("ReginaldCog").config.guild(ctx.guild).allowed_roles()
return any(role.id in allowed_roles for role in ctx.author.roles)
return commands.check(predicate)
@commands.guild_only() @commands.guild_only()
@commands.has_permissions(manage_guild=True) @commands.has_permissions(manage_guild=True)
@ -63,7 +70,7 @@ class ReginaldCog(commands.Cog):
await ctx.send("OpenAI API key set successfully.") await ctx.send("OpenAI API key set successfully.")
@commands.guild_only() @commands.guild_only()
@has_allowed_role() @role_check()
@commands.command(help="Ask Reginald a question") @commands.command(help="Ask Reginald a question")
@commands.cooldown(1, 10, commands.BucketType.user) # 10 second cooldown per user @commands.cooldown(1, 10, commands.BucketType.user) # 10 second cooldown per user
async def reginald(self, ctx, *, prompt=None): async def reginald(self, ctx, *, prompt=None):