diff options
| author | 2020-02-29 12:37:30 -0800 | |
|---|---|---|
| committer | 2020-03-22 15:54:43 -0700 | |
| commit | 6173072011b69c54fe817f383b70487e0ad97dee (patch) | |
| tree | e7de0b5840c8fb2007f8cc6f410c4f0bb21ef3b9 | |
| parent | HelpChannels: create generic way to schedule any awaitable (diff) | |
HelpChannels: allow users to claim a new channel every 15 minutes
| -rw-r--r-- | bot/cogs/help_channels.py | 20 | ||||
| -rw-r--r-- | bot/constants.py | 1 | ||||
| -rw-r--r-- | config-default.yml | 3 |
3 files changed, 24 insertions, 0 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index 5b8de156e..e6401b14b 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -515,6 +515,7 @@ class HelpChannels(Scheduler, commands.Cog): return # Ignore messages outside the Available category. await self.move_to_in_use(message.channel) + await self.revoke_send_permissions(message.author) log.trace("Releasing on_message lock.") # Move a dormant channel to the Available category to fill in the gap. @@ -522,6 +523,25 @@ class HelpChannels(Scheduler, commands.Cog): # be put in the queue. await self.move_to_available() + async def revoke_send_permissions(self, member: discord.Member) -> None: + """ + Disallow `member` to send messages in the Available category for a certain time. + + The time until permissions are reinstated can be configured with + `HelpChannels.claim_minutes`. + """ + log.trace( + f"Revoking {member}'s ({member.id}) send message permissions in the Available category." + ) + + await self.available_category.set_permissions(member, send_messages=False) + + timeout = constants.HelpChannels.claim_minutes * 60 + callback = self.available_category.set_permissions(member, send_messages=None) + + log.trace(f"Scheduling {member}'s ({member.id}) send message permissions to be reinstated.") + self.schedule_task(member.id, TaskData(timeout, callback)) + async def send_available_message(self, channel: discord.TextChannel) -> None: """Send the available message by editing a dormant message or sending a new message.""" channel_info = f"#{channel.name} ({channel.id})" diff --git a/bot/constants.py b/bot/constants.py index 7f19f8a0e..8e9d40e8d 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -529,6 +529,7 @@ class Free(metaclass=YAMLGetter): class HelpChannels(metaclass=YAMLGetter): section = 'help_channels' + claim_minutes: int cmd_whitelist: List[int] idle_minutes: int max_available: int diff --git a/config-default.yml b/config-default.yml index b91df4580..a62572b70 100644 --- a/config-default.yml +++ b/config-default.yml @@ -505,6 +505,9 @@ mention: reset_delay: 5 help_channels: + # Minimum interval before allowing a certain user to claim a new help channel + claim_minutes: 15 + # Roles which are allowed to use the command which makes channels dormant cmd_whitelist: - *HELPERS_ROLE |