async def report_cmd(message: Message, member: Member, reason: str) -> None: """ Report a member :param message: Message of command execution :param member: Member to be reported :param reason: Reason for report """ # Initialize varaibles channel: TextChannel = message.channel guild: Guild = message.guild reported_by: Member = message.author mod_log = moderation.get_mod_log(guild) if not mod_log: # Ignore if the moderation log is not set up raise Exception('Moderation log must be set up') # Delete message of member await util.delete_message(message) if member.id == secret.bot_id: # Don't warn the bot raise Exception('Cannot report the bot') if permission.is_mod(member=member): # Don't warn moderators of the server raise Exception('Cannot report moderators') # Insert into database insert.report(reporter_id=reported_by.id, user_id=member.id, date=datetime.utcnow(), guild_id=guild.id, reason=reason) # Send embed as response in chat await moderation.chat_message(channel, f'Reported {member.mention} for {reason}', appearance.moderation_color, reported_by) # Send log message in moderation log log_embed: Embed = Embed(colour=appearance.moderation_color, timestamp=datetime.utcnow()) # Add fields log_embed.set_author(name='Report', icon_url=member.avatar_url) log_embed.set_footer(text=reported_by.display_name, icon_url=reported_by.avatar_url) log_embed.add_field(name='User', value=member.mention, inline=True) log_embed.add_field(name='Reported by', value=reported_by.mention, inline=True) log_embed.add_field(name='Channel', value=channel.mention, inline=True) log_embed.add_field(name='Reason', value=reason, inline=False) await mod_log.send(embed=log_embed)
async def reports_error(self, ctx: Context, error: Exception): """Handles exceptions while running the reports command""" if not mod.get_mod_log(ctx.guild): # Ignore if the log is not set up return await error_messages.error_handler(ctx, error, description.get_command('reports'), 'Member', 'Cannot find the member.', True)
async def reports_of_member_cmd(client: Client, message: Message, member: Member) -> None: """ Get a list of the reports of the member on a guild :param client: Bot client :param message: Message of command execution :param member: Member to get reports of """ # Initialize varaibles channel: TextChannel = message.channel guild: Guild = message.guild mod_log = moderation.get_mod_log(guild) if not mod_log: # Ignore if the moderation log is not set up raise Exception('Moderation log must be set up') # Delete message of member await util.delete_message(message) # Get count of warns of member count = select.count_reports(member.id, guild.id) # Fetch warns reports: list[Report] = select.reports_of_user(member.id, guild.id, limit=5) # Create embed desc = f'{member.mention} has **{count} reports** total.' if count > 0: desc += '\n\u200b' if count > 5: desc += '\n**Here are the latest 5 reports:**' embed = Embed(title=f'Reports - {member.display_name}', description=desc, colour=appearance.moderation_color) # Add reports to embed for r in reports: reported_by: User = await client.fetch_user(r.reporter_id) date: datetime = r.date embed.add_field(name=date.strftime("%Y.%m.%d"), value=f'• Moderator: {reported_by.mention}' f'\n• Reason: {r.reason}', inline=False) await channel.send(embed=embed)
async def report_error(self, ctx: Context, error: Exception): """Handles exceptions while running the repor command""" if not mod.get_mod_log(ctx.guild): # Ignore if the log is not set up return elif error.args[0].endswith('moderators'): # Cannot report moderators await util.delete_message(ctx.message) await error_messages.invalid_input_error( ctx, title='Member', description='Cannot report moderators.') elif error.args[0].endswith('report the bot'): # Cannot report the bot await util.delete_message(ctx.message) await error_messages.invalid_input_error(ctx, title='Member', description='Nice try...') else: await error_messages.error_handler( ctx, error, description.get_command('report'), 'Member', 'Cannot find the member.', True)
async def moderation_page(channel: TextChannel, guild: Guild): """ Sends a page with all information about the setup of moderation. :param guild: Guild of call :param channel: TextChannel to send the message to """ # Initialize important values prefix = appearance.get_prefix(guild.id) # Setup appearance of the embed embed: Embed = Embed(title=f'{appearance.bot_name} Setup - Moderation', description='Setup the moderation system!', colour=appearance.get_color(guild.id)) # Add information about moderation roles embed.add_field(name='Set Moderation Roles', value=f'React with 👥', inline=False) mod_log: TextChannel = mod.get_mod_log(guild) # Add information about the current moderation log embed.add_field(name='\u200b', value='\u200b', inline=False) embed.add_field(name='Moderation Log', value='• Get notified of mod operations\n' '• Unlock reports', inline=False) if mod_log: embed.add_field(name='Current Channel', value=mod_log.mention, inline=False) # Add information about the commands embed.add_field( name='Set Moderation Log', value=f'`{prefix}{description.get_command("moderation log").syntax}`', inline=False) # How to deactivate moderation log if mod_log: embed.add_field(name='Deactivate Moderation Log', value='React with 📪', inline=False) # Add information about the warn system embed.add_field(name='\u200b', value='\u200b', inline=False) embed.add_field(name='Warn Punishment', value=f'• **1 warn:** 20 min mute\n' f'• **3 warns within two weeks:** 2h mute\n' f'• **4 warns within one month:** 24h mute & kick') # Add information about mute mute_role: Role = await mute.get_mute_role(guild) embed.add_field(name='\u200b', value='\u200b', inline=False) embed.add_field( name='Problems With Mute?', value=f'Make sure the position of {mute_role.mention} is high enough.') # Send embed msg = await channel.send(embed=embed) # Add reactions await msg.add_reaction('👥') if mod_log: await msg.add_reaction('📪')
'member': 'User mention or name', 'reason': 'Any text' }, mod_only=True), Command('warns', 'warns <member>', 'Get the latest warns of a member.', {'member': 'User mention or name'}, mod_only=True), Command('report', 'report <member> <reason>', 'Report a member of the server.', { 'member': 'User mention or name', 'reason': 'Any text' }, in_help=lambda g: moderation.get_mod_log(g) is not None), Command('reports', 'reports <member>', 'Get the latest reports of a member.', {'member': 'User mention or name'}, mod_only=True, in_help=lambda g: moderation.get_mod_log(g) is not None), # Admin commands Command('setup', 'setup', 'Menu to set up the bot.', admin_only=True), Command('prefix', 'setup prefix <prefix>', 'Set the prefix of the bot on the server.', {'prefix': 'Single character'}, admin_only=True, in_help=False),