async def get_rule_reason(self, message, criteria): reasons = [] for regex in criteria.matches: if re.search(regex, message.content): reasons.append("Message contains banned word or phrase.") if criteria.includes_slurs: for word in message.content.split(): if SLUR_FILTER.match(word): reasons.append( f"Message contains recognized racial slur: {word}") break if criteria.includes_invite_links: if any(invite.get_discord_invite_codes(message.content)): reasons.append("Message contains Discord invite link.") reasons += list(self.get_mention_reason(message, criteria.mentions)) reasons += list(self.get_embed_reason(message, criteria.embeds)) exclude_criteria = ( # Exclude the owner of the bot and the owner of the server. await self.bot.is_owner(message.author), message.guild.owner_id == message.author.id, # Exclude moderators and bots if configured. criteria.exclude_moderators and utils.is_moderator(message.author), criteria.exclude_bots and message.author.bot, # Exclude specific channels when configured. message.channel.id in criteria.excluded_channels, ) if any(exclude_criteria): reasons.clear() return reasons
def should_cache_member(self, member): # Cache if the member is: # - A moderator # - Is the bot user # - Is a member pending verification return utils.is_moderator(member) or \ member.id == member._state.user.id or \ member.pending
async def predicate(ctx): if ctx.guild is None: raise commands.NoPrivateMessage() if not (utils.is_moderator(ctx.author) or await ctx.bot.is_owner(ctx.author)): raise commands.CheckFailure( message='You are not a moderator of this server.') return True
async def is_dj(ctx, member=None): """ Checks if the user is a DJ or not. """ if member is None: member = ctx.author dj_roles = await get_dj_roles(ctx) if len(dj_roles) <= 0: return is_moderator(member) member_roles = set(member.roles) return len(dj_roles.intersection(member_roles)) > 0