diff options
| author | 2019-10-11 15:28:42 -0700 | |
|---|---|---|
| committer | 2019-10-11 15:28:42 -0700 | |
| commit | 2836db8cb8c62c5cb92454a5f9899ed6887a8cef (patch) | |
| tree | 52d7091ca9eded88fff51732a06706bec8ce38f6 | |
| parent | Merge pull request #518 from python-discord/bump-site-postgres-to-12 (diff) | |
| parent | Merge branch 'master' into modif_2 (diff) | |
Merge pull request #495 from kraktus/modif_2
Add Periodic Ping to Checkpoint
Diffstat (limited to '')
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | bot/cogs/verification.py | 38 | 
2 files changed, 40 insertions, 1 deletions
| diff --git a/.gitignore b/.gitignore index 261fa179f..a191523b6 100644 --- a/.gitignore +++ b/.gitignore @@ -116,3 +116,6 @@ config.yml  # JUnit XML reports from pytest  junit.xml + +# Mac OS .DS_Store, which is a file that stores custom attributes of its containing folder +.DS_Store diff --git a/bot/cogs/verification.py b/bot/cogs/verification.py index acd7a7865..5b115deaa 100644 --- a/bot/cogs/verification.py +++ b/bot/cogs/verification.py @@ -1,10 +1,12 @@  import logging +from datetime import datetime  from discord import Message, NotFound, Object +from discord.ext import tasks  from discord.ext.commands import Bot, Cog, Context, command  from bot.cogs.moderation import ModLog -from bot.constants import Channels, Event, Roles +from bot.constants import Bot as BotConfig, Channels, Event, Roles  from bot.decorators import InChannelCheckFailure, in_channel, without_role  log = logging.getLogger(__name__) @@ -27,12 +29,18 @@ from time to time, you can send `!subscribe` to <#{Channels.bot}> at any time to  If you'd like to unsubscribe from the announcement notifications, simply send `!unsubscribe` to <#{Channels.bot}>.  """ +PERIODIC_PING = ( +    f"@everyone To verify that you have read our rules, please type `{BotConfig.prefix}accept`." +    f" Ping <@&{Roles.admin}> if you encounter any problems during the verification process." +) +  class Verification(Cog):      """User verification and role self-management."""      def __init__(self, bot: Bot):          self.bot = bot +        self.periodic_ping.start()      @property      def mod_log(self) -> ModLog: @@ -155,6 +163,34 @@ class Verification(Cog):          else:              return True +    @tasks.loop(hours=12) +    async def periodic_ping(self) -> None: +        """Every week, mention @everyone to remind them to verify.""" +        messages = self.bot.get_channel(Channels.verification).history(limit=10) +        need_to_post = True  # True if a new message needs to be sent. + +        async for message in messages: +            if message.author == self.bot.user and message.content == PERIODIC_PING: +                delta = datetime.utcnow() - message.created_at  # Time since last message. +                if delta.days >= 7:  # Message is older than a week. +                    await message.delete() +                else: +                    need_to_post = False + +                break + +        if need_to_post: +            await self.bot.get_channel(Channels.verification).send(PERIODIC_PING) + +    @periodic_ping.before_loop +    async def before_ping(self) -> None: +        """Only start the loop when the bot is ready.""" +        await self.bot.wait_until_ready() + +    def cog_unload(self) -> None: +        """Cancel the periodic ping task when the cog is unloaded.""" +        self.periodic_ping.cancel() +  def setup(bot: Bot) -> None:      """Verification cog load.""" | 
