Exemple #1
0
    async def override_error(self, ctx: commands.Context, error):
        if isinstance(error, commands.BotMissingPermissions):
            message_base = "In order to override users' nicknames, I need the following additional permission(s): "

            final_message = message_base + \
                utilities.pretty_print_list(error.missing_perms)

            await ctx.send(final_message)
Exemple #2
0
    async def list_(self, ctx):
        """
        Lists all ignored roles and users for the current guild.

        Users and roles will be displayed in separate categories, which will be
        omitted in case they don't exist.
        """

        # Get reference to guild's ignored ids
        self.check_guild_data_exists(ctx.guild.id)
        ignores = self.guild_data[ctx.guild.id]["ignores"]

        ignore_embed = discord.Embed(title="Ignored Users and Roles",
                                     color=discord.Color.orange())

        ignored_roles = []
        for role_id in ignores["roles"]:
            role = ctx.guild.get_role(role_id)
            ignored_roles.append(role.mention)

        ignored_users = []
        for user_id in ignores["users"]:
            user = ctx.guild.get_member(user_id)
            ignored_users.append(user.mention)

        # Add corresponding fields to embed with pretty-printed information
        if len(ignored_roles) > 0:
            role_list_str = utilities.pretty_print_list(ignored_roles)
            ignore_embed.add_field(name="Ignored Roles:",
                                   value=role_list_str,
                                   inline=False)

        if len(ignored_users) > 0:
            user_list_str = utilities.pretty_print_list(ignored_users)
            ignore_embed.add_field(name="Ignored Users:",
                                   value=user_list_str,
                                   inline=False)

        # If both lists are empty, let the user know
        if len(ignored_roles) == 0 and len(ignored_users) == 0:
            ignore_embed.description = "There are no ignores for this guild."

        # send the embed
        await ctx.send(embed=ignore_embed)
Exemple #3
0
    async def add_(self, ctx: commands.Context):
        """
        Ignores a user/role for the purpose of verification.

        If multiple mentions are supplied, all of them will be ignored. A mix of
        mention types (roles/users) can be provided as well.

        Users/roles that are already ignored will not be added, but skipped.

        Ignores can be removed via the `ignore remove` command.
        """
        guild_id = ctx.guild.id

        # Check if this guild has already been initialized
        self.check_guild_data_exists(ctx.guild.id)

        # Store reference to ignored_ids subsection of guild data
        ignores = self.guild_data[ctx.guild.id]["ignores"]

        # Add users mentioned to ignore_rules under the "users" key
        for member in ctx.message.mentions:
            if member.id not in ignores["users"]:
                ignores["users"].append(member.id)

        # Add roles mentioned to same dictionary under the "roles" key
        for role in ctx.message.role_mentions:
            if role.id not in ignores["roles"]:
                ignores["roles"].append(role.id)

        # Write ignore changes
        self.write_guild_data_changes()

        response = ""

        if len(ctx.message.mentions) > 0:
            response += "Ignoring users: " + \
                utilities.pretty_print_list(ctx.message.mentions)

        if len(ctx.message.role_mentions) > 0:
            response += "\nIgnoring roles: " + \
                utilities.pretty_print_list(ctx.message.role_mentions)

        if response != "":
            await ctx.send(response)
Exemple #4
0
class Modrole(commands.Cog, name="Moderation"):
    def __init__(self, bot: commands.Bot):
        self.bot = bot
        self.modroles = self.load_if_exists("modroles.pickle")

        # Add the corresponding modrole check to the supplied bot.
        self.bot.add_check(self.mods_only)

    @commands.group()
    async def modrole(self, ctx: commands.Context):
        """
        The command group related to managing and viewing modroles.
        """
        if ctx.invoked_subcommand is None:
            await ctx.send_help(ctx.command)

    @modrole.command(usage="add <role>")
    async def add(self, ctx: commands.Context):
        """
        Adds a modrole to the current guild.
        If the modrole already exists for this guild, the user will be notified.
        """
        if len(role_mentions := ctx.message.role_mentions) == 0:
            await ctx.send("You need to supply roles to become modroles.")
            return

        # Create the modroles list if it doesn't exist already
        self.ensure_modroles_exist(ctx.guild.id)

        modrole_list = self.modroles[ctx.guild.id]

        # Add modrole ids to self.modroles under guild id key
        for role in role_mentions:
            if role.id not in modrole_list:
                modrole_list.append(role.id)

            else:
                await ctx.send(f"{role.name} is already a modrole.")

        # Write changes to storage
        self.write_modrole_changes()

        # Make a message with all of the supplied role names
        role_names = [role.name for role in role_mentions]
        confirmation_message = "New Modroles: " + \
            utilities.pretty_print_list(role_names)
Exemple #5
0
    async def list(self, ctx: commands.Context):
        """
        Lists all modroles for the current guild.
        """
        list_embed = discord.Embed(title="Moderator Roles",
                                   color=discord.Color.orange())

        self.ensure_modroles_exist(ctx.guild.id)
        self.write_modrole_changes()

        # Create a list of all modroles from their ids
        modrole_ids = self.modroles[ctx.guild.id]
        guild_modrole_mentions = []

        for role_id in modrole_ids:
            role = ctx.guild.get_role(role_id)
            guild_modrole_mentions.append(role.mention)

        list_embed.description = utilities.pretty_print_list(
            guild_modrole_mentions) or "There are no modroles for this guild."

        await ctx.send(embed=list_embed)
Exemple #6
0
        removed_roles = []

        # Check if the supplied role(s) are actually modroles
        for role in role_mentions:
            # Let user know if role is not a modrole
            if role.id not in (role_list := self.modroles[ctx.guild.id]):
                await ctx.send(f"{role.name} is not a modrole.")
                continue

            role_list.remove(role.id)
            removed_roles.append(role.name)

        self.write_modrole_changes()

        role_list_message = ("Modroles removed: " +
                             utilities.pretty_print_list(removed_roles)
                             ) or "There are no modroles for this guild."

        await ctx.send(role_list_message)

    @modrole.command(usage="list")
    async def list(self, ctx: commands.Context):
        """
        Lists all modroles for the current guild.
        """
        list_embed = discord.Embed(title="Moderator Roles",
                                   color=discord.Color.orange())

        self.ensure_modroles_exist(ctx.guild.id)
        self.write_modrole_changes()
Exemple #7
0
 async def reverify_error(self, ctx: commands.Context, error):
     if isinstance(error, commands.BotMissingPermissions):
         await ctx.send("Missing permissions for `reverify`: " +
                        utilities.pretty_print_list(error.missing_perms))
Exemple #8
0
        # List to keep track of user ignores that were removed
        removed_users = []

        # Check which roles to remove, if any
        for user_id in ignores["users"]:
            ignore_member = ctx.guild.get_member(user_id)
            if ignore_member in user_mentions:
                ignores["users"].remove(user_id)
                removed_users.append(ignore_member.mention)

        # Make an embed saying which roles and users were unignored
        removed_embed = discord.Embed(title="Removed Ignores",
                                      color=discord.Color.red())

        removed_role_str = utilities.pretty_print_list(
            removed_roles) or "No roles unignored."
        removed_user_str = utilities.pretty_print_list(
            removed_users) or "No users unignored."

        # Add removed ignore fields to embed
        removed_embed.add_field(name="Roles",
                                value=removed_role_str,
                                inline=False)
        removed_embed.add_field(name="Users",
                                value=removed_user_str,
                                inline=False)

        await ctx.send(embed=removed_embed)

    # Named list_ because of naming conflicts with list keyword
    @ignore.command(name="list", usage="list")