From bde266bbb99742ca0718edb97dc602da6575d0b4 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 10 Jun 2016 21:31:11 -0400 Subject: [PATCH] [commands] Fix @everyone elevation in the default help command. --- discord/ext/commands/bot.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 271bc966d..82a5653db 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -30,6 +30,7 @@ import inspect import importlib import sys import traceback +import re from .core import GroupMixin, Command, command from .view import StringView @@ -80,18 +81,28 @@ def when_mentioned_or(*prefixes): return inner +_mentions_transforms = { + '@everyone': '@\u200beveryone', + '@here': '@\u200bhere' +} + +_mention_pattern = re.compile('|'.join(_mentions_transforms.keys())) + @asyncio.coroutine 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 = commands[0] + name = _mention_pattern.sub(repl, commands[0]) command = None if name in bot.cogs: command = bot.cogs[name] @@ -103,7 +114,7 @@ def _default_help_command(ctx, *commands : str): pages = bot.formatter.format_help_for(ctx, command) else: - name = commands[0] + name = _mention_pattern.sub(repl, commands[0]) command = bot.commands.get(name) if command is None: yield from bot.send_message(destination, bot.command_not_found.format(name)) @@ -111,6 +122,7 @@ def _default_help_command(ctx, *commands : str): for key in commands[1:]: try: + key = _mention_pattern.sub(repl, key) command = command.commands.get(key) if command is None: yield from bot.send_message(destination, bot.command_not_found.format(key))