mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-08 10:22:31 -05:00
[Utils] General escape function
Allows to escape formatting and mass mentions
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user