Ejemplo n.º 1
0
async def warn_cmd(message: Message,
                   member: Member,
                   reason: str = None) -> None:
    """
    Warn command
    :param message: Message of command execution
    :param member: Member to be warned
    :param reason: Reason for warn
    """
    # Initialize varaibles
    channel: TextChannel = message.channel
    moderator: Member = message.author

    # Delete message of member
    await util.delete_message(message)

    if member.id == secret.bot_id:
        # Don't warn the bot
        raise Exception('Cannot warn the bot')

    if permission.is_mod(member=member):
        # Don't warn moderators of the server
        raise Exception('Cannot warn moderators')

    await warn(member, moderator, reason)

    # Send embed as response in chat
    await moderation.chat_message(channel, f'Warned {member.mention}',
                                  appearance.moderation_color, moderator)
Ejemplo n.º 2
0
async def ban_cmd(message: Message, member: Member, client: Client, reason: str = None) -> None:
    """
    Ban command
    :param message: Message of command call
    :param member: Member to be banned
    :param client: Bot client
    :param reason: Reason for ban
    """
    # Initialize varaibles
    channel: TextChannel = message.channel
    guild: Guild = message.guild
    moderator: Member = message.author

    # Delete message of member
    await util.delete_message(message)

    if member.id == secret.bot_id:
        # Don't ban the bot
        raise Exception('Cannot ban the bot')

    if permission.is_mod(member=member):
        # Don't ban moderators of the server
        raise Exception('Cannot ban moderators')

    # Ban member and send log message
    await ban(member, moderator, client, reason)

    # Send embed as response in chat
    await moderation.chat_message(channel, f'Banned {member.mention}', appearance.moderation_color,
                                  moderator)
Ejemplo n.º 3
0
async def tempban_cmd(message: Message, member: Member, duration_amount: int, duration_unit: str, client: Client,
                      reason: str = None) -> None:
    """
    Tempban member on the guild
    :param message: Message of command call
    :param member: Member to be banned
    :param duration_amount: Duration of ban (e.g. 60)
    :param duration_unit: Unit of duration (e.g. 'minutes', 'hours')
    :param client: Bot client
    :param reason: Reason for ban
    """
    # Initialize varaibles
    channel: TextChannel = message.channel
    moderator: Member = message.author

    # Delete message of member
    await util.delete_message(message)

    if member.id == secret.bot_id:
        # Don't ban the bot
        raise Exception('Cannot ban the bot')

    # Don't ban moderators of the server
    if permission.is_mod(member=member):
        raise Exception('Cannot ban moderators')

    tdelta, duration = moderation.get_duration(duration_amount, duration_unit)

    # Mute member and send log message
    await tempban(member, moderator, duration, tdelta, client, reason)

    # Send embed as response in chat
    await moderation.chat_message(channel, f'Banned {member.mention} for {duration}', appearance.moderation_color,
                                  moderator)
Ejemplo n.º 4
0
async def mute_cmd(message: Message,
                   member: Member,
                   reason: str = None) -> None:
    """
    Mute command that mutes a member on the guild
    :param message: Message of command call
    :param member: Member to be muted
    :param reason: Reason for mute
    """
    # Initialize varaibles
    channel: TextChannel = message.channel
    guild: Guild = message.guild
    moderator: Member = message.author

    # Delete message of member
    await util.delete_message(message)

    if member.id == secret.bot_id:
        # Don't mute the bot
        raise Exception('Cannot mute the bot')

    if permission.is_mod(member=member):
        # Don't mute moderators of the server
        raise Exception('Cannot mute moderators')

    # Mute the member and send log message
    await mute(member, moderator, reason)

    # Send embed as response in chat
    await moderation.chat_message(channel, f'Muted {member.mention}',
                                  appearance.moderation_color, moderator)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
async def help_command(message: Message) -> None:
    """
    Sends help messages.
    :param message: Message that executed the command
    """
    # Initialize attributes of message
    member: Member = message.author

    # Call different help messages depending on permission
    await _member_help(message)

    if permission.is_admin(member=member):
        await _mod_help(message, message.channel, footer=False)
        await _admin_help(message, message.channel)

    elif permission.is_mod(member=member):
        await _mod_help(message, message.channel)

    # Delete message
    await util.delete_message(message)