aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/cogs/moderation/incidents.py24
-rw-r--r--tests/bot/cogs/moderation/test_incidents.py32
2 files changed, 19 insertions, 37 deletions
diff --git a/bot/cogs/moderation/incidents.py b/bot/cogs/moderation/incidents.py
index ca591fc6e..3a1a3d84e 100644
--- a/bot/cogs/moderation/incidents.py
+++ b/bot/cogs/moderation/incidents.py
@@ -180,38 +180,30 @@ class Incidents(Cog):
async def archive(self, incident: discord.Message, outcome: Signal, actioned_by: discord.Member) -> bool:
"""
- Relay `incident` to the #incidents-archive channel.
+ Relay an embed representation of `incident` to the #incidents-archive channel.
The following pieces of information are relayed:
- * Incident message content (clean, pingless)
+ * Incident message content (as embed description)
* Incident author name (as webhook author)
* Incident author avatar (as webhook avatar)
- * Resolution signal (`outcome`)
+ * Resolution signal `outcome` (as embed colour & footer)
+ * Moderator `actioned_by` (name & discriminator shown in footer)
Return True if the relay finishes successfully. If anything goes wrong, meaning
not all information was relayed, return False. This signals that the original
message is not safe to be deleted, as we will lose some information.
"""
- log.debug(f"Archiving incident: {incident.id} with outcome: {outcome}")
+ log.debug(f"Archiving incident: {incident.id} (outcome: {outcome}, actioned by: {actioned_by})")
try:
- # First we try to grab the webhook
- webhook: discord.Webhook = await self.bot.fetch_webhook(Webhooks.incidents_archive)
-
- # Now relay the incident
- message: discord.Message = await webhook.send(
- content=incident.clean_content, # Clean content will prevent mentions from pinging
+ webhook = await self.bot.fetch_webhook(Webhooks.incidents_archive)
+ await webhook.send(
+ embed=make_embed(incident, outcome, actioned_by),
username=sub_clyde(incident.author.name),
avatar_url=incident.author.avatar_url,
- wait=True, # This makes the method return the sent Message object
)
-
- # Finally add the `outcome` emoji
- await message.add_reaction(outcome.value)
-
except Exception:
log.exception(f"Failed to archive incident {incident.id} to #incidents-archive")
return False
-
else:
log.trace("Message archived successfully!")
return True
diff --git a/tests/bot/cogs/moderation/test_incidents.py b/tests/bot/cogs/moderation/test_incidents.py
index 4731a786d..70dfe6b5f 100644
--- a/tests/bot/cogs/moderation/test_incidents.py
+++ b/tests/bot/cogs/moderation/test_incidents.py
@@ -312,39 +312,29 @@ class TestArchive(TestIncidents):
"""
If webhook is found, method relays `incident` properly.
- This test will assert the following:
- * The fetched webhook's `send` method is fed the correct arguments
- * The message returned by `send` will have `outcome` reaction added
- * Finally, the `archive` method returns True
-
- Assertions are made specifically in this order.
+ This test will assert that the fetched webhook's `send` method is fed the correct arguments,
+ and that the `archive` method returns True.
"""
- webhook_message = MockMessage() # The message that will be returned by the webhook's `send` method
- webhook = MockAsyncWebhook(send=AsyncMock(return_value=webhook_message))
-
+ webhook = MockAsyncWebhook()
self.cog_instance.bot.fetch_webhook = AsyncMock(return_value=webhook) # Patch in our webhook
- # Now we'll pas our own `incident` to `archive` and capture the return value
+ # Define our own `incident` for archivation
incident = MockMessage(
- clean_content="pingless message",
- content="pingful message",
+ content="this is an incident",
author=MockUser(name="author_name", avatar_url="author_avatar"),
id=123,
)
- archive_return = await self.cog_instance.archive(incident, MagicMock(value="A"), MockMember())
+ built_embed = MagicMock(discord.Embed, id=123) # We patch `make_embed` to return this
- # Check that the webhook was dispatched correctly
+ with patch("bot.cogs.moderation.incidents.make_embed", MagicMock(return_value=built_embed)):
+ archive_return = await self.cog_instance.archive(incident, MagicMock(value="A"), MockMember())
+
+ # Now we check that the webhook was given the correct args, and that `archive` returned True
webhook.send.assert_called_once_with(
- content="pingless message",
+ embed=built_embed,
username="author_name",
avatar_url="author_avatar",
- wait=True,
)
-
- # Now check that the correct emoji was added to the relayed message
- webhook_message.add_reaction.assert_called_once_with("A")
-
- # Finally check that the method returned True
self.assertTrue(archive_return)
async def test_archive_clyde_username(self):