示例#1
0
    async def profile_info(self, ctx, profile: str):
        # self.update_responses()
        responses = self.responses['profile']['profile_info']
        guild_id = str(ctx.guild.id)
        profiles = get_servers_data()[guild_id]['profiles']

        if profile in profiles:
            profile_roles = profiles[profile]
            embed = embed_template(
                title=responses['embed_data']['title'].format(profile=profile),
                description=responses['embed_data']['description'].format(
                    number=format(len(profile_roles), "bold")))
            content = responses['content']
            field = ""
            for role_id in profile_roles:
                role = discord.utils.get(ctx.guild.roles, id=role_id)
                if role is None:
                    self.remove_profile_role(guild_id, role_id, profile)
                else:
                    field += f"{role.mention}, "
            field = field.rstrip(', ')
            embed.add_field(name="Roles:", value=field)
            await ctx.send(content=content, embed=embed)
        else:
            raise commands.BadArgument(profile, "invalid_profile")
示例#2
0
 async def predicate(ctx):
     guild_id = str(ctx.guild.id)
     guild_data = get_servers_data()[guild_id]
     permission_type = guild_data["permission_type"]
     author_perms = ctx.message.author.guild_permissions
     if ctx.message.author.id == ctx.guild.owner_id or ctx.message.author.id in get_config(
     )['has_access'] or permission_type == "everyone":
         return True
     elif permission_type == "administrator" or permission_type == "manage_server":
         if getattr(author_perms, permission_type, False):
             return True
     elif permission_type == "custom" and guild_data[
             "custom_has_permission"]:
         if ctx.message.author.id in guild_data[
                 "custom_has_permission"]:
             return True
     # if the check has gone this far and returned nothing, then the check has failed and permission is denied
     with open("info/responses.json", "r") as f:
         responses = json.load(f)['fail_check']['perms']
         embed = embed_template(
             title=responses['embed_data']['title'].format(
                 command=ctx.invoked_with),
             description=responses['embed_data']['description'].format(
                 permission_type=permission_type))
         embed.color = 15138816
         await ctx.send(content=responses['content'], embed=embed)
示例#3
0
    async def permission_type(self, ctx):
        self.update_response()
        responses = self.responses['permissions']['permission_type']

        data = get_servers_data()
        guild_id = str(ctx.guild.id)
        guild_exists(guild_id)
        permission_type = data[guild_id]["permission_type"]

        embed = embed_template(
            title=responses["embed_data"]["title"].format(
                server=ctx.guild.name),
            description=responses["embed_data"]["description"])

        embed.add_field(name=f"Permission type:", value=permission_type)

        if permission_type == "custom":
            user_ids = data[guild_id]['custom_has_permission']
            users = []
            for user_id in user_ids:
                user_obj = discord.utils.get(ctx.guild.members, id=user_id)
                users.append(f"{user_obj.name}#{user_obj.discriminator}")
            users.append(
                f"{ctx.guild.owner.name}#{ctx.guild.owner.discriminator} (server owner)"
            )
            embed.add_field(name="Custom permission access",
                            value=', '.join(users))

        await ctx.send(content=None, embed=embed)
示例#4
0
    async def help(self, ctx, specific=None):
        self.update_response()
        guild_exists(str(ctx.guild.id))

        if specific is not None:
            specific = specific.lower()
        
        embed = embed_template()
        content = None

        # dictionary of lower cog name: cog
        cogs = {cog.qualified_name.lower(): cog for cog in self.client.cogs.values()}

        # dictionary of all lower command name: command
        # commands = {command.name.lower(): command for cog in self.client.cogs.values() for command in cog.get_commands() } # have to include command aliases
        commands = {}
        for cog in self.client.cogs.values():
            for command in cog.get_commands():
                commands[command.name.lower()] = command
                for alias in command.aliases:
                    commands[alias.lower()] = command

        if specific is None:
            content = self.help_embed(ctx, embed)
        elif specific in cogs:
            content = self.module_help_embed(ctx, cogs[specific], embed)
        elif specific in commands:
            self.command_help_embed(commands[specific], embed)
        else:
            # print(f"{specific} not found")
            self.help_embed(ctx, embed)
            content = f"Specific command or module \"{specific}\" was not found. Here is the main help page."


        await ctx.send(content=content, embed=embed)
示例#5
0
    async def server_config(self, ctx):
        self.update_response()
        responses = self.responses['settings']['server_config']
        guild_exists(str(ctx.guild.id))
        guild_id = str(ctx.guild.id)
        guild_data = get_servers_data()[guild_id]

        prefix = ctx.prefix
        number_of_profiles = len(guild_data["profiles"])
        permission_type = guild_data["permission_type"]

        jail_role = discord.utils.get(ctx.guild.roles,
                                      id=guild_data["jail_role"])
        jail_role = jail_role.mention if jail_role is not None else jail_role
        jail_channel = discord.utils.get(ctx.guild.text_channels,
                                         id=guild_data["jail_channel"])
        jail_channel = jail_channel.mention if jail_channel is not None else jail_channel

        embed = embed_template(
            title=responses["embed_data"]["title"].format(
                server=ctx.guild.name),
            description=responses["embed_data"]["description"])

        embed.add_field(name="Bot prefix", value=f'`{prefix}`', inline=True)
        embed.add_field(name="Number of profiles",
                        value=number_of_profiles,
                        inline=True)
        embed.add_field(name="Permission type",
                        value=permission_type,
                        inline=True)
        if permission_type == "custom":
            user_ids = guild_data['custom_has_permission']
            users = []
            for user_id in user_ids:
                user_obj = discord.utils.get(ctx.guild.members, id=user_id)
                if user_obj is not None:
                    users.append(f"{user_obj.name}#{user_obj.discriminator}")
                else:
                    users.append(str(user_id))
            users.append(
                f"{ctx.guild.owner.name}#{ctx.guild.owner.discriminator} (server owner)"
            )
            embed.add_field(name="Custom permission access",
                            value=', '.join(users))
        embed.add_field(name="Jail role", value=jail_role)
        embed.add_field(name="Jail channel", value=jail_channel)

        await ctx.send(content=None, embed=embed)
