Browse Source

[commands] Add back dm_help tribool for the provided HelpCommands

Also add a dm_help_threshold integer to control the length.
pull/1987/head
Rapptz 6 years ago
parent
commit
61f63a9346
  1. 42
      discord/ext/commands/help.py

42
discord/ext/commands/help.py

@ -772,6 +772,16 @@ class DefaultHelpCommand(HelpCommand):
Defaults to 80. Defaults to 80.
sort_commands: :class:`bool` sort_commands: :class:`bool`
Whether to sort the commands in the output alphabetically. Defaults to ``True``. Whether to sort the commands in the output alphabetically. Defaults to ``True``.
dm_help: Optional[:class:`bool`]
A tribool that indicates if the help command should DM the user instead of
sending it to the channel it received it from. If the boolean is set to
``True``, then all help output is DM'd. If ``False``, none of the help
output is DM'd. If ``None``, then the bot will only DM when the help
message becomes too long (dictated by more than :attr:`dm_help_threshold` characters).
Defaults to ``False``.
dm_help_threshold: Optional[:class:`int`]
The number of characters the paginator must accumulate before getting DM'd to the
user if :attr:`dm_help` is set to ``None``. Defaults to 1000.
indent: :class:`int` indent: :class:`int`
How much to intend the commands from a heading. Defaults to ``2``. How much to intend the commands from a heading. Defaults to ``2``.
commands_heading: :class:`str` commands_heading: :class:`str`
@ -788,6 +798,8 @@ class DefaultHelpCommand(HelpCommand):
self.width = options.pop('width', 80) self.width = options.pop('width', 80)
self.indent = options.pop('indent', 2) self.indent = options.pop('indent', 2)
self.sort_commands = options.pop('sort_commands', True) self.sort_commands = options.pop('sort_commands', True)
self.dm_help = options.pop('dm_help', False)
self.dm_help_threshold = options.pop('dm_help_threshold', 1000)
self.commands_heading = options.pop('commands_heading', "Commands:") self.commands_heading = options.pop('commands_heading', "Commands:")
self.no_category = options.pop('no_category', 'No Category') self.no_category = options.pop('no_category', 'No Category')
self.paginator = options.pop('paginator', None) self.paginator = options.pop('paginator', None)
@ -869,6 +881,15 @@ class DefaultHelpCommand(HelpCommand):
if command.help: if command.help:
self.paginator.add_line(command.help, empty=True) self.paginator.add_line(command.help, empty=True)
def get_destination(self):
ctx = self.context
if self.dm_help is True:
return ctx.author
elif self.dm_help is None and len(self.paginator) > self.dm_help_threshold:
return ctx.author
else:
return ctx.channel
async def prepare_help_command(self, ctx, command): async def prepare_help_command(self, ctx, command):
self.paginator.clear() self.paginator.clear()
@ -949,6 +970,16 @@ class MinimalHelpCommand(HelpCommand):
aliases_heading: :class:`str` aliases_heading: :class:`str`
The alias list's heading string used to list the aliases of the command. Useful for i18n. The alias list's heading string used to list the aliases of the command. Useful for i18n.
Defaults to ``"Aliases:"``. Defaults to ``"Aliases:"``.
dm_help: Optional[:class:`bool`]
A tribool that indicates if the help command should DM the user instead of
sending it to the channel it received it from. If the boolean is set to
``True``, then all help output is DM'd. If ``False``, none of the help
output is DM'd. If ``None``, then the bot will only DM when the help
message becomes too long (dictated by more than :attr:`dm_help_threshold` characters).
Defaults to ``False``.
dm_help_threshold: Optional[:class:`int`]
The number of characters the paginator must accumulate before getting DM'd to the
user if :attr:`dm_help` is set to ``None``. Defaults to 1000.
no_category: :class:`str` no_category: :class:`str`
The string used when there is a command which does not belong to any category(cog). The string used when there is a command which does not belong to any category(cog).
Useful for i18n. Defaults to ``"No Category"`` Useful for i18n. Defaults to ``"No Category"``
@ -959,6 +990,8 @@ class MinimalHelpCommand(HelpCommand):
def __init__(self, **options): def __init__(self, **options):
self.sort_commands = options.pop('sort_commands', True) self.sort_commands = options.pop('sort_commands', True)
self.commands_heading = options.pop('commands_heading', "Commands") self.commands_heading = options.pop('commands_heading', "Commands")
self.dm_help = options.pop('dm_help', False)
self.dm_help_threshold = options.pop('dm_help_threshold', 1000)
self.aliases_heading = options.pop('aliases_heading', "Aliases:") self.aliases_heading = options.pop('aliases_heading', "Aliases:")
self.no_category = options.pop('no_category', 'No Category') self.no_category = options.pop('no_category', 'No Category')
self.paginator = options.pop('paginator', None) self.paginator = options.pop('paginator', None)
@ -1073,6 +1106,15 @@ class MinimalHelpCommand(HelpCommand):
if command.help: if command.help:
self.paginator.add_line(command.help, empty=True) self.paginator.add_line(command.help, empty=True)
def get_destination(self):
ctx = self.context
if self.dm_help is True:
return ctx.author
elif self.dm_help is None and len(self.paginator) > self.dm_help_threshold:
return ctx.author
else:
return ctx.channel
async def prepare_help_command(self, ctx, command): async def prepare_help_command(self, ctx, command):
self.paginator.clear() self.paginator.clear()

Loading…
Cancel
Save