mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 11:48:55 -05:00
[Utils] General escape function
Allows to escape formatting and mass mentions
This commit is contained in:
parent
5c13dab8e5
commit
9c2246b9b2
@ -58,12 +58,16 @@ def strikethrough(text):
|
||||
def underline(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):
|
||||
words = {
|
||||
"@everyone": "@\u200beveryone",
|
||||
"@here": "@\u200bhere"
|
||||
}
|
||||
for k, v in words.items():
|
||||
text = text.replace(k, v)
|
||||
return text
|
||||
return escape(text, mass_mentions=True)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user