aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-08-12 12:11:47 -0700
committerGravatar MarkKoz <[email protected]>2020-08-12 12:40:17 -0700
commit257048446a1e37c1bbdad424f8a8465f0491ca83 (patch)
tree49cf8975dec3b07c37c3442ec959128be94a92d6
parentMerge pull request #1097 from Numerlor/remove-api-endpoints (diff)
Filtering: ignore errors for duplicate offensive messages
The error happens when a filter is triggered by a message edit. Fixes #1099 Fixes BOT-6B
-rw-r--r--bot/cogs/filtering.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py
index 93cc1c655..99b659bff 100644
--- a/bot/cogs/filtering.py
+++ b/bot/cogs/filtering.py
@@ -11,6 +11,7 @@ from discord import Colour, HTTPException, Member, Message, NotFound, TextChanne
from discord.ext.commands import Cog
from discord.utils import escape_markdown
+from bot.api import ResponseCodeError
from bot.bot import Bot
from bot.cogs.moderation import ModLog
from bot.constants import (
@@ -301,9 +302,16 @@ class Filtering(Cog):
'delete_date': delete_date
}
- await self.bot.api_client.post('bot/offensive-messages', json=data)
- self.schedule_msg_delete(data)
- log.trace(f"Offensive message {msg.id} will be deleted on {delete_date}")
+ try:
+ await self.bot.api_client.post('bot/offensive-messages', json=data)
+ except ResponseCodeError as e:
+ if e.status == 400 and "already exists" in e.response_json.get("id", [""])[0]:
+ log.debug(f"Offensive message {msg.id} already exists.")
+ else:
+ log.error(f"Offensive message {msg.id} failed to post: {e}")
+ else:
+ self.schedule_msg_delete(data)
+ log.trace(f"Offensive message {msg.id} will be deleted on {delete_date}")
if is_private:
channel_str = "via DM"