def predicate(ctx): if ctx.author.id == config['discord']['owner_id']: return True # we do this so owner has a constant override server_settings = guild_settings.get_settings(guild=ctx.guild) if ctx.author.id == ctx.guild.owner.id: return True for role in ctx.author.roles: if str(role.id) in server_settings['staff_roles']: return True logger.warning("User {} failed is_server_allowed check".format( ctx.author.id)) return False
async def promote_role(self, ctx, role_id): """ Add a role to the list of allowed roles """ role = ctx.guild.get_role(int(role_id)) if role is None: return await ctx.send(embed=discord.Embed(title="Error", description="That role does not exist", color=red)) settings = guild_settings.get_settings(guild=ctx.guild) if role_id in settings['staff_roles']: return await ctx.send(embed=discord.Embed(title="Error", description="Role already has admin perms", color=red)) settings['staff_roles'].append(role_id) guild_settings.write_settings(settings) return await ctx.send(embed=discord.Embed(title="Success", description="Role {} added to admin list".format(role.name), color=green))
async def demote_role(self, ctx, role_id): role_id = int(role_id) role_to_remove = ctx.guild.get_role(int(role_id)) if role_to_remove is None: return await ctx.send(embed=discord.Embed(title="Error", description="That role does not exist", color=red)) settings = guild_settings.get_settings(guild=ctx.guild) if role_id in ctx.author.roles: # this means the user is removing a role that gives them perms users_permitted_roles = [] # list of roles that give user permission to run this for role in ctx.author.roles: for role_existing in settings['staff_roles']: if role_existing == role.id: users_permitted_roles.append(role) if len(users_permitted_roles) <= 1: return await ctx.send(embed=discord.Embed(title="Error", description="You cannot remove a role that gives permissions without another role which has permissions to do so", color=red)) try: settings['staff_roles'].remove(str(role_id)) guild_settings.write_settings(settings) return await ctx.send(embed=discord.Embed(title="Success", description="Removed {} from permitted role list".format(role_to_remove.name), color=green)) except ValueError: return await ctx.send(embed=discord.Embed(title="Error", description="That role does not exist in the permitted role list", color=red))