Exemplo n.º 1
0
async def _default_help_command(ctx, *commands: str):
    """Shows this message."""
    bot = ctx.bot
    destination = ctx.message.author if bot.pm_help else ctx.message.channel

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

    # help by itself just lists our own commands.
    if len(commands) == 0:
        pages = bot.formatter.format_help_for(ctx, bot)
    elif len(commands) == 1:
        # try to see if it is a cog name
        name = _mention_pattern.sub(repl, commands[0])
        command = None
        if name in [x.lower() for x in bot.cogs]:
            command = bot.cogs[[x for x in bot.cogs if x.lower() == name][0]]
        else:
            command = bot.commands.get(name)
            if command is None:
                await bot.responses.failure(
                    destination=destination,
                    message=bot.command_not_found.format(name))
                return

        pages = bot.formatter.format_help_for(ctx, command)
    else:
        name = _mention_pattern.sub(repl, commands[0])
        command = bot.commands.get(name)
        if command is None:
            await bot.responses.failure(
                destination=destination,
                message=bot.command_not_found.format(name))
            return

        for key in commands[1:]:
            try:
                key = _mention_pattern.sub(repl, key)
                command = command.commands.get(key)
                if command is None:
                    await bot.responses.failure(
                        destination=destination,
                        message=bot.command_not_found.format(name))
                    return
            except AttributeError:
                await bot.responses.failure(
                    destination=destination,
                    message=bot.command_has_no_subcommands.format(
                        command, key))
                return

        pages = bot.formatter.format_help_for(ctx, command)

    if bot.pm_help is None:
        characters = sum(map(lambda l: len(l), pages.values()))
        if characters > 1000:
            destination = ctx.message.author

    await bot.responses.full(destination=destination, **pages)
Exemplo n.º 2
0
    async def help(self, ctx, command: str = None):
        """Shows this message."""
        def repl(obj):
            return _mentions_transforms.get(obj.group(0), '')

        # help by itself just lists our own commands.
        if command == "all":
            embed = await self.bot.formatter.format_as_embed(
                ctx, self.bot, True)
        elif command == None:
            embed = await self.bot.formatter.format_as_embed(
                ctx, self.bot, False)
        else:
            # try to see if it is a cog name
            name = _mention_pattern.sub(repl, command).lower()
            if name in map(lambda c: c.lower(), self.bot.cogs):
                for cog in self.bot.cogs:
                    if cog.lower() == name:
                        command = self.bot.cogs[cog]
            else:
                command = self.bot.all_commands.get(name)
                if command is None:
                    await ctx.send(self.bot.command_not_found.format(name))
                    return
            embed = await self.bot.formatter.format_as_embed(ctx, command)

        await ctx.send(embed=embed)
Exemplo n.º 3
0
    async def _help(self, ctx, *commands, type=Formatter.ExtendedFilter):
        """Shows this message."""
        author = ctx.author
        if isinstance(ctx.author, discord.User):
            type = Formatter.Generic

        bot = ctx.bot
        destination = ctx.message.channel
        is_owner = author.id == self.owner_id

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

        # help by itself just lists our own commands.
        if len(commands) == 0:
            pages = await self.formatter.format_help_for(ctx,
                                                         self,
                                                         is_owner=is_owner,
                                                         type=type)
        elif len(commands) == 1:
            # try to see if it is a cog name
            name = _mention_pattern.sub(repl, commands[0])
            command = None
            if name in bot.cogs:
                command = bot.cogs[name]
            else:
                command = bot.all_commands.get(name)
                if command is None:
                    await destination.send(bot.command_not_found.format(name))
                    return

            pages = await self.formatter.format_help_for(ctx,
                                                         command,
                                                         is_owner=is_owner,
                                                         type=type)
        else:
            name = _mention_pattern.sub(repl, commands[0])
            command = bot.all_commands.get(name)
            if command is None:
                await destination.send(bot.command_not_found.format(name))
                return

            for key in commands[1:]:
                try:
                    key = _mention_pattern.sub(repl, key)
                    command = command.all_commands.get(key)
                    if command is None:
                        await destination.send(
                            bot.command_not_found.format(key))
                        return
                except AttributeError:
                    await destination.send(
                        bot.command_has_no_subcommands.format(command, key))
                    return

            pages = await self.formatter.format_help_for(ctx,
                                                         commands,
                                                         is_owner=is_owner,
                                                         type=type)

        for page in pages:
            await destination.send(embed=page)
Exemplo n.º 4
0
    async def help(self, ctx, *commands: str):
        '''
		Shows this message
		Note: If you are not currently able to use a command in the channel where you executed help, it will not be displayed in the corresponding help message
		'''
        if len(commands) == 0:
            embed = discord.Embed(title="Categories", color=clients.bot_color)
            avatar = ctx.message.author.avatar_url or ctx.message.author.default_avatar_url
            embed.set_author(name=ctx.message.author.display_name,
                             icon_url=avatar)
            embed.description = "  ".join(
                "__{}__".format(category)
                for category in sorted(self.bot.cogs, key=str.lower))
            embed.add_field(
                name="For more info:",
                value=
                "`{0}{1} [category]`\n`{0}{1} [command]`\n`{0}{1} [command] [subcommand]`"
                .format(ctx.prefix, ctx.invoked_with))
            embed.add_field(name="Also see:",
                            value="`{0}about`\n`{0}{1} other`".format(
                                ctx.prefix, ctx.invoked_with))  # stats?
            embed.add_field(name="For all commands:",
                            value="`{}{} all`".format(ctx.prefix,
                                                      ctx.invoked_with),
                            inline=False)
            await self.bot.say(embed=embed)
            return

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

        if len(commands) == 1:
            name = _mention_pattern.sub(repl, commands[0])
            if name in self.bot.cogs:
                command = self.bot.cogs[name]
            elif name.lower() in self.bot.commands:
                command = self.bot.commands[name.lower()]
            elif name.lower() in [cog.lower() for cog in self.bot.cogs.keys()
                                  ]:  # more efficient way?
                command = discord.utils.find(
                    lambda c: c[0].lower() == name.lower(),
                    self.bot.cogs.items())[1]
            else:
                output = self.command_not_found.format(name)
                close_matches = difflib.get_close_matches(
                    name, self.bot.commands.keys(), n=1)
                if close_matches:
                    output += "\nDid you mean `{}`?".format(close_matches[0])
                await self.bot.embed_reply(output)
                return
            embeds = self.bot.formatter.format_help_for(ctx, command)
        else:
            name = _mention_pattern.sub(repl, commands[0])
            command = self.bot.commands.get(name)
            if command is None:
                await self.bot.embed_reply(self.command_not_found.format(name))
                return
            for key in commands[1:]:
                try:
                    key = _mention_pattern.sub(repl, key)
                    command = command.commands.get(key)
                    if command is None:
                        await self.bot.embed_reply(
                            self.command_not_found.format(key))
                        return
                except AttributeError:
                    await self.bot.embed_reply(
                        "`{}` command has no subcommands".format(command.name))
                    return
            embeds = self.bot.formatter.format_help_for(ctx, command)

        if len(embeds) > 1:
            destination = ctx.message.author
            if not ctx.message.channel.is_private:
                await self.bot.embed_reply("Check your DMs")
        else:
            destination = ctx.message.channel
        for embed in embeds:
            if destination == ctx.message.channel:
                avatar = ctx.message.author.avatar_url or ctx.message.author.default_avatar_url
                embed.set_author(name=ctx.message.author.display_name,
                                 icon_url=avatar)
            await self.bot.send_message(destination, embed=embed)