Repository: python-discord/bot

Issue:
Mods+ should be permitted to use any command in #checkpoint
Currently the bot will ignore all commands inside #checkpoint. However, there are cases where this is not ideal, for example if we want to clean the channel up with the !clean command.

Write a fix that allows moderators, admins and owners to use any command in this channel, but still ignores everything but `!accept` from anyone else.
Make the bot delete any message it posts in #checkpoint after a while
Currently, messages posted in #checkpoint by the bot will usually be posted with a `delete_after` of 10 seconds or so, so they will automatically be removed. This helps the channel stay clean so that the important messages at the top of it will stay there. The bot also automatically deletes any messages posted in this channel by other users.

However, when the bot posts messages in this channel that are not related to the Verification cog, they will never get deleted. For example, if a user in this channel triggers the spam filter, the bot will post a message about muting the user which will never be deleted.

We want this channel to stay clean, so let's implement some logics that ensure that **any message posted by the bot** in this channel will be deleted after a short time, like 10 seconds.


Discussion:

Resolving patch:
diff --git a/bot/cogs/verification.py b/bot/cogs/verification.py
--- a/bot/cogs/verification.py
+++ b/bot/cogs/verification.py
@@ -10,9 +10,10 @@
 from bot.constants import (
     Bot as BotConfig,
     Channels, Colours, Event,
-    Filter, Icons, Roles
+    Filter, Icons, MODERATION_ROLES, Roles
 )
 from bot.decorators import InChannelCheckFailure, in_channel, without_role
+from bot.utils.checks import without_role_check
 
 log = logging.getLogger(__name__)
 
@@ -38,6 +39,7 @@
     f"@everyone To verify that you have read our rules, please type `{BotConfig.prefix}accept`."
     f" If you encounter any problems during the verification process, ping the <@&{Roles.admin}> role in this channel."
 )
+BOT_MESSAGE_DELETE_DELAY = 10
 
 
 class Verification(Cog):
@@ -55,12 +57,16 @@ def mod_log(self) -> ModLog:
     @Cog.listener()
     async def on_message(self, message: Message) -> None:
         """Check new message event for messages to the checkpoint channel & process."""
-        if message.author.bot:
-            return  # They're a bot, ignore
-
         if message.channel.id != Channels.verification:
             return  # Only listen for #checkpoint messages
 
+        if message.author.bot:
+            # They're a bot, delete their message after the delay.
+            # But not the periodic ping; we like that one.
+            if message.content != PERIODIC_PING:
+                await message.delete(delay=BOT_MESSAGE_DELETE_DELAY)
+            return
+
         # if a user mentions a role or guild member
         # alert the mods in mod-alerts channel
         if message.mentions or message.role_mentions:
@@ -190,7 +196,7 @@ async def cog_command_error(self, ctx: Context, error: Exception) -> None:
     @staticmethod
     def bot_check(ctx: Context) -> bool:
         """Block any command within the verification channel that is not !accept."""
-        if ctx.channel.id == Channels.verification:
+        if ctx.channel.id == Channels.verification and without_role_check(ctx, *MODERATION_ROLES):
             return ctx.command.name == "accept"
         else:
             return True


Test patch: