diff --git a/bot/exts/utils/snekbox.py b/bot/exts/utils/snekbox.py index 8a2e68b282..7ec617ef4a 100644 --- a/bot/exts/utils/snekbox.py +++ b/bot/exts/utils/snekbox.py @@ -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}" @@ -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']}") @@ -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 diff --git a/tests/bot/exts/utils/test_snekbox.py b/tests/bot/exts/utils/test_snekbox.py index b1f32c2105..ed4400d937 100644 --- a/tests/bot/exts/utils/test_snekbox.py +++ b/tests/bot/exts/utils/test_snekbox.py @@ -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) @@ -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}) @@ -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()) @@ -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}) @@ -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' ) @@ -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')) @@ -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)