[Utils] General escape function

Allows to escape formatting and mass mentions
This commit is contained in:
Twentysix 2016-09-23 09:41:29 +02:00
parent 5c13dab8e5
commit 9c2246b9b2

View File

@ -58,12 +58,16 @@ def strikethrough(text):
def underline(text): def underline(text):
return "__{}__".format(text) return "__{}__".format(text)
def escape(text, *, mass_mentions=False, formatting=False):
if mass_mentions:
text = text.replace("@everyone", "@\u200beveryone")
text = text.replace("@here", "@\u200bhere")
if formatting:
text = (text.replace("`", "\\`")
.replace("*", "\\*")
.replace("_", "\\_")
.replace("~", "\\~"))
return text
def escape_mass_mentions(text): def escape_mass_mentions(text):
words = { return escape(text, mass_mentions=True)
"@everyone": "@\u200beveryone",
"@here": "@\u200bhere"
}
for k, v in words.items():
text = text.replace(k, v)
return text