From 15235ea60bec4f9f3e7c6f2111d82fff4309fe8e Mon Sep 17 00:00:00 2001 From: Thurisatic <99002593+thurisatic@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:11:23 -0500 Subject: [PATCH] Prevent 3.13's ANSI escapes from mangling pinwand uploads --- bot/exts/utils/snekbox/_cog.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bot/exts/utils/snekbox/_cog.py b/bot/exts/utils/snekbox/_cog.py index 63f45dd23e..d448898f3c 100644 --- a/bot/exts/utils/snekbox/_cog.py +++ b/bot/exts/utils/snekbox/_cog.py @@ -29,6 +29,7 @@ log = get_logger(__name__) +ANSI_REGEX = re.compile(r"\N{ESC}\[[0-9;:]*m") ESCAPE_REGEX = re.compile("[`\u202E\u200B]{3,}") # The timeit command should only output the very last line, so all other output should be suppressed. @@ -281,7 +282,10 @@ async def format_output( output = f"{output[:max_chars]}\n... (truncated - too long)" if truncated: - paste_link = await self.upload_output(original_output) + # ANSI colors are quite nice, but don't render in pinwand, + # thus mangling the output + ansiless_output = ANSI_REGEX.sub("", original_output) + paste_link = await self.upload_output(ansiless_output) if output_default and not output: output = output_default