Skip to content
Closed
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: 4 additions & 4 deletions bot/exts/utils/snekbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ async def send_job(
output, paste_link = await self.format_output(results["stdout"])

icon = self.get_status_emoji(results)
msg = f"{ctx.author.mention} {icon} {msg}.\n\n```\n{output}\n```"
msg = f"{icon} {msg}.\n\n```\n{output}\n```"
if paste_link:
msg = f"{msg}\nFull output: {paste_link}"

Expand All @@ -364,7 +364,7 @@ async def send_job(
else:
allowed_mentions = AllowedMentions(everyone=False, roles=False, users=[ctx.author])
view = self.build_python_version_switcher_view(job_name, python_version, ctx, code, args)
response = await ctx.send(msg, allowed_mentions=allowed_mentions, view=view)
response = await ctx.reply(msg, allowed_mentions=allowed_mentions, view=view)
view.message = response

log.info(f"{ctx.author}'s {job_name} job had a return code of {results['returncode']}")
Expand Down Expand Up @@ -471,8 +471,8 @@ async def run_job(
try:
response = await self.send_job(ctx, python_version, code, args=args, job_name=job_name)
except LockedResourceError:
await ctx.send(
f"{ctx.author.mention} You've already got a job running - "
await ctx.reply(
"You've already got a job running - "
"please wait for it to finish!"
)
return
Expand Down
27 changes: 14 additions & 13 deletions tests/bot/exts/utils/test_snekbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ async def test_format_output(self):
'15 lines, 1965 characters output'
),
)

for case, expected, testname in cases:
with self.subTest(msg=testname, case=case, expected=expected):
self.assertEqual(await self.cog.format_output(case), expected)
Expand Down Expand Up @@ -220,7 +221,7 @@ async def test_send_job(self):
"""Test the send_job function."""
ctx = MockContext()
ctx.message = MockMessage()
ctx.send = AsyncMock()
ctx.reply = AsyncMock()
ctx.author = MockUser(mention='@LemonLemonishBeard#0042')

self.cog.post_job = AsyncMock(return_value={'stdout': '', 'returncode': 0})
Expand All @@ -234,12 +235,12 @@ async def test_send_job(self):

await self.cog.send_job(ctx, '3.11', 'MyAwesomeCode', job_name='eval')

ctx.send.assert_called_once()
ctx.reply.assert_called_once()
self.assertEqual(
ctx.send.call_args.args[0],
'@LemonLemonishBeard#0042 :yay!: Return code 0.\n\n```\n[No output]\n```'
ctx.reply.call_args.args[0],
':yay!: Return code 0.\n\n```\n[No output]\n```'
)
allowed_mentions = ctx.send.call_args.kwargs['allowed_mentions']
allowed_mentions = ctx.reply.call_args.kwargs['allowed_mentions']
expected_allowed_mentions = AllowedMentions(everyone=False, roles=False, users=[ctx.author])
self.assertEqual(allowed_mentions.to_dict(), expected_allowed_mentions.to_dict())

Expand All @@ -252,7 +253,7 @@ async def test_send_job_with_paste_link(self):
"""Test the send_job function with a too long output that generate a paste link."""
ctx = MockContext()
ctx.message = MockMessage()
ctx.send = AsyncMock()
ctx.reply = AsyncMock()
ctx.author.mention = '@LemonLemonishBeard#0042'

self.cog.post_job = AsyncMock(return_value={'stdout': 'Way too long beard', 'returncode': 0})
Expand All @@ -266,10 +267,10 @@ async def test_send_job_with_paste_link(self):

await self.cog.send_job(ctx, '3.11', 'MyAwesomeCode', job_name='eval')

ctx.send.assert_called_once()
ctx.reply.assert_called_once()
self.assertEqual(
ctx.send.call_args.args[0],
'@LemonLemonishBeard#0042 :yay!: Return code 0.'
ctx.reply.call_args.args[0],
':yay!: Return code 0.'
'\n\n```\nWay too long beard\n```\nFull output: lookatmybeard.com'
)

Expand All @@ -284,7 +285,7 @@ async def test_send_job_with_non_zero_eval(self):
"""Test the send_job function with a code returning a non-zero code."""
ctx = MockContext()
ctx.message = MockMessage()
ctx.send = AsyncMock()
ctx.reply = AsyncMock()
ctx.author.mention = '@LemonLemonishBeard#0042'
self.cog.post_job = AsyncMock(return_value={'stdout': 'ERROR', 'returncode': 127})
self.cog.get_results_message = MagicMock(return_value=('Return code 127', 'Beard got stuck in the eval'))
Expand All @@ -297,10 +298,10 @@ async def test_send_job_with_non_zero_eval(self):

await self.cog.send_job(ctx, '3.11', 'MyAwesomeCode', job_name='eval')

ctx.send.assert_called_once()
ctx.reply.assert_called_once()
self.assertEqual(
ctx.send.call_args.args[0],
'@LemonLemonishBeard#0042 :nope!: Return code 127.\n\n```\nBeard got stuck in the eval\n```'
ctx.reply.call_args.args[0],
':nope!: Return code 127.\n\n```\nBeard got stuck in the eval\n```'
)

self.cog.post_job.assert_called_once_with('MyAwesomeCode', '3.11', args=None)
Expand Down