aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2024-03-16 06:51:16 +0000
committerGravatar Chris Lovering <[email protected]>2024-03-26 12:24:36 +0000
commitc1a51dbc398a86ff4a6797028a0b9b758cc22997 (patch)
tree24074a8bf7a7d9806706282ba8c1eb965da8ba90
parentMake help showable through button on command error message. (#2439) (diff)
Always cancel scheduled help post closes if present in scheduler when rescheduling a task
-rw-r--r--bot/exts/help_channels/_channel.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/bot/exts/help_channels/_channel.py b/bot/exts/help_channels/_channel.py
index fe7da789b..0e56b8ba8 100644
--- a/bot/exts/help_channels/_channel.py
+++ b/bot/exts/help_channels/_channel.py
@@ -205,13 +205,8 @@ async def get_closing_time(post: discord.Thread) -> tuple[arrow.Arrow, _stats.Cl
return time, _stats.ClosingReason.INACTIVE
-async def maybe_archive_idle_post(post: discord.Thread, scheduler: scheduling.Scheduler, has_task: bool = True) -> None:
- """
- Archive the `post` if idle, or schedule the archive for later if still active.
-
- If `has_task` is True and rescheduling is required, the extant task to make the post
- dormant will first be cancelled.
- """
+async def maybe_archive_idle_post(post: discord.Thread, scheduler: scheduling.Scheduler) -> None:
+ """Archive the `post` if idle, or schedule the archive for later if still active."""
try:
await post.guild.fetch_channel(post.id)
except discord.HTTPException:
@@ -235,9 +230,10 @@ async def maybe_archive_idle_post(post: discord.Thread, scheduler: scheduling.Sc
await _close_help_post(post, closing_reason)
return
- if has_task:
+ if post.id in scheduler:
+ # Cancel any existing close task
scheduler.cancel(post.id)
delay = (closing_time - arrow.utcnow()).seconds
log.info(f"#{post} ({post.id}) is still active; scheduling it to be archived after {delay} seconds.")
- scheduler.schedule_later(delay, post.id, maybe_archive_idle_post(post, scheduler, has_task=True))
+ scheduler.schedule_later(delay, post.id, maybe_archive_idle_post(post, scheduler))