aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-02-29 09:30:16 -0800
committerGravatar MarkKoz <[email protected]>2020-03-22 15:54:42 -0700
commit13d4c82ffafe8ba6cd0a6dab061bef02547d66b1 (patch)
tree4e02cfd17771e5f7a471e1a1e367285be22bdc4e
parentScheduler: add a method to cancel all tasks (diff)
HelpChannels: explicitly specify if a task should be cancelled
When rescheduling an idle channel, the task will only be cancelled if the function was told the channel should currently have a task scheduled. This means warnings for missing tasks will appear when they should. The previous approach of checking if a task exists was flawed because it had no way to tell whether a task *should* exist. It assumed nothing is wrong if a task doesn't exist. Currently, the only case when a task shouldn't exist is when the cog is initialised and channels from the bot's previous life are being scheduled.
-rw-r--r--bot/cogs/help_channels.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py
index 01bcc28f7..12c64c39b 100644
--- a/bot/cogs/help_channels.py
+++ b/bot/cogs/help_channels.py
@@ -351,7 +351,7 @@ class HelpChannels(Scheduler, commands.Cog):
log.trace("Moving or rescheduling in-use channels.")
for channel in self.get_category_channels(self.in_use_category):
- await self.move_idle_channel(channel)
+ await self.move_idle_channel(channel, has_task=False)
log.info("Cog is ready!")
self.ready.set()
@@ -365,11 +365,12 @@ class HelpChannels(Scheduler, commands.Cog):
embed = message.embeds[0]
return embed.description.strip() == DORMANT_MSG.strip()
- async def move_idle_channel(self, channel: discord.TextChannel) -> None:
+ async def move_idle_channel(self, channel: discord.TextChannel, has_task: bool = True) -> None:
"""
Make the `channel` dormant if idle or schedule the move if still active.
- If a task to make the channel dormant already exists, it will first be cancelled.
+ If `has_task` is True and rescheduling is required, the extant task to make the channel
+ dormant will first be cancelled.
"""
log.trace(f"Handling in-use channel #{channel.name} ({channel.id}).")
@@ -385,7 +386,7 @@ class HelpChannels(Scheduler, commands.Cog):
await self.move_to_dormant(channel)
else:
# Cancel the existing task, if any.
- if channel.id in self.scheduled_tasks:
+ if has_task:
self.cancel_task(channel.id)
data = ChannelTimeout(channel, idle_seconds - time_elapsed)