diff options
| -rw-r--r-- | bot/cogs/help_channels.py | 21 | 
1 files changed, 21 insertions, 0 deletions
| diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index 187adfe51..9313efc67 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -113,6 +113,10 @@ class HelpChannels(Scheduler, commands.Cog):      # RedisCache[discord.TextChannel.id, UtcPosixTimestamp]      claim_times = RedisCache() +    # This cache maps a help channel to original question message in same channel. +    # RedisCache[discord.TextChannel.id, discord.Message.id] +    question_messages = RedisCache() +      def __init__(self, bot: Bot):          super().__init__() @@ -548,6 +552,15 @@ class HelpChannels(Scheduler, commands.Cog):          A caller argument is provided for metrics.          """ +        msg_id = await self.question_messages.pop(channel.id) + +        try: +            await self.bot.http.unpin_message(channel.id, msg_id) +        except discord.HTTPException: +            log.trace(f"Message {msg_id} don't exist, can't unpin.") +        else: +            log.trace(f"Unpinned message {msg_id}.") +          log.info(f"Moving #{channel} ({channel.id}) to the Dormant category.")          await self.move_to_bottom_position( @@ -688,6 +701,14 @@ class HelpChannels(Scheduler, commands.Cog):              log.info(f"Channel #{channel} was claimed by `{message.author.id}`.")              await self.move_to_in_use(channel)              await self.revoke_send_permissions(message.author) +            # Pin message for better access and storage this to cache +            try: +                await message.pin() +            except discord.NotFound: +                log.info(f"Pinning message {message.id} ({channel}) failed because message got deleted.") +            else: +                await self.question_messages.set(channel.id, message.id) +              # Add user with channel for dormant check.              await self.help_channel_claimants.set(channel.id, message.author.id) | 
