aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/exts/utils/snekbox/_cog.py18
-rw-r--r--tests/bot/exts/utils/snekbox/test_snekbox.py15
2 files changed, 20 insertions, 13 deletions
diff --git a/bot/exts/utils/snekbox/_cog.py b/bot/exts/utils/snekbox/_cog.py
index eedac810a..0b96e78d3 100644
--- a/bot/exts/utils/snekbox/_cog.py
+++ b/bot/exts/utils/snekbox/_cog.py
@@ -393,7 +393,7 @@ class Snekbox(Cog):
output, paste_link = await self.format_output(output)
status_msg = result.get_status_message(job)
- msg = f"{ctx.author.mention} {result.status_emoji} {status_msg}.\n"
+ msg = f"{result.status_emoji} {status_msg}.\n"
# This is done to make sure the last line of output contains the error
# and the error is not manually printed by the author with a syntax error.
@@ -435,7 +435,21 @@ class Snekbox(Cog):
files = [f.to_file() for f in allowed if f not in text_files]
allowed_mentions = AllowedMentions(everyone=False, roles=False, users=[ctx.author])
view = self.build_python_version_switcher_view(job.version, ctx, job)
- response = await ctx.send(msg, allowed_mentions=allowed_mentions, view=view, files=files)
+
+ if ctx.message.channel == ctx.channel:
+ # Don't fail if the command invoking message was deleted.
+ message = ctx.message.to_reference(fail_if_not_exists=False)
+ response = await ctx.send(
+ msg,
+ allowed_mentions=allowed_mentions,
+ view=view,
+ files=files,
+ reference=message
+ )
+ else:
+ # The command was directed so a reply wont work, send a normal message with a mention.
+ msg = f"{ctx.author.mention} {msg}"
+ response = await ctx.send(msg, allowed_mentions=allowed_mentions, view=view, files=files)
view.message = response
log.info(f"{ctx.author}'s {job.name} job had a return code of {result.returncode}")
diff --git a/tests/bot/exts/utils/snekbox/test_snekbox.py b/tests/bot/exts/utils/snekbox/test_snekbox.py
index d057b284d..08925afaa 100644
--- a/tests/bot/exts/utils/snekbox/test_snekbox.py
+++ b/tests/bot/exts/utils/snekbox/test_snekbox.py
@@ -292,7 +292,6 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
async def test_send_job(self):
"""Test the send_job function."""
ctx = MockContext()
- ctx.message = MockMessage()
ctx.send = AsyncMock()
ctx.author = MockUser(mention="@LemonLemonishBeard#0042")
@@ -311,7 +310,7 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
ctx.send.assert_called_once()
self.assertEqual(
ctx.send.call_args.args[0],
- "@LemonLemonishBeard#0042 :warning: Your 3.12 eval job has completed "
+ ":warning: Your 3.12 eval job has completed "
"with return code 0.\n\n```\n[No output]\n```"
)
allowed_mentions = ctx.send.call_args.kwargs["allowed_mentions"]
@@ -325,9 +324,7 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
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.author.mention = "@LemonLemonishBeard#0042"
eval_result = EvalResult("Way too long beard", 0)
self.cog.post_job = AsyncMock(return_value=eval_result)
@@ -343,7 +340,7 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
ctx.send.assert_called_once()
self.assertEqual(
ctx.send.call_args.args[0],
- "@LemonLemonishBeard#0042 :white_check_mark: Your 3.12 eval job "
+ ":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"
)
@@ -354,9 +351,7 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
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.author.mention = "@LemonLemonishBeard#0042"
eval_result = EvalResult("ERROR", 127)
self.cog.post_job = AsyncMock(return_value=eval_result)
@@ -372,7 +367,7 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
ctx.send.assert_called_once()
self.assertEqual(
ctx.send.call_args.args[0],
- "@LemonLemonishBeard#0042 :x: Your 3.12 eval job has completed with return code 127."
+ ":x: Your 3.12 eval job has completed with return code 127."
"\n\n```\nERROR\n```"
)
@@ -382,9 +377,7 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
async def test_send_job_with_disallowed_file_ext(self):
"""Test send_job with disallowed file extensions."""
ctx = MockContext()
- ctx.message = MockMessage()
ctx.send = AsyncMock()
- ctx.author.mention = "@user#7700"
files = [
FileAttachment("test.disallowed2", b"test"),
@@ -407,7 +400,7 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
ctx.send.assert_called_once()
res = ctx.send.call_args.args[0]
self.assertTrue(
- res.startswith("@user#7700 :white_check_mark: Your 3.12 eval job has completed with return code 0.")
+ res.startswith(":white_check_mark: Your 3.12 eval job has completed with return code 0.")
)
self.assertIn("Files with disallowed extensions can't be uploaded: **.disallowed, .disallowed2, ...**", res)