Esempio n. 1
0
async def help(ctx: commands.Context, *, command_name: str = ""):
    """Show help documentation.

    - `[p]help`: Show the help manual.
    - `[p]help command`: Show help for a command.
    - `[p]help Category`: Show commands and description for a category,
    """
    bot = ctx.bot
    if bot.pm_help:
        destination = ctx.author
    else:
        destination = ctx.channel

    use_embeds = await ctx.embed_requested()
    if use_embeds:
        formatter = bot.formatter
    else:
        formatter = dpy_formatter.HelpFormatter()

    if not command_name:
        # help by itself just lists our own commands.
        pages = await formatter.format_help_for(ctx, bot)
    else:
        # First check if it's a cog
        command = bot.get_cog(command_name)
        if command is None:
            command = bot.get_command(command_name)
        if command is None:
            if hasattr(formatter, "format_command_not_found"):
                msg = await formatter.format_command_not_found(ctx, command_name)
            else:
                msg = await default_command_not_found(ctx, command_name, use_embeds=use_embeds)
            pages = [msg]
        else:
            pages = await formatter.format_help_for(ctx, command)

    max_pages_in_guild = await ctx.bot.db.help.max_pages_in_guild()
    if len(pages) > max_pages_in_guild:
        destination = ctx.author
    if ctx.guild and not ctx.guild.me.permissions_in(ctx.channel).send_messages:
        destination = ctx.author
    try:
        for page in pages:
            if isinstance(page, discord.Embed):
                await destination.send(embed=page)
            else:
                await destination.send(page)
    except discord.Forbidden:
        await ctx.channel.send(
            _(
                "I couldn't send the help message to you in DM. Either you blocked me or you "
                "disabled DMs in this server."
            )
        )
Esempio n. 2
0
 def __unload(self):
     print('called __unload')
     self.bot.formatter = formatter.HelpFormatter()
     self.bot.add_command(orig_help)
Esempio n. 3
0
 def __unload(self):
     self.bot.formatter = formatter.HelpFormatter()
     self.bot.add_command(orig_help)
Esempio n. 4
0
async def help(ctx, *cmds: str):
    """Shows help documentation.

    [p]**help**: Shows the help manual.
    [p]**help** command: Show help for a command
    [p]**help** Category: Show commands and description for a category"""
    destination = ctx.author if ctx.bot.pm_help else ctx

    def repl(obj):
        return _mentions_transforms.get(obj.group(0), "")

    use_embeds = await ctx.embed_requested()
    f = formatter.HelpFormatter()
    # help by itself just lists our own commands.
    if len(cmds) == 0:
        if use_embeds:
            embeds = await ctx.bot.formatter.format_help_for(ctx, ctx.bot)
        else:
            embeds = await f.format_help_for(ctx, ctx.bot)
    elif len(cmds) == 1:
        # try to see if it is a cog name
        name = _mention_pattern.sub(repl, cmds[0])
        command = None
        if name in ctx.bot.cogs:
            command = ctx.bot.cogs[name]
        else:
            command = ctx.bot.all_commands.get(name)
            if command is None:
                if use_embeds:
                    fuzzy_result = await fuzzy_command_search(ctx, name)
                    if fuzzy_result is not None:
                        await destination.send(
                            embed=await ctx.bot.formatter.cmd_not_found(
                                ctx, name, description=fuzzy_result))
                else:
                    fuzzy_result = await fuzzy_command_search(ctx, name)
                    if fuzzy_result is not None:
                        await destination.send(
                            ctx.bot.command_not_found.format(
                                name, fuzzy_result))
                return
        if use_embeds:
            embeds = await ctx.bot.formatter.format_help_for(ctx, command)
        else:
            embeds = await f.format_help_for(ctx, command)
    else:
        name = _mention_pattern.sub(repl, cmds[0])
        command = ctx.bot.all_commands.get(name)
        if command is None:
            if use_embeds:
                fuzzy_result = await fuzzy_command_search(ctx, name)
                if fuzzy_result is not None:
                    await destination.send(
                        embed=await ctx.bot.formatter.cmd_not_found(
                            ctx, name, description=fuzzy_result))
            else:
                fuzzy_result = await fuzzy_command_search(ctx, name)
                if fuzzy_result is not None:
                    await destination.send(
                        ctx.bot.command_not_found.format(name, fuzzy_result))
            return

        for key in cmds[1:]:
            try:
                key = _mention_pattern.sub(repl, key)
                command = command.all_commands.get(key)
                if command is None:
                    if use_embeds:
                        fuzzy_result = await fuzzy_command_search(ctx, name)
                        if fuzzy_result is not None:
                            await destination.send(
                                embed=await ctx.bot.formatter.cmd_not_found(
                                    ctx, name, description=fuzzy_result))
                    else:
                        fuzzy_result = await fuzzy_command_search(ctx, name)
                        if fuzzy_result is not None:
                            await destination.send(
                                ctx.bot.command_not_found.format(
                                    name, fuzzy_result))
                    return
            except AttributeError:
                if use_embeds:
                    await destination.send(
                        embed=await ctx.bot.formatter.simple_embed(
                            ctx,
                            title='Command "{0.name}" has no subcommands.'.
                            format(command),
                            color=await ctx.bot.formatter.color(),
                        ))
                else:
                    await destination.send(
                        ctx.bot.command_has_no_subcommands.format(command))
                return
        if use_embeds:
            embeds = await ctx.bot.formatter.format_help_for(ctx, command)
        else:
            embeds = await f.format_help_for(ctx, command)

    max_pages_in_guild = await ctx.bot.db.help.max_pages_in_guild()
    if len(embeds) > max_pages_in_guild:
        destination = ctx.author
    try:
        for embed in embeds:
            if use_embeds:
                try:
                    await destination.send(embed=embed)
                except discord.HTTPException:
                    destination = ctx.author
                    await destination.send(embed=embed)
            else:
                try:
                    await destination.send(embed)
                except discord.HTTPException:
                    destination = ctx.author
                    await destination.send(embed)
    except discord.Forbidden:
        await ctx.channel.send(
            "I couldn't send the help message to you in DM. Either you blocked me or you disabled DMs in this server."
        )
