aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar kwzrd <[email protected]>2020-06-12 17:17:36 +0200
committerGravatar kwzrd <[email protected]>2020-06-12 17:37:57 +0200
commitd7165bf5547340242cb99460a35cabd753d60c42 (patch)
tree309df21f683b28278ed722d56aeeb04fa6ba4caf
parentIncidents: implement reaction listener (diff)
Incidents: implement `archive` method
-rw-r--r--bot/cogs/moderation/incidents.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/bot/cogs/moderation/incidents.py b/bot/cogs/moderation/incidents.py
index 88ed04f45..8781d6749 100644
--- a/bot/cogs/moderation/incidents.py
+++ b/bot/cogs/moderation/incidents.py
@@ -7,7 +7,7 @@ import discord
from discord.ext.commands import Cog
from bot.bot import Bot
-from bot.constants import Channels, Emojis, Roles
+from bot.constants import Channels, Emojis, Roles, Webhooks
log = logging.getLogger(__name__)
@@ -107,6 +107,44 @@ class Incidents(Cog):
log.debug("Crawl task finished!")
+ async def archive(self, incident: discord.Message, outcome: Signal) -> bool:
+ """
+ Relay `incident` to the #incidents-archive channel.
+
+ The following pieces of information are relayed:
+ * Incident message content (clean, pingless)
+ * Incident author name (as webhook author)
+ * Incident author avatar (as webhook avatar)
+ * Resolution signal (`outcome`)
+
+ 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}")
+ 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
+ username=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 as exc:
+ log.exception("Failed to archive incident to #incidents-archive", exc_info=exc)
+ return False
+
+ else:
+ log.debug("Message archived successfully!")
+ return True
+
async def resolve_message(self, message_id: int) -> t.Optional[discord.Message]:
"""
Get `discord.Message` for `message_id` from cache, or API.