示例#6
0
    async def list_profiles(self, ctx):
        # self.update_responses()
        responses = self.responses['profile']['list_profiles']

        guild_id = str(ctx.guild.id)
        profiles = get_servers_data()[guild_id]['profiles']

        fields = []
        for profile_name, profile_roles in profiles.items():
            fields.append({'name': profile_name, 'value': len(profile_roles)})

        fields.sort(key=lambda f: f['name'])

        num_profiles = len(fields)
        num_embeds = num_profiles // 25  # 25 is the max num fields per embed
        slices = []
        if num_embeds != 0:
            leftover = len(fields) - (num_embeds * 25)
            for i in range(num_embeds):
                start = i * 25
                stop = (i + 1) * 25
                slices.append(slice(start, stop))
            if leftover:
                slices.append(slice(stop, stop + leftover))
        else:
            slices.append(slice(0, len(fields)))

        for slice_ in slices:
            embed = embed_template(
                title=responses['embed_data']['title'].format(
                    name=ctx.guild.name),
                description=responses['embed_data']['description'].format(
                    name=ctx.guild.name,
                    number=format(num_profiles, "bold"),
                    prefix=ctx.prefix))
            embed_fields = fields[slice_]
            if embed_fields:
                for field in embed_fields:
                    embed.add_field(
                        name=field['name'],
                        value=f"{format(field['value'], 'bold')} total roles.",
                        inline=True)
            else:
                embed.add_field(name="\a", value='There are no responders')
            await ctx.send(embed=embed)

        # BUG: if there's more than 25, than it isn't shown, loop through yk  the drill plsz
        '''
示例#7
0
 async def predicate(ctx):
     guild_id = str(ctx.guild.id)
     guild_data = get_servers_data()[guild_id]
     if ("jail_role" in guild_data and guild_data["jail_role"]
             is not None) and ("jail_channel" in guild_data and
                               guild_data["jail_channel"] is not None):
         return True
     # if the check has gone this far and returned nothing, then the check has failed
     with open("info/responses.json", "r") as f:
         responses = json.load(f)['fail_check']['jail_exists']
         embed = embed_template(
             title=responses['embed_data']['title'].format(
                 command=ctx.invoked_with),
             description=responses['embed_data']['description'].format(
                 command=ctx.invoked_with, prefix=ctx.prefix))
         embed.color = 15138816
         await ctx.send(content=responses['content'], embed=embed)
示例#8
0
 async def predicate(ctx):
     guild_id = str(ctx.guild.id)
     guild_data = get_servers_data()[guild_id]
     permission_type = guild_data["permission_type"]
     if guild_data["permission_type"] == "custom":
         return True
     # if the check has gone this far and returned nothing, then the check has failed
     with open("info/responses.json", "r") as f:
         responses = json.load(f)['fail_check']['custom_perms_enabled']
         embed = embed_template(
             title=responses['embed_data']['title'].format(
                 command=ctx.invoked_with),
             description=responses['embed_data']['description'].format(
                 command=ctx.invoked_with,
                 permission_type=permission_type,
                 prefix=ctx.prefix))
         embed.color = 15138816
         await ctx.send(content=responses['content'], embed=embed)
示例#9
0
    async def on_command_error(self, ctx, error):
        """The event triggered when an error is raised while invoking a command.
        ctx   : Context
        error : Exception
        
        edited from https://gist.github.com/EvieePy/7822af90858ef65012ea500bcecf1612
        """
        # if hasattr(ctx.command, 'on_error'):
        #    return

        ignored = (commands.CommandNotFound, commands.CheckFailure)
        error = getattr(error, 'original', error)

        if isinstance(error, ignored):
            return

        elif isinstance(error, KeyError):
            command = self.client.get_command(ctx.invoked_with)
            responses = get_responses()[command.cog.qualified_name.lower()][
                command.name]
            embed = embed_template(
                title="An internal responder message error has occured",
                description=
                f"Missing responder `{error.args[0]}` for command `command.name`"
            )
            embed.color = 15138816
            await ctx.send(content=None, embed=embed)
        else:
            try:
                command = self.client.get_command(ctx.invoked_with)
                responses = get_responses()[
                    command.cog.qualified_name.lower()][command.name]

                message = ""
                if isinstance(error, commands.MissingRequiredArgument):
                    message = responses["error"][f"missing_{error.param.name}"]

                elif isinstance(error, commands.BadArgument):
                    if len(error.args) == 1:
                        message = responses["error"][error.args[0]]
                    elif len(error.args) == 2:
                        message = responses["error"][error.args[1]].format(
                            profile=format(error.args[0], 'single_code'))

                elif isinstance(error, discord.Forbidden):
                    message = responses["error"]['forbidden']

                embed = embed_template(title="An error has occured",
                                       description=message)
                embed.color = 15138816
                await ctx.send(content=None, embed=embed)
            except KeyError:
                command = self.client.get_command(ctx.invoked_with)
                responses = get_responses()[
                    command.cog.qualified_name.lower()][command.name]
                embed = embed_template(
                    title="An internal responder message error has occured",
                    description=
                    f"Missing responder `{error.args[0]}` for command `{command.name}`"
                )
                embed.color = 15138816
                await ctx.send(content=None, embed=embed)

        raise error