Browse Source

[commands] Add Bot.help_attrs to customise the help command.

The help message now uses the invoked_with attribute of the context to
get the name of the command it uses instead of a hardcoded help.
pull/95/head
Rapptz 9 years ago
parent
commit
bb5e222f29
  1. 17
      discord/ext/commands/bot.py
  2. 5
      discord/ext/commands/formatter.py

17
discord/ext/commands/bot.py

@ -51,7 +51,6 @@ def when_mentioned(bot, msg):
to being mentioned, e.g. ``@bot ``."""
return '{0.user.mention} '.format(bot)
@command(pass_context=True, name='help')
@asyncio.coroutine
def _default_help_command(ctx, *commands : str):
"""Shows this message."""
@ -142,6 +141,12 @@ class Bot(GroupMixin, discord.Client):
output is PM'd. If ``None``, then the bot will only PM when the help
message becomes too long (dictated by more than 1000 characters).
Defaults to ``False``.
help_attrs : dict
A dictionary of options to pass in for the construction of the help command.
This allows you to change the command behaviour without actually changing
the implementation of the command. The attributes will be the same as the
ones passed in the :class:`Command` constructor. Note that ``pass_context``
will always be set to ``True`` regardless of what you pass in.
"""
def __init__(self, command_prefix, formatter=None, description=None, pm_help=False, **options):
super().__init__(**options)
@ -151,6 +156,13 @@ class Bot(GroupMixin, discord.Client):
self.extensions = {}
self.description = inspect.cleandoc(description) if description else ''
self.pm_help = pm_help
self.help_attrs = options.pop('help_attrs', {})
self.help_attrs['pass_context'] = True
if 'name' not in self.help_attrs:
self.help_attrs['name'] = 'help'
if formatter is not None:
if not isinstance(formatter, HelpFormatter):
raise discord.ClientException('Formatter must be a subclass of HelpFormatter')
@ -158,7 +170,8 @@ class Bot(GroupMixin, discord.Client):
else:
self.formatter = HelpFormatter()
self.add_command(_default_help_command)
# pay no mind to this ugliness.
self.command(**self.help_attrs)(_default_help_command)
# internal helpers

5
discord/ext/commands/formatter.py

@ -160,8 +160,9 @@ class HelpFormatter:
return ' '.join(result)
def get_ending_note(self):
return "Type {0}help command for more info on a command.\n" \
"You can also type {0}help category for more info on a category.".format(self.clean_prefix)
command_name = self.context.invoked_with
return "Type {0}{1} command for more info on a command.\n" \
"You can also type {0}{1} category for more info on a category.".format(self.clean_prefix, command_name)
def filter_command_list(self):
"""Returns a filtered list of commands based on the two attributes

Loading…
Cancel
Save