aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Shivansh <[email protected]>2021-05-12 09:55:19 +0530
committerGravatar Shivansh-007 <[email protected]>2021-10-11 12:05:44 +0530
commitecfcc902fc619c2f07c449b40c4373a61b5abaf7 (patch)
treef29a6c1a0418486605140fed7f8f064625750bdf
parentDelete msg link embed if no link on edit (diff)
Use `on_raw_message_edit`
Originally it was using `on_message_edit` which would have failed if the message was not in the bot' cache. Therefore we would have to use a raw listener.
-rw-r--r--bot/exts/moderation/incidents.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/bot/exts/moderation/incidents.py b/bot/exts/moderation/incidents.py
index 7aad1df35..0da4acaa2 100644
--- a/bot/exts/moderation/incidents.py
+++ b/bot/exts/moderation/incidents.py
@@ -520,9 +520,12 @@ class Incidents(Cog):
await self.send_message_link_embeds(webhook_embed_list, message, self.incidents_webhook)
@Cog.listener()
- async def on_message_edit(self, msg_before: discord.Message, msg_after: discord.Message) -> None:
+ async def on_raw_message_edit(self, payload: discord.RawMessageUpdateEvent) -> None:
"""
- Pass `msg_after` to `extract_message_links` and edit `msg_before` webhook msg.
+ Pass processed `payload` to `extract_message_links` and edit `msg_before` webhook msg.
+
+ Fetch the message found in payload, if not found i.e. the message got deleted then delete its
+ webhook message and return.
Deletes cache value (`message_link_embeds_cache`) of `msg_before` if it exists and removes the
webhook message for that particular link from the channel.
@@ -533,9 +536,15 @@ class Incidents(Cog):
The edited message is also passed into `add_signals` if it is a incident message.
"""
+ try:
+ channel = self.bot.get_channel(int(payload.data["channel_id"]))
+ msg_after = await channel.fetch_message(payload.message_id)
+ except discord.NotFound: # Was deleted before we got the event
+ return
+
if is_incident(msg_after):
webhook_embed_list = await self.extract_message_links(msg_after)
- webhook_msg_id = await self.message_link_embeds_cache.get(msg_before.id)
+ webhook_msg_id = await self.message_link_embeds_cache.get(payload.message_id)
if not webhook_embed_list:
await self.delete_msg_link_embed(msg_after)