From 44e30289d9682a92ef6e6d2ca8e9cf9b669ad65c Mon Sep 17 00:00:00 2001 From: kwzrd Date: Fri, 12 Jun 2020 17:23:26 +0200 Subject: Incidents: implement `make_confirmation_task` method --- bot/cogs/moderation/incidents.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bot/cogs/moderation/incidents.py b/bot/cogs/moderation/incidents.py index 8781d6749..2186530d9 100644 --- a/bot/cogs/moderation/incidents.py +++ b/bot/cogs/moderation/incidents.py @@ -145,6 +145,21 @@ class Incidents(Cog): log.debug("Message archived successfully!") return True + def make_confirmation_task(self, incident: discord.Message, timeout: int = 5) -> asyncio.Task: + """ + Create a task to wait `timeout` seconds for `incident` to be deleted. + + If `timeout` passes, this will raise `asyncio.TimeoutError`, signaling that we haven't + been able to confirm that the message was deleted. + """ + log.debug(f"Confirmation task will wait {timeout=} seconds for {incident.id=} to be deleted") + coroutine = self.bot.wait_for( + event="raw_message_delete", + check=lambda payload: payload.message_id == incident.id, + timeout=timeout, + ) + return self.bot.loop.create_task(coroutine) + async def resolve_message(self, message_id: int) -> t.Optional[discord.Message]: """ Get `discord.Message` for `message_id` from cache, or API. -- cgit v1.2.3