aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Numerlor <[email protected]>2020-04-06 22:34:17 +0200
committerGravatar Numerlor <[email protected]>2020-04-09 20:24:40 +0200
commit7f1be2882dde670d12000fe661424d3b6f406f89 (patch)
treeb3671f6352adad446972410c5bba978e734c5514
parentCancel permission restoration task. (diff)
Reverse help_channel_user pairs.
Pairing users to channels was a design flaw, because the keys didn't get overwritten. This allowed multiple users to access the dormant command for the running session of the bot. Replacing this with a reversed paring fixes both issues because the cache is overwritten on channel activation.
-rw-r--r--bot/cogs/help_channels.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py
index 03bac27a4..dbe7cedc1 100644
--- a/bot/cogs/help_channels.py
+++ b/bot/cogs/help_channels.py
@@ -109,7 +109,7 @@ class HelpChannels(Scheduler, commands.Cog):
super().__init__()
self.bot = bot
- self.help_channel_users: t.Dict[discord.User, discord.TextChannel] = {}
+ self.help_channel_users: t.Dict[discord.TextChannel, discord.User] = {}
# Categories
self.available_category: discord.CategoryChannel = None
@@ -191,7 +191,7 @@ class HelpChannels(Scheduler, commands.Cog):
async def dormant_check(self, ctx: commands.Context) -> bool:
"""Return True if the user started the help channel session or passes the role check."""
- if self.help_channel_users.get(ctx.author) == ctx.channel:
+ if self.help_channel_users.get(ctx.channel) == ctx.author:
log.trace(f"{ctx.author} started the help session, passing the check for dormant.")
return True
@@ -563,7 +563,7 @@ class HelpChannels(Scheduler, commands.Cog):
await self.move_to_in_use(channel)
await self.revoke_send_permissions(message.author)
# Add user with channel for dormant check.
- self.help_channel_users[message.author] = channel
+ self.help_channel_users[channel] = message.author
log.trace(f"Releasing on_message lock for {message.id}.")
@@ -622,11 +622,9 @@ class HelpChannels(Scheduler, commands.Cog):
async def reset_send_permissions_for_help_user(self, channel: discord.TextChannel) -> None:
"""Reset send permissions in the Available category for member that started the help session in `channel`."""
- # Get mapping of channels to users that started the help session in them.
- channels_to_users = {value: key for key, value in self.help_channel_users.items()}
log.trace(f"Attempting to find user for help session in #{channel.name} ({channel.id}).")
try:
- member: discord.Member = channels_to_users[channel]
+ member = self.help_channel_users[channel]
except KeyError:
log.trace(f"Channel #{channel.name} ({channel.id}) not in help session cache, permissions unchanged.")
return