From abbe79919b14e09f41c98d4bc295b03ed36f5317 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sat, 23 Jan 2016 03:15:12 -0500 Subject: [PATCH] [commands] Change Bot.pm_help to be an optional bool. The behaviour of passing in pm_help=None makes it so the bot will only send private messages if the length of the message is too "big", which is defined as having more than 1000 characters in the output. --- discord/ext/commands/bot.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 8605f83fe..d1df7fc2c 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -56,7 +56,7 @@ def when_mentioned(bot, msg): def _default_help_command(ctx, *commands : str): """Shows this message.""" bot = ctx.bot - destination = ctx.message.channel if not bot.pm_help else ctx.message.author + destination = ctx.message.author if bot.pm_help else ctx.message.channel # help by itself just lists our own commands. if len(commands) == 0: @@ -93,6 +93,12 @@ def _default_help_command(ctx, *commands : str): pages = bot.formatter.format_help_for(ctx, command) + if bot.pm_help is None: + characters = sum(map(lambda l: len(l), pages)) + # modify destination based on length of pages. + if characters > 1000: + destination = ctx.message.author + for page in pages: yield from bot.send_message(destination, page) @@ -129,9 +135,13 @@ class Bot(GroupMixin, discord.Client): If you want to change the help command completely (add aliases, etc) then a call to :meth:`remove_command` with 'help' as the argument would do the trick. - pm_help : bool - A boolean that indicates if the help command should PM the user instead of - sending it to the channel it received it from. Defaults to ``False``. + pm_help : Optional[bool] + A tribool that indicates if the help command should PM 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 PM'd. If ``False``, none of the help + 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``. """ def __init__(self, command_prefix, formatter=None, description=None, pm_help=False, **options): super().__init__(**options)