mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
Attempt to fix issue with removal of non-available webhooks
This commit is contained in:
parent
2a06074df5
commit
55347d62a2
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue