From 96f15c06183d4f2ea3cf1be7e3e20352a18239c7 Mon Sep 17 00:00:00 2001 From: e1pupper Date: Tue, 14 Feb 2023 11:12:22 +0100 Subject: [PATCH 1/5] reply to user when using !eval/!timeit command instead of pinging --- bot/exts/utils/snekbox.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/utils/snekbox.py b/bot/exts/utils/snekbox.py index 8a2e68b282..c49f041acd 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']}") From 1ce2ef3dc580e0b17e0d76189f1028cb9e7b5fdf Mon Sep 17 00:00:00 2001 From: e1pupper Date: Tue, 14 Feb 2023 13:58:49 +0100 Subject: [PATCH 2/5] Fixed reply when spamming, and test_snekbox --- bot/exts/utils/snekbox.py | 4 ++-- tests/bot/exts/utils/test_snekbox.py | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bot/exts/utils/snekbox.py b/bot/exts/utils/snekbox.py index c49f041acd..4233b1dcba 100644 --- a/bot/exts/utils/snekbox.py +++ b/bot/exts/utils/snekbox.py @@ -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( + f"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..982bb83f26 100644 --- a/tests/bot/exts/utils/test_snekbox.py +++ b/tests/bot/exts/utils/test_snekbox.py @@ -220,7 +220,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 +234,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 +252,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 +266,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 +284,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 +297,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) From 6a11a859cc4b16181954024fb51bc8a4d21ea1e7 Mon Sep 17 00:00:00 2001 From: e1pupper Date: Tue, 14 Feb 2023 14:04:32 +0100 Subject: [PATCH 3/5] changed lint-test --- tests/bot/exts/utils/test_snekbox.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/bot/exts/utils/test_snekbox.py b/tests/bot/exts/utils/test_snekbox.py index 982bb83f26..5925bca230 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) From 213e87c9b0b2101cb83c7d3654f6df11d49f99b5 Mon Sep 17 00:00:00 2001 From: e1pupper Date: Tue, 14 Feb 2023 14:06:49 +0100 Subject: [PATCH 4/5] f string removed --- bot/exts/utils/snekbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/utils/snekbox.py b/bot/exts/utils/snekbox.py index 4233b1dcba..7ec617ef4a 100644 --- a/bot/exts/utils/snekbox.py +++ b/bot/exts/utils/snekbox.py @@ -472,7 +472,7 @@ async def run_job( response = await self.send_job(ctx, python_version, code, args=args, job_name=job_name) except LockedResourceError: await ctx.reply( - f"You've already got a job running - " + "You've already got a job running - " "please wait for it to finish!" ) return From c95e70f602a049d7a0d5f2a83f58e615a830d5b6 Mon Sep 17 00:00:00 2001 From: e1pupper Date: Fri, 17 Feb 2023 22:07:35 +0100 Subject: [PATCH 5/5] trailing white-space :nerd: --- tests/bot/exts/utils/test_snekbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bot/exts/utils/test_snekbox.py b/tests/bot/exts/utils/test_snekbox.py index 5925bca230..ed4400d937 100644 --- a/tests/bot/exts/utils/test_snekbox.py +++ b/tests/bot/exts/utils/test_snekbox.py @@ -167,7 +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)