mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-06 01:12:33 -05:00
First commit
This commit is contained in:
76
core/utils/chat_formatting.py
Normal file
76
core/utils/chat_formatting.py
Normal file
@@ -0,0 +1,76 @@
|
||||
def error(text):
|
||||
return "\N{NO ENTRY SIGN} {}".format(text)
|
||||
|
||||
|
||||
def warning(text):
|
||||
return "\N{WARNING SIGN} {}".format(text)
|
||||
|
||||
|
||||
def info(text):
|
||||
return "\N{INFORMATION SOURCE} {}".format(text)
|
||||
|
||||
|
||||
def question(text):
|
||||
return "\N{BLACK QUESTION MARK ORNAMENT} {}".format(text)
|
||||
|
||||
|
||||
def bold(text):
|
||||
return "**{}**".format(text)
|
||||
|
||||
|
||||
def box(text, lang=""):
|
||||
ret = "```{}\n{}\n```".format(lang, text)
|
||||
return ret
|
||||
|
||||
|
||||
def inline(text):
|
||||
return "`{}`".format(text)
|
||||
|
||||
|
||||
def italics(text):
|
||||
return "*{}*".format(text)
|
||||
|
||||
|
||||
def pagify(text, delims=["\n"], *, escape=True, shorten_by=8,
|
||||
page_length=2000):
|
||||
"""DOES NOT RESPECT MARKDOWN BOXES OR INLINE CODE"""
|
||||
in_text = text
|
||||
if escape:
|
||||
num_mentions = text.count("@here") + text.count("@everyone")
|
||||
shorten_by += num_mentions
|
||||
page_length -= shorten_by
|
||||
while len(in_text) > page_length:
|
||||
closest_delim = max([in_text.rfind(d, 0, page_length)
|
||||
for d in delims])
|
||||
closest_delim = closest_delim if closest_delim != -1 else page_length
|
||||
if escape:
|
||||
to_send = escape_mass_mentions(in_text[:closest_delim])
|
||||
else:
|
||||
to_send = in_text[:closest_delim]
|
||||
yield to_send
|
||||
in_text = in_text[closest_delim:]
|
||||
|
||||
if escape:
|
||||
yield escape_mass_mentions(in_text)
|
||||
else:
|
||||
yield in_text
|
||||
|
||||
|
||||
def strikethrough(text):
|
||||
return "~~{}~~".format(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
|
||||
Reference in New Issue
Block a user