aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar kraktus <[email protected]>2019-10-11 21:57:05 +0200
committerGravatar kraktus <[email protected]>2019-10-11 21:57:05 +0200
commit91971b39bfdd9fc338689607f71caec76f01d0de (patch)
tree0bab0acca435b2998b87cc86d52be17eb131513f
parentRequested changes (diff)
Better check way of checking timelaps
Use a coroutine instead of a list.
-rw-r--r--bot/cogs/verification.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/bot/cogs/verification.py b/bot/cogs/verification.py
index 24dd9b6f8..204981d80 100644
--- a/bot/cogs/verification.py
+++ b/bot/cogs/verification.py
@@ -31,7 +31,8 @@ If you'd like to unsubscribe from the announcement notifications, simply send `!
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.")
+ f" Ping <@&{Roles.admin}> if you encounter any problems during the verification process."
+)
class Verification(Cog):
@@ -165,17 +166,18 @@ class Verification(Cog):
@tasks.loop(hours=12)
async def periodic_ping(self) -> None:
"""Post a recap message every week with an @everyone."""
- 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
+ messages = self.bot.get_channel(Channels.verification).history(limit=10) # check lasts messages
+ need_to_post = True # if the bot has to post a new message in the channel
+ async 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()
+ else:
+ need_to_post = False
+ break
+ if need_to_post: # 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: