Last fixes

pull/167/head
stijndcl 2023-02-03 00:57:12 +01:00 committed by Stijn De Clercq
parent 4548f0e003
commit 4e205a02c7
1 changed files with 8 additions and 2 deletions

View File

@ -44,8 +44,12 @@ class Timer:
"""Replace the current task if necessary"""
# If there is a current (pending) task, and the new timer is sooner than the
# pending one, cancel it
if self._task is not None and not self._task.done() and self.upcoming_timer > event.timestamp:
self._task.cancel()
if self._task is not None and not self._task.done():
if self.upcoming_timer > event.timestamp:
self._task.cancel()
else:
# The new task happens after the existing task, it has to wait for its turn
return
self._task = self.client.loop.create_task(self.end_timer(endtime=event.timestamp, event_id=event.event_id))
self.upcoming_timer = event.timestamp
@ -54,4 +58,6 @@ class Timer:
async def end_timer(self, *, endtime: datetime, event_id: int):
"""Wait until a timer runs out, and then trigger an event to send the message"""
await discord.utils.sleep_until(endtime)
self.upcoming_timer = None
self.upcoming_event_id = None
self.client.dispatch("timer_end", event_id)