diff options
| author | 2020-02-24 17:01:34 -0800 | |
|---|---|---|
| committer | 2020-03-22 15:54:36 -0700 | |
| commit | c1e485b11dee6f275a4c499e8f9be6cdde9e5e7a (patch) | |
| tree | 0776b05ea118040db6228a6817349cfd09d63225 | |
| parent | HelpChannels: cancel scheduled tasks when the cog unloads (diff) | |
HelpChannels: cancel an existing task before scheduling a new one
| -rw-r--r-- | bot/cogs/help_channels.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index f493e5918..c547d9524 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -218,13 +218,21 @@ class HelpChannels(Scheduler, commands.Cog): self.ready.set() async def move_idle_channel(self, channel: discord.TextChannel) -> None: - """Make the `channel` dormant if idle or schedule the move if still active.""" + """ + 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. + """ idle_seconds = constants.HelpChannels.idle_minutes * 60 time_elapsed = await self.get_idle_time(channel) if time_elapsed is None or time_elapsed > idle_seconds: await self.move_to_dormant(channel) else: + # Cancel the existing task, if any. + if channel.id in self.scheduled_tasks: + self.cancel_task(channel.id) + data = ChannelTimeout(channel, idle_seconds - time_elapsed) self.schedule_task(self.bot.loop, channel.id, data) |