From 483ef36d1b3b1a7654239b767550d2cfd31b5d54 Mon Sep 17 00:00:00 2001 From: Predeactor <61093863+Predeactor@users.noreply.github.com> Date: Wed, 27 Oct 2021 14:34:20 +0200 Subject: [PATCH] Modernize syntax in chat formatting module and add `success()` (#5427) * Downloader's plurial & Fix * Don't forget pipinstall * Fix syntax issue * This f****** fix that took me too much of my time for nothing. * Black * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Fix Jack's syntax, remove numbers & fix bad calculated cogs * Black ofc * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/downloader/downloader.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Address my review comment * Simplify * this is kinda a lot but shh * Change format to f-string * Add success function to char_formatting * Revert "Merge branch 'V3/develop' of github.com:Predeactor/Red-DiscordBot into master/chat-formatting-enhancement" This reverts commit c338da7b66a79eaff975f4dbaa8269263a388e37, reversing changes made to f2422ad782258990a56438db8abad61180cea681. * For once I would have appreciated if style checks were failing... Co-authored-by: Predeactor Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- redbot/core/utils/chat_formatting.py | 47 +++++++++++++++++----------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/redbot/core/utils/chat_formatting.py b/redbot/core/utils/chat_formatting.py index 3e8ef048d..8a97c42f4 100644 --- a/redbot/core/utils/chat_formatting.py +++ b/redbot/core/utils/chat_formatting.py @@ -27,7 +27,7 @@ def error(text: str) -> str: The new message. """ - return "\N{NO ENTRY SIGN} {}".format(text) + return f"\N{NO ENTRY SIGN} {text}" def warning(text: str) -> str: @@ -44,7 +44,7 @@ def warning(text: str) -> str: The new message. """ - return "\N{WARNING SIGN}\N{VARIATION SELECTOR-16} {}".format(text) + return f"\N{WARNING SIGN}\N{VARIATION SELECTOR-16} {text}" def info(text: str) -> str: @@ -61,7 +61,24 @@ def info(text: str) -> str: The new message. """ - return "\N{INFORMATION SOURCE}\N{VARIATION SELECTOR-16} {}".format(text) + return f"\N{INFORMATION SOURCE}\N{VARIATION SELECTOR-16} {text}" + + +def success(text: str) -> str: + """Get text prefixed with a success emoji. + + Parameters + ---------- + text : str + The text to be prefixed. + + Returns + ------- + str + The new message. + + """ + return f"\N{WHITE HEAVY CHECK MARK} {text}" def question(text: str) -> str: @@ -78,7 +95,7 @@ def question(text: str) -> str: The new message. """ - return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16} {}".format(text) + return f"\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16} {text}" def bold(text: str, escape_formatting: bool = True) -> str: @@ -99,8 +116,7 @@ def bold(text: str, escape_formatting: bool = True) -> str: The marked up text. """ - text = escape(text, formatting=escape_formatting) - return "**{}**".format(text) + return f"**{escape(text, formatting=escape_formatting)}**" def box(text: str, lang: str = "") -> str: @@ -119,8 +135,7 @@ def box(text: str, lang: str = "") -> str: The marked up text. """ - ret = "```{}\n{}\n```".format(lang, text) - return ret + return f"```{lang}\n{text}\n```" def inline(text: str) -> str: @@ -138,9 +153,9 @@ def inline(text: str) -> str: """ if "`" in text: - return "``{}``".format(text) + return f"``{text}``" else: - return "`{}`".format(text) + return f"`{text}`" def italics(text: str, escape_formatting: bool = True) -> str: @@ -161,8 +176,7 @@ def italics(text: str, escape_formatting: bool = True) -> str: The marked up text. """ - text = escape(text, formatting=escape_formatting) - return "*{}*".format(text) + return f"*{escape(text, formatting=escape_formatting)}*" def spoiler(text: str, escape_formatting: bool = True) -> str: @@ -183,8 +197,7 @@ def spoiler(text: str, escape_formatting: bool = True) -> str: The marked up text. """ - text = escape(text, formatting=escape_formatting) - return "||{}||".format(text) + return f"||{escape(text, formatting=escape_formatting)}||" def bordered(*columns: Sequence[str], ascii_border: bool = False) -> str: @@ -343,8 +356,7 @@ def strikethrough(text: str, escape_formatting: bool = True) -> str: The marked up text. """ - text = escape(text, formatting=escape_formatting) - return "~~{}~~".format(text) + return f"~~{escape(text, formatting=escape_formatting)}~~" def underline(text: str, escape_formatting: bool = True) -> str: @@ -365,8 +377,7 @@ def underline(text: str, escape_formatting: bool = True) -> str: The marked up text. """ - text = escape(text, formatting=escape_formatting) - return "__{}__".format(text) + return f"__{escape(text, formatting=escape_formatting)}__" def quote(text: str) -> str: