Esempio n. 1
0
    async def send_cog_help(self, cog: commands.Cog) -> None:
        if cog.qualified_name in NO_ACCESS_COGS or not cog.help_check(self.context):
            raise self.command_not_found(cog.qualified_name)

        embed = Embed(
            title=f"Help for extension: `{cog.qualified_name}`",
            description="Ooooh ther's lots of fun stuff in here!",
            color=Color.blue(),
        )
        embed.add_field(
            name="What does this extension do?", value=cog.__doc__, inline=False
        )
        command = commands.Command

        commands_in_cog = [
            f"`{command.name}`"
            for command in cog.walk_commands()
            if command.parent is None
        ]

        embed.add_field(
            name="Commands:",
            value=(", ".join(commands_in_cog))
            if commands_in_cog
            else "No Commands Found!",
        )
        await self.dispatch_help(embed)
Esempio n. 2
0
    async def send_cog_help(self, cog: commands.Cog) -> None:
        embed = discord.Embed(title=f"{cog.qualified_name} Help", description=self.get_ending_note(), color=self.color)

        field_value = self.command_lister(cog.get_commands()) if cog.get_commands() else "No commands!"
        embed.add_field(name="Commands:", value=field_value)

        await self.get_destination().send(embed=embed)
Esempio n. 3
0
def brief_cog(cog: Cog):
    brief = literals('cog_brief')['no_description']
    if cog.description is not None:
        brief = cog.description
    elif cog.get_commands():
        brief = ''
    if not cog.get_commands():
        return brief
    commands = ''
    for command in cog.get_commands():
        commands += brief_command(command) + '\n'
    if commands:
        brief += '\n' + commands
    return brief
Esempio n. 4
0
    async def send_cog_help(self, cog: commands.Cog):
        """The coroutine to run when requested help for a Cog
        
        Parameters
        ----------
        cog: discord.ext.commands.Cog
            The cog requested
        """

        cmds = cog.get_commands()

        # filter commands for the ones that pass all checks
        cmds = await self.filter_commands(cmds, sort=True)

        pages = []
        current_page = []
        if len(cmds) > per_page:

            # splits the cog into multiple pages
            for i in range(0, len(cmds), per_page):
                end_index = i + per_page
                current_page.append((cog, cmds[i:end_index]))
                pages.append(current_page)

        else:
            current_page.append((cog, cmds))
            pages.append(current_page)

        paginator = BotOrCogHelp(self, self.context.bot, self.context, pages)

        await paginator.paginate()
Esempio n. 5
0
    async def send_cog_help(self, cog: commands.Cog):
        locale = self.context.bot.system.locale
        e = discord.Embed()

        fmt = locale("__{0} help__\n").format(
            getattr(cog, "locale_name", cog.qualified_name))

        cmds = await self.filter_commands(cog.get_commands())
        if not cmds:
            return await self.context.send(
                self.command_not_found(cog.qualified_name))

        for command in cmds:
            sig = self.get_command_signature(command)
            fmt += "|- " + sig + "\n"
            if command.short_doc:
                fmt += "|  | " + command.short_doc + "\n"

            if isinstance(command, GroupWithLocale):
                subs = command.commands
                for sub in subs:
                    fmt += "|  |- " + self.get_command_signature(sub) + "\n"

        e.description = fmt

        await self.context.send(embed=e)
Esempio n. 6
0
 async def send_cog_help(self, cog: commands.Cog):
     async with self.get_destination().typing():
         filtered = await self.filter_commands(
             cog.get_commands(), sort=self.sort_commands
         )
         self.paginator.add_cog(cog, filtered)
     await self.send_pages()
Esempio n. 7
0
    async def cog(self, ctx, cog: commands.Cog):
        "return cog commands"

        emb = discord.Embed(title=cog.qualified_name,
                            description="",
                            colour=discord.Colour.from_hsv(
                                random.random(), 1, 1),
                            timestamp=ctx.message.created_at)
        emb.set_author(name=ctx.author,
                       icon_url=str(
                           ctx.author.avatar_url_as(static_format="png")))

        commands = cog.get_commands()
        commands = [cmd for cmd in commands if not cmd.hidden]

        cog_str = ""

        if len(commands) >= 1:
            for command in commands:
                cog_str += f"{self.bot.clean_prefix}{command.name} {command.signature}\n" if command.signature else f"{self.bot.clean_prefix}{command.name}\n"

                try:
                    for cmd in command.commands:
                        cog_str += f"{self.bot.clean_prefix}{cmd.parent} {cmd.name} {cmd.signature}\n" if command.signature else f"{self.bot.clean_prefix}{cmd.parent} {cmd.name}\n"
                except:
                    pass

            emb.description = f"```prolog\n{cog_str}\n```"

        else:
            return await self.cog_not_found(ctx, cog.qualified_name)

        return await ctx.send(embed=emb)
Esempio n. 8
0
    async def call_after_hooks(self, ctx: Context) -> None:
        cog = self.cog
        cogcmd = self.cogcmd
        if self._after_invoke is not None:
            _earg = self._get_extra_arg(self._after_invoke)
            if _earg:
                _arg: Union[Tuple[Union[Cog, CCmd, None], Context],
                            Tuple[Context]] = (_earg, ctx)
            else:
                _arg = (ctx, )
            await self.call_if_overridden(self._after_invoke, *_arg)

        if cogcmd is not None:
            await self.call_if_overridden(cogcmd.subcommand_after_invoke, ctx)

        # call the cog local hook if applicable:
        if cog is not None:
            hook = Cog._get_overridden_method(cog.cog_after_invoke)
            if hook is not None:
                await hook(ctx)

        # call the bot global hook if necessary
        hook = ctx.bot._after_invoke
        if hook is not None:
            await hook(ctx)
Esempio n. 9
0
    async def send_cog_help(self, cog: Cog):
        """
        Async method that will send the specified Cog info in embed format

        Parameters
        ----------
        cog: Cog
            the cog requesting more info for
        """
        if self.checked():
            return

        embed = discord.Embed(colour=self.paginator.color,
                              title=f"**__{cog.qualified_name}__** Cog",
                              description="__Commands__:")

        filtered = await self.filter_commands(cog.get_commands(),
                                              sort=self.sort_commands)
        result = process_command_list(embed, filtered)
        icon = self.context.bot.user.avatar_url_as(size=64)

        for i in range(len(result)):
            result[i].set_footer(icon_url=icon,
                                 text=f"{i + 1} / {len(result)} Pages")
            await (self.context.author.send(embed=result[i])
                   if self.dm_help else self.context.reply(embed=result[i]))
Esempio n. 10
0
async def dispatch_error(self, ctx, error):
    ctx.command_failed = True
    cog = self.cog
    try:
        command_on_error = self.on_error
    except AttributeError:
        command_on_error = None

    handled = False

    if command_on_error is not None:
        wrapped_command_on_error = wrap_callback(command_on_error)

        try:
            if cog is not None:
                await wrapped_command_on_error(cog, ctx, error)
            else:
                await wrapped_command_on_error(ctx, error)
            handled = True
        except Exception as e:
            error = e

    if not handled and cog is None:
        cog_on_error = Cog._get_overridden_method(cog.cog_command_error)
        if cog_on_error is not None:
            wrapped_cog_on_error = wrap_callback(cog_on_error)
            try:
                await wrapped_cog_on_error(ctx, error)
                handled = True
            except Exception as e:
                error = e

    if not handled:
        ctx.bot.dispatch("command_error", ctx, error)
Esempio n. 11
0
 async def send_cog_help(self, cog: commands.Cog):
     if cog.qualified_name != "System":
         embed = discord.Embed()
         embed.colour = discord.Colour.dark_gold()
         embed.title = cog.qualified_name
         embed.set_author(name=self.context.bot.user.name,
                          icon_url=self.context.bot.user.avatar_url)
         for command in cog.get_commands():
             if command is not None and command in await self.filter_commands(
                     cog.get_commands()):
                 embed.add_field(name=command.name,
                                 value=command.help,
                                 inline=False)
         await self.context.send(embed=embed)
     else:
         await self.context.send("There is no cog named System!")
 async def send_cog_help(self, cog: commands.Cog) -> None:
     # Test if the current channel is correct
     result = await self.channelCheck()
     if result is None:
         # Create embed
         cogHelpEmbed = Embed(
             title=f"{self.getCogName(cog.qualified_name)} Help",
             colour=self.colour)
         cogHelpEmbed.set_footer(text=f"{len(cog.get_commands())} commands")
         for command in cog.get_commands():
             # Create aliases string
             aliases = self.createAliases(command)
             if aliases is not None:
                 cogHelpEmbed.add_field(
                     name=f"{self.clean_prefix}{command.qualified_name}",
                     value=f"{command.help}\n\n{aliases}",
                     inline=False)
             else:
                 cogHelpEmbed.add_field(
                     name=f"{self.clean_prefix}{command.qualified_name}",
                     value=f"{command.help}",
                     inline=False)
         # Send embed
         channel = self.get_destination()
         await channel.send(embed=cogHelpEmbed)
     else:
         await Utils.commandDebugEmbed(self.get_destination(), result)
Esempio n. 13
0
    async def cog(self, ctx, cog: commands.Cog):
        "return cog commands"

        def __init__(self, description=None):
            self.description = description

        emb = discord.Embed(title=cog.qualified_name,
                            description="",
                            colour=self.bot.colour,
                            timestamp=ctx.message.created_at)
        emb.set_author(name=ctx.author,
                       icon_url=str(
                           ctx.author.avatar_url_as(static_format="png")))

        commands = cog.get_commands()
        commands = [cmd for cmd in commands if not cmd.hidden]

        cog_str = f"**{cog.qualified_name.upper()}**\n"

        if len(commands) >= 1:
            for command in commands:
                cog_str += f"`{command.name} {command.signature}` " if command.signature else f"`{command.name}` "

                try:
                    for cmd in command.commands:
                        cog_str += f"`{cmd.parent} {cmd.name} {cmd.signature}` " if command.signature else f"`{cmd.parent} {cmd.name}` "
                except:
                    pass

            emb.description = cog_str

        else:
            return await self.cog_not_found(ctx, cog.qualified_name)

        return await ctx.send(embed=emb)
Esempio n. 14
0
 async def send_cog_help(self, cog: commands.Cog) -> None:
     """Send help for a cog."""
     ctx = self.context
     prefix = ctx.prefix
     embed = discord.Embed(
         title=cog.qualified_name,
         description=textwrap.dedent(
             f"""
             Help syntax : `<Required argument>`. `[t.Optional argument]`
             Command prefix: `{prefix}`
             {cog.description}
             """
         ),
         color=discord.Color.blue(),
     )
     embed.set_author(
         name=str(ctx.message.author),
         icon_url=str(ctx.message.author.avatar_url),
     )
     embed.set_thumbnail(url=str(ctx.bot.user.avatar_url))
     for command in await self.filter_commands(cog.get_commands()):
         embed.add_field(
             name=f"{prefix}{self.get_command_signature(command)}",
             value=command.help,
             inline=False,
         )
     embed.set_footer(
         text=f"Are you interested in {cog.qualified_name}?",
         icon_url=str(ctx.bot.user.avatar_url),
     )
     await ctx.send(embed=embed)
Esempio n. 15
0
 async def send_cog_help(self, cog: Cog, /):
     """Function that triggers when help command is used with a cog."""
     full_mapping = {
         com
         for com in cog.get_commands() if com.enabled and not com.hidden
     }
     await self._send_command_list(full_mapping)
    def get_cog_commands(self, cog: commands.Cog):
        """
        Gets slash command from :class:`discord.ext.commands.Cog`.

        .. note::
            Since version ``1.0.9``, this gets called automatically during cog initialization.

        :param cog: Cog that has slash commands.
        :type cog: discord.ext.commands.Cog
        """
        if hasattr(cog, '_slash_registered'):  # Temporary warning
            return self.logger.warning(
                "Calling get_cog_commands is no longer required "
                "to add cog slash commands. Make sure to remove all calls to this function."
            )
        cog._slash_registered = True  # Assuming all went well
        func_list = [getattr(cog, x) for x in dir(cog)]
        res = [
            x for x in func_list if isinstance(x, (model.CogBaseCommandObject,
                                                   model.CogSubcommandObject))
        ]
        for x in res:
            x.cog = cog
            if isinstance(x, model.CogBaseCommandObject):
                if x.name in self.commands:
                    raise error.DuplicateCommand(x.name)
                self.commands[x.name] = x
            else:
                if x.base in self.commands:
                    base_command = self.commands[x.base]
                    for i in x.allowed_guild_ids:
                        if i not in base_command.allowed_guild_ids:
                            base_command.allowed_guild_ids.append(i)

                    base_permissions = x.base_command_data["api_permissions"]
                    if base_permissions:
                        for applicable_guild in base_permissions:
                            if applicable_guild not in base_command.permissions:
                                base_command.permissions[applicable_guild] = []
                            base_command.permissions[applicable_guild].extend(
                                base_permissions[applicable_guild])

                    self.commands[x.base].has_subcommands = True

                else:
                    self.commands[x.base] = model.BaseCommandObject(
                        x.base, x.base_command_data)
                if x.base not in self.subcommands:
                    self.subcommands[x.base] = {}
                if x.subcommand_group:
                    if x.subcommand_group not in self.subcommands[x.base]:
                        self.subcommands[x.base][x.subcommand_group] = {}
                    if x.name in self.subcommands[x.base][x.subcommand_group]:
                        raise error.DuplicateCommand(
                            f"{x.base} {x.subcommand_group} {x.name}")
                    self.subcommands[x.base][x.subcommand_group][x.name] = x
                else:
                    if x.name in self.subcommands[x.base]:
                        raise error.DuplicateCommand(f"{x.base} {x.name}")
                    self.subcommands[x.base][x.name] = x
Esempio n. 17
0
 def create_musics(self,
                   ctx: commands.Context,
                   music_cog: commands.Cog = None):
     if music_cog:
         return dict(musics=music_cog.urls(ctx))
     else:
         return dict(musics=[])
Esempio n. 18
0
    def get_cog_commands(self, cog: commands.Cog):
        """
        Gets slash command from :class:`discord.ext.commands.Cog`.

        .. note::
            Since version ``1.0.9``, this gets called automatically during cog initialization.

        :param cog: Cog that has slash commands.
        :type cog: discord.ext.commands.Cog
        """
        if hasattr(cog, "_slash_registered"):  # Temporary warning
            return self.logger.warning(
                "Calling get_cog_commands is no longer required "
                "to add cog slash commands. Make sure to remove all calls to this function."
            )
        cog._slash_registered = True  # Assuming all went well
        func_list = [getattr(cog, x) for x in dir(cog)]
        res = [
            x
            for x in func_list
            if isinstance(x, (model.CogCommandObject, model.CogSubcommandObject))
        ]
        for x in res:
            x.cog = cog
            if isinstance(x, model.CogCommandObject):
                if x.name in self.commands:
                    raise error.DuplicateCommand(x.name)
                self.commands[x.name] = x
            else:
                if x.base in self.commands:
                    for i in x.allowed_guild_ids:
                        if i not in self.commands[x.base].allowed_guild_ids:
                            self.commands[x.base].allowed_guild_ids.append(i)
                    self.commands[x.base].has_subcommands = True
                else:
                    _cmd = {
                        "func": None,
                        "description": x.base_description,
                        "auto_convert": {},
                        "guild_ids": x.allowed_guild_ids.copy(),
                        "api_options": [],
                        "has_subcommands": True,
                        "connector": {},
                    }
                    self.commands[x.base] = model.CommandObject(x.base, _cmd)
                if x.base not in self.subcommands:
                    self.subcommands[x.base] = {}
                if x.subcommand_group:
                    if x.subcommand_group not in self.subcommands[x.base]:
                        self.subcommands[x.base][x.subcommand_group] = {}
                    if x.name in self.subcommands[x.base][x.subcommand_group]:
                        raise error.DuplicateCommand(
                            f"{x.base} {x.subcommand_group} {x.name}"
                        )
                    self.subcommands[x.base][x.subcommand_group][x.name] = x
                else:
                    if x.name in self.subcommands[x.base]:
                        raise error.DuplicateCommand(f"{x.base} {x.name}")
                    self.subcommands[x.base][x.name] = x
Esempio n. 19
0
    def build_list_cog_help(self, cog: commands.Cog) -> str:
        result_string = f'{self.emoji_mapping[cog.qualified_name]} Here is a list of commands in the `{cog.qualified_name}` category\n'

        cmds: List[commands.Command] = sorted(cog.get_commands(),
                                              key=lambda x: x.name)
        for cmd in cmds:
            result_string += f'`{cmd.name}` - {cmd.description}\n'
        return result_string
Esempio n. 20
0
 async def send_cog_help(self, cog: commands.Cog):
     embed = Embed('Commands in ' + cog.qualified_name)
     for cmd in cog.walk_commands():
         embed.description += f'**{cmd.name}**: {cmd.help}\n'
     embed.set_footer(text='Version ' + cog.description.split('Version')[1])
     await self.context.reply(
         f"Send `{await self.context.bot.get_prefix(self.context.message)}help <command>`!",
         embed=embed)
Esempio n. 21
0
 async def send_cog_help(self, cog: commands.Cog) -> None:
     allowed_commands = await self.filter_commands(cog.get_commands())
     embed = discord.Embed(title=cog.qualified_name,
                           description="\n".join(
                               f"`{command.name}` - {command.short_doc}"
                               for command in allowed_commands),
                           color=discord.Color.blue())
     await self.send_embed(embed)
Esempio n. 22
0
    def __init__(self, cog: Cog, prefix: str, *, per_page=3):
        if not isinstance(cog, Cog):
            raise TypeError("a valid cog wasn't passed")

        self._prefix = prefix
        self._doc = Embed(title=cog.qualified_name,
                          description=cog.description,
                          color=get_color())
        super().__init__(cog.get_commands(), per_page=per_page)
Esempio n. 23
0
 async def send_cog_help(self, cog: commands.Cog):
     embed = self.embed
     embed.set_author(name=f"Commands in the {cog.qualified_name} Category")
     embed.description = f"Use `{self.context.bot.command_prefix}help [command]` for more information."
     for cmd in cog.get_commands():
         embed.add_field(name=f"`{self.get_cmd_string(cmd)}`",
                         value=cmd.brief if cmd.brief else cmd.help,
                         inline=False)
     await self.get_destination().send(embed=embed)
Esempio n. 24
0
def get_cog_commands(cog: Cog, include_hidden=False) -> Dict[str, Command]:
    commands = {}
    for command in cog.get_commands():
        hidden = command.hidden if not include_hidden else False
        if not hidden:
            commands[command.name] = command
        if isinstance(command, Group):
            commands.update(get_group_commands(command))
    return commands
Esempio n. 25
0
    async def send_cog_help(self, cog: commands.Cog):
        embed = discord.Embed(title=f"Help for {cog.qualified_name}")
        for command in cog.get_commands():
            embed.add_field(
                name=self.get_command_signature(command),
                value=command.short_doc or "No help provided...",
                inline=False,
            )

        await self.get_destination().send(embed=embed)
 async def send_cog_help(self, cog: commands.Cog):
     if cog.qualified_name != "System":
         embed = discord.Embed()
         embed.colour = discord.Colour.dark_gold()
         embed.title = cog.qualified_name
         embed.description = cog.__doc__.format(prefix_1=self.clean_prefix) if cog.__doc__ else "Information about this module not available. Owner has forgot to add " \
                                                                                                "information to this cog or he may be adding information to the cog."
         embed.set_author(name=self.context.bot.user.name,
                          icon_url=self.context.bot.user.avatar_url)
         for command in cog.get_commands():
             if command is not None and command in await self.filter_commands(
                     cog.get_commands()):
                 embed.add_field(
                     name=f"`{self.clean_prefix}{command.name}`",
                     value=command.help,
                     inline=False)
         await self.context.send(embed=embed)
     else:
         await self.context.send("There is no cog named System!")
Esempio n. 27
0
    async def send_cog_help(self, cog: commands.Cog):
        """Sends help for an entire cog.

        Args:
            cog (commands.Cog): The cog to send help for.
        """
        async with self.get_destination().typing():
            filtered = await self.filter_commands(cog.get_commands(),
                                                  sort=self.sort_commands)
            self.paginator.add_cog(cog, filtered)
        await self.send_pages()
Esempio n. 28
0
    async def send_cog_help(self, cog: commands.Cog):
        ctx = self.context
        embed = discord.Embed(title=f"Help for {cog.qualified_name}")
        embed.set_footer(text=f"Do {self.clean_prefix}help [command] for more help")

        entries = await self.filter_commands(cog.get_commands(), sort=True)
        for cmd in entries:
            embed.add_field(name=f"{self.clean_prefix}{cmd.name} {cmd.signature}",
                            value=f"{cmd.help}",
                            inline=False)

        await ctx.send(embed=embed)
Esempio n. 29
0
    async def send_cog_help(self, cog: commands.Cog):
        e = discord.Embed(title=cog.qualified_name,
                          description=cog.description or 'No help provided.')

        filtered = await self.filter_commands(cog.get_commands(), sort=True)

        if filtered:
            for command in filtered:
                e.add_field(name=self.get_command_signature(command),
                            value=command.short_doc or 'No help provided.')

        await self.context.send(embed=e)
Esempio n. 30
0
    async def send_cog_help(self, cog: commands.Cog):
        pages = []

        await self.format_commands(
            cog, await self.filter_commands(cog.get_commands(), sort=True), pages=pages
        )

        total = len(pages)
        for i, embed in enumerate(pages, start=1):
            embed.title = f"Page {i}/{total}: {embed.title}"

        pg = RoboPages(HelpSource(range(0, len(pages)), pages))
        await pg.start(self.context)