aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/exts/help_channels.py41
1 files changed, 29 insertions, 12 deletions
diff --git a/bot/exts/help_channels.py b/bot/exts/help_channels.py
index ced2f72ef..25ca67d47 100644
--- a/bot/exts/help_channels.py
+++ b/bot/exts/help_channels.py
@@ -217,18 +217,13 @@ class HelpChannels(commands.Cog):
and reset the send permissions cooldown for the user who started the session.
"""
log.trace("close command invoked; checking if the channel is in-use.")
- if ctx.channel.category == self.in_use_category:
- if await self.dormant_check(ctx):
- await self.remove_cooldown_role(ctx.author)
-
- # Ignore missing task when cooldown has passed but the channel still isn't dormant.
- if ctx.author.id in self.scheduler:
- self.scheduler.cancel(ctx.author.id)
-
- await self.move_to_dormant(ctx.channel, "command")
- self.scheduler.cancel(ctx.channel.id)
- else:
+ if ctx.channel.category != self.in_use_category:
log.debug(f"{ctx.author} invoked command 'dormant' outside an in-use help channel")
+ return
+
+ if await self.dormant_check(ctx):
+ await self.move_to_dormant(ctx.channel, "command")
+ self.scheduler.cancel(ctx.channel.id)
async def get_available_candidate(self) -> discord.TextChannel:
"""
@@ -552,12 +547,13 @@ class HelpChannels(commands.Cog):
"""
log.info(f"Moving #{channel} ({channel.id}) to the Dormant category.")
- await self.help_channel_claimants.delete(channel.id)
await self.move_to_bottom_position(
channel=channel,
category_id=constants.Categories.help_dormant,
)
+ await self.unclaim_channel(channel)
+
self.bot.stats.incr(f"help.dormant_calls.{caller}")
in_use_time = await self.get_in_use_time(channel.id)
@@ -581,6 +577,27 @@ class HelpChannels(commands.Cog):
self.channel_queue.put_nowait(channel)
self.report_stats()
+ async def unclaim_channel(self, channel: discord.TextChannel) -> None:
+ """
+ Deletes `channel` from the mapping of channels to claimants and removes the help cooldown
+ role from the claimant if it was their only channel
+ """
+ claimant_id = await self.help_channel_claimants.pop(channel.id)
+
+ # Ignore missing task when cooldown has passed but the channel still isn't dormant.
+ if claimant_id in self.scheduler:
+ self.scheduler.cancel(claimant_id)
+
+ claimant = self.bot.get_guild(constants.Guild.id).get_member(claimant_id)
+
+ if claimant is None:
+ # `claimant` has left the guild, so the cooldown role need not be removed
+ return
+
+ # Remove the cooldown role if the claimant has no other channels left
+ if not any(claimant.id == user_id for _, user_id in await self.help_channel_claimants.items()):
+ await self.remove_cooldown_role(claimant)
+
async def move_to_in_use(self, channel: discord.TextChannel) -> None:
"""Make a channel in-use and schedule it to be made dormant."""
log.info(f"Moving #{channel} ({channel.id}) to the In Use category.")