aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/exts/utils/snekbox/_cog.py8
-rw-r--r--tests/bot/exts/utils/snekbox/test_snekbox.py6
2 files changed, 9 insertions, 5 deletions
diff --git a/bot/exts/utils/snekbox/_cog.py b/bot/exts/utils/snekbox/_cog.py
index f6c201598..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
@@ -400,7 +404,7 @@ class Snekbox(Cog):
# Skip output if it's empty and there are file uploads
if result.stdout or not result.has_files:
- msg += f"\n```\n{output}\n```"
+ msg += f"\n```ansi\n{output}\n```"
if paste_link:
msg += f"\nFull output: {paste_link}"
diff --git a/tests/bot/exts/utils/snekbox/test_snekbox.py b/tests/bot/exts/utils/snekbox/test_snekbox.py
index 6a2ab5c24..9cfd75df8 100644
--- a/tests/bot/exts/utils/snekbox/test_snekbox.py
+++ b/tests/bot/exts/utils/snekbox/test_snekbox.py
@@ -312,7 +312,7 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(
ctx.send.call_args.args[0],
":warning: Your 3.12 eval job has completed "
- "with return code 0.\n\n```\n[No output]\n```"
+ "with return code 0.\n\n```ansi\n[No output]\n```"
)
allowed_mentions = ctx.send.call_args.kwargs["allowed_mentions"]
expected_allowed_mentions = AllowedMentions(everyone=False, roles=False, users=[ctx.author])
@@ -343,7 +343,7 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
ctx.send.call_args.args[0],
":white_check_mark: Your 3.12 eval job "
"has completed with return code 0."
- "\n\n```\nWay too long beard\n```\nFull output: lookatmybeard.com"
+ "\n\n```ansi\nWay too long beard\n```\nFull output: lookatmybeard.com"
)
self.cog.post_job.assert_called_once_with(job)
@@ -369,7 +369,7 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(
ctx.send.call_args.args[0],
":x: Your 3.12 eval job has completed with return code 127."
- "\n\n```\nERROR\n```"
+ "\n\n```ansi\nERROR\n```"
)
self.cog.post_job.assert_called_once_with(job)