Esempio n. 5
0
async def help(ctx, *cmds: str):
    """Shows help documentation.

    [p]**help**: Shows the help manual.
    [p]**help** command: Show help for a command
    [p]**help** Category: Show commands and description for a category"""
    destination = ctx.author if ctx.bot.pm_help else ctx

    def repl(obj):
        return _mentions_transforms.get(obj.group(0), "")

    use_embeds = await ctx.bot.embed_requested(
        ctx.channel, ctx.author, command=ctx.command
    )
    if ctx.guild and not ctx.channel.permissions_for(ctx.guild.me).embed_links:
        use_embeds = False
    # use_embeds = await ctx.embed_requested()
    f = formatter.HelpFormatter()
    # help by itself just lists our own commands.
    if len(cmds) == 0:
        if use_embeds:
            embeds = await ctx.bot.formatter.format_help_for(ctx, ctx.bot)
        else:
            embeds = await f.format_help_for(ctx, ctx.bot)
    elif len(cmds) == 1:
        # try to see if it is a cog name
        name = _mention_pattern.sub(repl, cmds[0])
        command = None
        if name in ctx.bot.cogs:
            command = ctx.bot.cogs[name]
        else:
            command = ctx.bot.all_commands.get(name)
        if use_embeds:
            embeds = await ctx.bot.formatter.format_help_for(ctx, command)
        else:
            embeds = await f.format_help_for(ctx, command)
    else:
        name = _mention_pattern.sub(repl, cmds[0])
        command = ctx.bot.all_commands.get(name)
        for key in cmds[1:]:
            try:
                key = _mention_pattern.sub(repl, key)
                command = command.all_commands.get(key)
            except AttributeError:
                if use_embeds:
                    await destination.send(
                        embed=await ctx.bot.formatter.simple_embed(
                            ctx,
                            title='Command "{0.name}" has no subcommands.'.format(command),
                            color=await ctx.bot.formatter.color(),
                        )
                    )
                else:
                    await destination.send(ctx.bot.command_has_no_subcommands.format(command))
                return
        if use_embeds:
            embeds = await ctx.bot.formatter.format_help_for(ctx, command)
        else:
            embeds = await f.format_help_for(ctx, command)

    max_pages_in_guild = await ctx.bot.conf.help.max_pages_in_guild()
    if len(embeds) > max_pages_in_guild:
        destination = ctx.author

    for embed in embeds:
        if use_embeds:
            try:
                await destination.send(embed=embed)
            except discord.HTTPException:
                destination = ctx.author
                await destination.send(embed=embed)
        else:
            try:
                await destination.send(embed)
            except discord.HTTPException:
                destination = ctx.author
                await destination.send(embed)