diff options
author | 2019-10-05 18:07:25 +0200 | |
---|---|---|
committer | 2019-10-05 18:07:25 +0200 | |
commit | 23fe6c71398391fea8fdca71a287faca304c3ea8 (patch) | |
tree | 1e382ac3c077554527d9215b26e5edc92afb9665 | |
parent | Added a new `periodic_ping` to fix #320 (diff) |
Requested changes
Changed `PERIODIC_PING` from 2 f-string to one normal and one f-string.
The bot now checks in the lasts 5 messages (why 5? Admins/mods could have add some notes, and/or users could have wrong taped the command, which lead the bot to send a message) the time of his last ping. If there is not historic ping, will send one (initialization and make the command more robust). If there is one previous `PERIODIC_PING` message, checks if it older than one week.
I also set the countdown from 1 to 12 hours. Why not more? Because each time the bot is restarted the countdown is reset to 0, and I don't know how often it is restarted.
-rw-r--r-- | bot/cogs/verification.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/bot/cogs/verification.py b/bot/cogs/verification.py index 588037d45..24dd9b6f8 100644 --- a/bot/cogs/verification.py +++ b/bot/cogs/verification.py @@ -29,8 +29,9 @@ 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 `!accept`." - f" Ping <@&{Roles.admin}> if you encounter any problems during the verification process.") +PERIODIC_PING = ( + "@everyone To verify that you have read our rules, please type `!accept`." + f" Ping <@&{Roles.admin}> if you encounter any problems during the verification process.") class Verification(Cog): @@ -161,14 +162,20 @@ class Verification(Cog): else: return True - @tasks.loop(hours=1.0) + @tasks.loop(hours=12) async def periodic_ping(self) -> None: """Post a recap message every week with an @everyone.""" - message = await self.bot.get_channel(Channels.verification).history(limit=1).flatten() # check last message - delta = datetime.utcnow() - message[0].created_at # time since last periodic ping - if delta.days >= 7: # if the message is older than a week - await message[0].delete() + messages = await self.bot.get_channel(Channels.verification).history(limit=5).flatten() # check lasts messages + messages_content = [i.content for i in messages] + if PERIODIC_PING not in messages_content: # if the bot did not posted yet await self.bot.get_channel(Channels.verification).send(PERIODIC_PING) + else: + for message in messages: + if message.content == PERIODIC_PING: # to be sure to measure timelaps between two identical messages + delta = datetime.utcnow() - message.created_at # time since last periodic ping + if delta.days >= 7: # if the message is older than a week + await message.delete() + await self.bot.get_channel(Channels.verification).send(PERIODIC_PING) @periodic_ping.before_loop async def before_ping(self) -> None: |