Exemplo n.º 1
0
    async def overview_embed(self, embed: Embed, ctx) -> Embed:
        """
        Building the help menu embed
        :param embed: embed object to use for the building of the embed.
        :param ctx: context of the invocation.
        :return: the overview embed
        """
        embed.title = 'Help Menu'
        embed.description = 'Use {}help <command> for more information'.format(config['prefix'])
        cog_mapping = self.bot.cogs
        not_rendered_counter = 0
        for cog in cog_mapping:
            command_list = cog_mapping[cog].get_commands()
            if len(command_list) == 0:
                not_rendered_counter -= 1
                continue

            embed_val = ''
            for command in command_list:
                # check if command is executable for caller
                try:
                    # if it is include in the embed, otherwise no need for user to know about the command.
                    if await command.can_run(ctx):
                        embed_val += command.name + '\n'
                except CommandError:
                    pass

            if embed_val != '':
                embed.add_field(name='**' + cog + '**', value=f'```fix\n{embed_val}```', inline=True)
        # use the not rendered counter to insert zero width space fields to properly align the embed
        embed = add_filler_fields(embed, cog_mapping, '-', not_rendered_counter)
        return embed
Exemplo n.º 2
0
    def build_config_embed(self) -> Embed:
        """
        Building the config embed with all keys that are changeable current values.
        :return: discord.Embed
        """
        config_embed: Embed = Embed(
            title='Aura Configuration Menu',
            description='Shows all changeable configuration keys ' +
            'and their current values ',
            colour=embed_color)
        for key in config.keys():
            if key not in hidden_config:
                if isinstance(config[key], Mapping):
                    config_embed.add_field(name=f'**{key}**',
                                           value=config[key])
                    continue
                for other_key in config[key].keys():
                    config_embed.add_field(name=f'**{key} {other_key}**',
                                           value=config[key][other_key])

        config_embed = add_filler_fields(config_embed, config_embed.fields)
        config_embed.set_footer(
            text=
            'token, owner, prefix, database, logging level only only changeable before runtime'
        )
        return config_embed
Exemplo n.º 3
0
    async def build_profile_embed(self, karma_member: KarmaMember,
                                  guild: discord.Guild) -> discord.Embed:
        """
        Build the profile embed with top channel breakdown configured
        :param karma_member: member whose profile to show
        :param guild: the discord guild
        :return: discord.Embed
        """
        channel_cursor = self.karma_service.aggregate_member_by_channels(
            karma_member)
        embed: discord.Embed = discord.Embed(colour=embed_color)
        embed.description = "Karma Profile with breakdown of top {} channels".format(
            profile()["channels"])
        channel_list = list(channel_cursor)
        total_karma = self.karma_service.aggregate_member_by_karma(
            karma_member)
        if len(channel_list) > 0:
            embed.add_field(name="0", value="0", inline=False)
            index = 0
            for document in channel_list:
                channel = guild.get_channel(int(document["_id"]["channel_id"]))
                if (index % 3) == 0 and index != 0:
                    if channel is None:
                        embed.add_field(
                            name=bold_field.format("deleted channel"),
                            value=document["karma"],
                            inline=False,
                        )
                    else:
                        embed.add_field(
                            name=bold_field.format(channel.name),
                            value=document["karma"],
                            inline=False,
                        )
                else:
                    if channel is None:
                        embed.add_field(
                            name=bold_field.format("deleted channel"),
                            value=document["karma"],
                            inline=True,
                        )
                    else:
                        embed.add_field(
                            name=bold_field.format(channel.name),
                            value=document["karma"],
                            inline=True,
                        )

            embed = add_filler_fields(embed, channel_list)
            embed.set_field_at(index=0,
                               name="**total**",
                               value=str(total_karma),
                               inline=False)
            return embed
        else:
            # small embed since no karma etc.
            embed.add_field(name="**total**", value="0", inline=False)
            return embed
Exemplo n.º 4
0
    async def show_permission(self, ctx):
        embed: discord.Embed = Embed(color=embed_color, title='Permission Overview',
                                     description='shows all commands with their currently set permissions.')
        embed.add_field(name=bold_field.format('help'), value='everyone')
        for key in permission_map.keys():
            embed.add_field(name=bold_field.format(key), value=permission_map[key])

        balanced_embed = add_filler_fields(embed, embed.fields)
        await ctx.channel.send(embed=balanced_embed)
Exemplo n.º 5
0
    async def build_profile_embed(self, karma_member: KarmaMember,
                                  guild: discord.Guild) -> discord.Embed:
        """
        Build the profile embed with top channel breakdown configured
        :param karma_member: member whose profile to show
        :param guild: the discord guild
        :return: discord.Embed
        """
        channel_cursor = self.karma_service.aggregate_member_by_channels(
            karma_member)
        embed: discord.Embed = discord.Embed(colour=embed_color)
        embed.description = 'Karma Profile with breakdown of top {} channels'.format(
            profile()['channels'])
        channel_list = list(channel_cursor)
        total_karma = self.karma_service.aggregate_member_by_karma(
            karma_member)
        if len(channel_list) == 0:
            embed.add_field(name="**total**", value='', inline=False)
            return embed

        embed.add_field(name='0', value='0', inline=False)
        index = 0
        for document in channel_list:
            channel = guild.get_channel(int(document['_id']['channel_id']))
            name = 'deleted channel' if channel is None else channel.name
            value = document['karma']
            inline = index == 0 or index % 3 != 0
            embed.add_field(name=bold_field.format(name),
                            value=value,
                            inline=inline)
            # index += 1

        embed = add_filler_fields(embed, channel_list)
        embed.set_field_at(index=0,
                           name="**total**",
                           value=str(total_karma),
                           inline=False)
        return embed
Exemplo n.º 6
0
 async def overview_embed(self, embed: Embed, ctx) -> Embed:
     """
     Building the help menu embed
     :param embed: embed object to use for the building of the embed.
     :param ctx: context of the invocation.
     :return: the overview embed
     """
     embed.title = "Help Menu"
     embed.description = "Use {}help <command> for more information".format(
         config["prefix"]
     )
     cog_mapping = self.bot.cogs
     not_rendered_counter = 0
     for cog in cog_mapping:
         command_list = cog_mapping[cog].get_commands()
         if len(command_list) > 0:
             embed_val = ""
             for command in command_list:
                 # check if command is executable for caller
                 is_executable = False
                 try:
                     is_executable = await command.can_run(ctx)
                 except CommandError:
                     pass
                 if is_executable:
                     # if it is include in the embed, otherwise no need for user to know about the command.
                     embed_val += command.name + "\n"
             if embed_val != "":
                 embed.add_field(
                     name="**" + cog + "**",
                     value=f"```fix\n{embed_val}```",
                     inline=True,
                 )
         else:
             not_rendered_counter -= 1
     # use the not rendered counter to insert zero width space fields to properly align the embed
     embed = add_filler_fields(embed, cog_mapping, "-", not_rendered_counter)
     return embed