aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Thurisatic <[email protected]>2024-11-14 15:11:23 -0500
committerGravatar Thurisatic <[email protected]>2024-11-14 15:11:23 -0500
commit15235ea60bec4f9f3e7c6f2111d82fff4309fe8e (patch)
tree989e2793776d78d3e9bea02b3fead534bc736a93
parentAdd eval output highlight language to support ANSI colors (diff)
Prevent 3.13's ANSI escapes from mangling pinwand uploads
-rw-r--r--bot/exts/utils/snekbox/_cog.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/bot/exts/utils/snekbox/_cog.py b/bot/exts/utils/snekbox/_cog.py
index 63f45dd23..d448898f3 100644
--- a/bot/exts/utils/snekbox/_cog.py
+++ b/bot/exts/utils/snekbox/_cog.py
@@ -29,6 +29,7 @@ if TYPE_CHECKING:
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 @@ class Snekbox(Cog):
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