mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-09 15:29:57 +00:00
[commands] Add escape_markdown parameter for clean_content.
This commit is contained in:
parent
34815a43f4
commit
b2cf11fe9d
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user