diff options
| author | Rapptz <[email protected]> | 2017-05-28 23:18:54 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-05-28 23:18:54 -0400 |
| commit | b2cf11fe9da7a7af9da7c868a9fa73a4f37a94b2 (patch) | |
| tree | 2cc6dc86ed7c6bc7daf870c0e71f8e3e00733cdc | |
| parent | Permissions.view_audit_logs -> Permissions.view_audit_log (diff) | |
| download | discord.py-b2cf11fe9da7a7af9da7c868a9fa73a4f37a94b2.tar.xz discord.py-b2cf11fe9da7a7af9da7c868a9fa73a4f37a94b2.zip | |
[commands] Add escape_markdown parameter for clean_content.
| -rw-r--r-- | discord/ext/commands/converter.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py index 62aa8e81..b109765b 100644 --- a/discord/ext/commands/converter.py +++ b/discord/ext/commands/converter.py @@ -368,10 +368,13 @@ class clean_content(Converter): Whether to clean channel mentions. use_nicknames: bool Whether to use nicknames when transforming mentions. + escape_markdown: bool + Whether to also escape special markdown characters. """ - def __init__(self, *, fix_channel_mentions=False, use_nicknames=True): + def __init__(self, *, fix_channel_mentions=False, use_nicknames=True, escape_markdown=False): self.fix_channel_mentions = fix_channel_mentions self.use_nicknames = use_nicknames + self.escape_markdown = escape_markdown @asyncio.coroutine def convert(self, ctx, argument): @@ -416,6 +419,18 @@ class clean_content(Converter): pattern = re.compile('|'.join(transformations.keys())) result = pattern.sub(repl, argument) + if self.escape_markdown: + transformations = { + re.escape(c): '\\' + c + for c in ('*', '`', '_', '~', '\\') + } + + def replace(obj): + return transformations.get(re.escape(obj.group(0)), '') + + pattern = re.compile('|'.join(transformations.keys())) + result = pattern.sub(replace, result) + transformations = { '@everyone': '@\u200beveryone', '@here': '@\u200bhere' |