From 1fa02b28b1613cde5d907523b4b13edea41f4e28 Mon Sep 17 00:00:00 2001 From: Ben Cos <52817096+BenCos17@users.noreply.github.com> Date: Sun, 1 Sep 2024 23:52:57 +0100 Subject: [PATCH] pull to main branch (#20) * [Trivia] Correct Stephen to Steven (#6434) Co-authored-by: Artemis6969 <82315185+Artemis6969@users.noreply.github.com> * Generate default LL server config and attach it to GH release (#6430) * [Audio] Update Lavalink.jar and yt source build numbers (#6435) Co-authored-by: Jakub Kuczys * [Audio] Fix trying to send notify message with no channel object (#6429) * Bump dependencies (#6436) * Red 3.5.13 - Changelog (#6437) * Automated Crowdin downstream (#6439) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Version bump to 3.5.13 (#6438) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Fix publish release workflow * Add missing perm to Publish Release workflow * Change Red 3.5.13 release date * Version bump to 3.5.14.dev1 * [Trivia] Correct typos in World Cup trivia list for Golden Glove questions (#6441) * Split out non-Python assets in Publish Release workflow (#6440) * Add `header`, `hyperlink` and `subtext` utilities (#6102) (#19) Co-authored-by: Kreusada <67752638+Kreusada@users.noreply.github.com> Co-authored-by: Kowlin <10947836+Kowlin@users.noreply.github.com> --------- Co-authored-by: Guyonsteroids <82315185+Guyonsteroids@users.noreply.github.com> Co-authored-by: Artemis6969 <82315185+Artemis6969@users.noreply.github.com> Co-authored-by: Jakub Kuczys Co-authored-by: aikaterna <20862007+aikaterna@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Mellow <89431994+mellow-org@users.noreply.github.com> Co-authored-by: Kreusada <67752638+Kreusada@users.noreply.github.com> Co-authored-by: Kowlin <10947836+Kowlin@users.noreply.github.com> --- redbot/core/utils/chat_formatting.py | 68 +++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/redbot/core/utils/chat_formatting.py b/redbot/core/utils/chat_formatting.py index b13d869dc02..a65417b298c 100644 --- a/redbot/core/utils/chat_formatting.py +++ b/redbot/core/utils/chat_formatting.py @@ -5,7 +5,7 @@ import math import textwrap from io import BytesIO -from typing import Iterator, List, Optional, Sequence, SupportsInt, Union +from typing import Iterator, List, Literal, Optional, Sequence, SupportsInt, Union import discord from babel.lists import format_list as babel_list @@ -21,11 +21,14 @@ "question", "bold", "box", + "header", + "hyperlink", "inline", "italics", "spoiler", "pagify", "strikethrough", + "subtext", "underline", "quote", "escape", @@ -39,6 +42,69 @@ _ = Translator("UtilsChatFormatting", __file__) +def hyperlink(text: str, url: str) -> str: + """Create hyperlink markdown with text and a URL. + + Parameters + ---------- + text : str + The text which will contain the link. + url : str + The URL used for the hyperlink. + + Returns + ------- + str + The new message. + + """ + return f"[{text}]({url})" + + +def header(text: str, size: Literal["small", "medium", "large"]) -> str: + """Formats a header. + + Parameters + ---------- + text : str + The text for the header. + url : Literal['small', 'medium', 'large'] + The size of the header ('small', 'medium' or 'large') + + Returns + ------- + str + The new message. + + """ + if size == "small": + multiplier = 3 + elif size == "medium": + multiplier = 2 + elif size == "large": + multiplier = 1 + else: + raise ValueError(f"Invalid size '{size}'") + return "#" * multiplier + " " + text + + +def subtext(text: str) -> str: + """Formats subtext from the given text. + + Parameters + ---------- + text : str + The text to format as subtext. + + Returns + ------- + str + The new message. + + """ + return "-# " + text + + def error(text: str) -> str: """Get text prefixed with an error emoji.