mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-09 23:39:50 +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.
|
Whether to clean channel mentions.
|
||||||
use_nicknames: bool
|
use_nicknames: bool
|
||||||
Whether to use nicknames when transforming mentions.
|
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.fix_channel_mentions = fix_channel_mentions
|
||||||
self.use_nicknames = use_nicknames
|
self.use_nicknames = use_nicknames
|
||||||
|
self.escape_markdown = escape_markdown
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def convert(self, ctx, argument):
|
def convert(self, ctx, argument):
|
||||||
@ -416,6 +419,18 @@ class clean_content(Converter):
|
|||||||
pattern = re.compile('|'.join(transformations.keys()))
|
pattern = re.compile('|'.join(transformations.keys()))
|
||||||
result = pattern.sub(repl, argument)
|
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 = {
|
transformations = {
|
||||||
'@everyone': '@\u200beveryone',
|
'@everyone': '@\u200beveryone',
|
||||||
'@here': '@\u200bhere'
|
'@here': '@\u200bhere'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user