From 55347d62a220d11611d57f593adb66d296db1f99 Mon Sep 17 00:00:00 2001 From: Frisk Date: Sat, 31 Aug 2024 22:27:06 +0200 Subject: [PATCH] Attempt to fix issue with removal of non-available webhooks --- src/discord/queue.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/discord/queue.py b/src/discord/queue.py index 23ec612..9848085 100644 --- a/src/discord/queue.py +++ b/src/discord/queue.py @@ -104,6 +104,7 @@ class MessageQueue: if webhook_messages is None: logger.error("MessageQueue.suspension_check failed due to lack of messages belonging to a webhook ID {} in message queue".format(webhook_url.split("/")[0])) return + logger.debug("Attempting to send messages for the suspended webhook.") await self.send_msg_set(webhook_messages) @staticmethod @@ -128,11 +129,11 @@ class MessageQueue: message_dict[webhook].append(msg) # defaultdict{"dadibadyvbdmadgqueh23/dihjd8agdandashd": [DiscordMessage, DiscordMessage]} return message_dict.items() - def delete_all_with_matching_metadata(self, **properties): - """Deletes all of the messages that have matching metadata properties (useful for message redaction)""" - for index, item in reversed(list(enumerate(self._queue))): - if self.compare_message_to_dict(item[1], properties): - self._queue.pop(index) + # def delete_all_with_matching_metadata(self, **properties): + # """Deletes all of the messages that have matching metadata properties (useful for message redaction)""" + # for index, item in reversed(list(enumerate(self._queue))): + # if self.compare_message_to_dict(item[1], properties): + # self._queue.pop(index) async def pack_massages(self, messages: list[QueueEntry], current_pack=None) -> AsyncGenerator[tuple[StackedDiscordMessage, int, str], None]: """Pack messages into StackedDiscordMessage. It's an async generator""" @@ -168,8 +169,6 @@ class MessageQueue: If stacked message succeeds in changing, its status in _queue is changed to sent for given webhook.""" webhook_url, messages = msg_set # str("daosdkosakda/adkahfwegr34", list(QueueEntry, QueueEntry, QueueEntry) - if webhook_url.split("/")[0] in self.webhook_suspensions: - return async for msg, index, method in self.pack_massages(messages): if msg is None: # Msg can be None if last message was not POST continue @@ -213,14 +212,17 @@ class MessageQueue: if hasattr(msg, "wiki"): # PATCH and DELETE can not have wiki attribute webhook_id = webhook_url.split("/")[0] if webhook_id in self.webhook_suspensions: + logger.debug("Found webhook ID in webhook_suspensions, nuking it.") await msg.wiki.remove_webhook_from_db(webhook_url, "Attempts to send a message to a webhook result in client error.", send_reason=False) + for message in messages: + self._queue.remove(message) self.webhook_suspensions[webhook_id].cancel() else: self.webhook_suspensions[webhook_id] = asyncio.create_task(self.suspension_check(webhook_url), name="DC Sus Check for {}".format(webhook_id)) break async def resend_msgs(self): - """Main function for orchestrating Discord message sending. It's a task that runs every half a second.""" + """Main function for orchestrating Discord message sending. It's a task that runs every second+.""" self.global_rate_limit = False if self._queue: logger.info( @@ -228,6 +230,8 @@ class MessageQueue: tasks_to_run = [] for set_msgs in await self.group_by_webhook(): # logger.debug(set_msgs) + if set_msgs[0].split("/")[0] in self.webhook_suspensions: + continue tasks_to_run.append(self.send_msg_set(set_msgs)) await asyncio.gather(*tasks_to_run) # we wait for all send_msg_set functions to finish self._queue = [x for x in self._queue if x.complete() is False] # get rid of sent messages