aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Shivansh-007 <[email protected]>2021-06-13 13:20:08 +0530
committerGravatar Shivansh-007 <[email protected]>2021-06-13 13:20:08 +0530
commit99e597584516c1495e165647e5b2c131e232175f (patch)
treeba8eda2d0d3b1cfa113361c92cff340a4169210a
parent(modpings): Add subcommand to delete your modpings schedule (diff)
(modpings): Add a day to datetime if already passed
-rw-r--r--bot/exts/moderation/modpings.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/bot/exts/moderation/modpings.py b/bot/exts/moderation/modpings.py
index 9b7843e20..207480a68 100644
--- a/bot/exts/moderation/modpings.py
+++ b/bot/exts/moderation/modpings.py
@@ -92,7 +92,7 @@ class ModPings(Cog):
# Add the task again
log.trace(f"Adding mod pings schedule task again for mod with ID {mod.id}")
- schedule_start += datetime.timedelta(day=1)
+ schedule_start += datetime.timedelta(days=1)
self._modpings_scheduler.schedule_at(
schedule_start,
mod.id,
@@ -203,11 +203,19 @@ class ModPings(Cog):
)
return
+ if start < datetime.datetime.utcnow():
+ # The datetime has already gone for the day, so make it tomorrow
+ # otherwise the scheduler would schedule it immediately
+ start += datetime.timedelta(days=1)
+
start, end = start.replace(tzinfo=None), end.replace(tzinfo=None)
work_time = (end - start).total_seconds()
await self.modpings_schedule.set(ctx.author.id, f"{start.timestamp()}|{work_time}")
+ if ctx.author.id in self._modpings_scheduler:
+ self._modpings_scheduler.cancel(ctx.author.id)
+
self._modpings_scheduler.schedule_at(
start,
ctx.author.id,