async def delete(self, ctx: commands.Context, name): tag_repo = TagRepository() claims_repo = ClaimsRepository() if not await tag_repo.check_tag_exists(name, ctx.guild.id): embed = discord.Embed(title=f'Error: tag {name} does not exist', color=Colors.Error) await ctx.send(embed=embed) return tag = await tag_repo.get_tag(name, ctx.guild.id) if tag['fk_UserId'] == ctx.author.id: await self._delete_tag(name, ctx) return claims = await claims_repo.fetch_all_claims_user(ctx.author) if ctx.command.claims_check(claims): await self._delete_tag(name, ctx) return error_str = f'Error: You do not have the tag_delete claim or you do not own this tag' embed = discord.Embed(title=error_str, color=Colors.Error) await ctx.send(embed=embed)
async def command_claims_check(self, ctx: commands.Context): """ Before invoke hook to make sure a user has the correct claims to allow a command invocation """ command = ctx.command author = ctx.author repo = ClaimsRepository() if not isinstance(command, ext.ExtBase): #If the command isnt an extension command let it through, we dont need to think about it return if len(command.claims) == 0: #command requires no claims nothing else to do return if author.guild_permissions.administrator: #Admins have full bot access no matter what return claims = await repo.fetch_all_claims_user(author) if claims and command.claims_check(claims): #Author has valid claims return claims_str = '\n'.join(command.claims) raise ClaimsAccessError( f'Missing claims to run this operation, Need any of the following\n ```\n{claims_str}```' )
async def claims_check(self, ctx: commands.Context): """ Before invoke hook to make sure a user has the correct claims to allow a command invocation """ command = ctx.command author = ctx.author repo = ClaimsRepository() if await self.is_owner(author): # if the author owns the bot, authorize the command no matter what return True if not isinstance(command, ext.ExtBase): # If the command isnt an extension command let it through, we dont need to think about it return True if author.guild_permissions.administrator: # Admins have full bot access no matter what return True if len(command.claims) == 0: # command requires no claims nothing else to do return True claims = await repo.fetch_all_claims_user(author) if claims and command.claims_check(claims): # Author has valid claims return True return False
async def remove(self, ctx, claim: ClaimsConverter, role: discord.Role): repo = ClaimsRepository() if not await repo.check_claim_role(claim, role): embed = discord.Embed( title=f'Error: {claim.name} not added to {role.name}', color=Colors.Error) await ctx.send(embed=embed) return title = f'Claim: "{claim.name}" successfully removed from role @{role.name} :white_check_mark:' claims = await repo.fetch_all_claims_role(role) claims_str = '\n'.join(claims) if claims else 'No current claims' desc = f'Current {role.mention} claims ```\n{claims_str}```' embed = discord.Embed(title=title, color=Colors.ClemsonOrange, description=desc) await ctx.send(embed=embed) await repo.remove_claim_mapping(claim.name, role)
async def add(self, ctx, claim: ClaimsConverter, role: discord.Role): repo = ClaimsRepository() if await repo.check_claim_role(claim, role): embed = discord.Embed( title=f'Error: {claim.name} already added to {role.name}', color=Colors.Error) await ctx.send(embed=embed) return await repo.add_claim_mapping(claim.name, role) title = f'Claim: "{claim.name}" successfully added to role @{role.name} :white_check_mark:' claims = await repo.fetch_all_claims_role(role) claims_str = "\n".join(claims) desc = f'Current {role.mention} claims ```\n{claims_str}```' embed = discord.Embed(title=title, color=Colors.ClemsonOrange, description=desc) await ctx.send(embed=embed)
async def command_claims_check(self, ctx: commands.Context): """ Before invoke hook to make sure a user has the correct claims to allow a command invocation """ command = ctx.command author = ctx.author repo = ClaimsRepository() if await self.is_owner(author): # if the author owns the bot, authorize the command no matter what return if not isinstance(command, ext.ExtBase): # If the command isnt an extension command let it through, we dont need to think about it return if author.guild_permissions.administrator: # Admins have full bot access no matter what return if len(command.claims) == 0: # command requires no claims nothing else to do return if command.ignore_claims_pre_invoke: # The command is going to check the claims in the command body, nothing else to do return claims = await repo.fetch_all_claims_user(author) if claims and command.claims_check(claims): # Author has valid claims return claims_str = '\n'.join(command.claims) raise ClaimsAccessError(f'Missing claims to run this operation, Need any of the following\n ```\n{claims_str}```' f'\n **Help:** For more information on how claims work please see the wiki [Link!](' f'https://github.com/ClemsonCPSC-Discord/ClemBot/wiki/Authorization-Claims)\n' f'or run the `{await self.current_prefix(ctx.message)}help claims` command')
async def _send_user_claims(self, ctx, user): repo = ClaimsRepository() claims = await repo.fetch_all_claims_user(user) embed = self._build_claims_embed(ctx, claims) await ctx.send(embed=embed)
async def _send_role_claims(self, ctx, role): repo = ClaimsRepository() claims = await repo.fetch_all_claims_role(role) embed = self._build_claims_embed(ctx, claims) await ctx.send(embed=embed)