aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-01-23 03:43:54 -0500
committerRapptz <[email protected]>2016-01-23 03:43:54 -0500
commitbb5e222f29863368a3f4708c9a798efb1f6f19dd (patch)
tree690d84b22788c917d2a9eb153942b7ff12aaff0d
parent[commands] Change Bot.pm_help to be an optional bool. (diff)
downloaddiscord.py-bb5e222f29863368a3f4708c9a798efb1f6f19dd.tar.xz
discord.py-bb5e222f29863368a3f4708c9a798efb1f6f19dd.zip
[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.
-rw-r--r--discord/ext/commands/bot.py17
-rw-r--r--discord/ext/commands/formatter.py5
2 files changed, 18 insertions, 4 deletions
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py
index d1df7fc2..5530beb4 100644
--- a/discord/ext/commands/bot.py
+++ b/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
diff --git a/discord/ext/commands/formatter.py b/discord/ext/commands/formatter.py
index f06c487b..0a052776 100644
--- a/discord/ext/commands/formatter.py
+++ b/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