Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bot/exts/utils/snekbox/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -400,7 +404,7 @@ async def send_job(self, ctx: Context, job: EvalJob) -> Message:

# 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}"
Expand Down
6 changes: 3 additions & 3 deletions tests/bot/exts/utils/snekbox/test_snekbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ async def test_send_job(self):
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])
Expand Down Expand Up @@ -343,7 +343,7 @@ async def test_send_job_with_paste_link(self):
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)
Expand All @@ -369,7 +369,7 @@ async def test_send_job_with_non_zero_eval(self):
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)
Expand Down