From a6ad6587c91fb0072542352faa5ca052a1f4ee0e Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Sat, 24 Oct 2020 00:23:28 +0200 Subject: [PATCH] Only send shedules during weekdays but now it actually works :tm: --- cogs/tasks.py | 10 ++++++++-- data/remind.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cogs/tasks.py b/cogs/tasks.py index 888bdc0..243e4d2 100644 --- a/cogs/tasks.py +++ b/cogs/tasks.py @@ -183,12 +183,18 @@ class Tasks(commands.Cog): # Don't do it multiple times a day if bot dc's, ... with open("files/lastTasks.json", "r") as fp: lastTasks = json.load(fp) - if self.getCurrentWeekday() < 5 and int(self.getCurrentHour()) == 7 and int(time.time()) - int(lastTasks["remind"]) > 10000: + if int(self.getCurrentHour()) == 0 and int(time.time()) - int(lastTasks["remind"]) > 10000: reminders = Reminders() + weekday = self.getCurrentWeekday() + for category in reminders.categories: + # Checks if this reminder can be sent on weekdays + if (not category["weekends"]) and weekday > 4: + continue + for user in category["users"]: - userInstance = await self.client.fetch_user(user) + userInstance = self.client.get_user(user) # User can't be fetched for whatever reason, ignore instead of crashing if userInstance is None: diff --git a/data/remind.py b/data/remind.py index 8b3bc58..ef359f3 100644 --- a/data/remind.py +++ b/data/remind.py @@ -8,11 +8,11 @@ class Reminders: self._nightlyUsers = [int(user[0]) for user in rows if user[1]] self._nightlyMessages = ["Dagelijkse herinnering om Didier Nightly te doen.", "Vrees niet, Nightly-streak-liefhebber! 't Zenne kik, Didier, me ne reminder!"] - self.nightly = {"users": self._nightlyUsers, "messages": self._nightlyMessages} + self.nightly = {"users": self._nightlyUsers, "messages": self._nightlyMessages, "weekends": True} self._les = [int(user[0]) for user in rows if user[2]] self._lesMessages = ["Lessenrooster voor vandaag:"] - self.les = {"users": self._les, "messages": self._lesMessages, "embed": self.lesEmbed()} + self.les = {"users": self._les, "messages": self._lesMessages, "embed": self.lesEmbed(), "weekends": False} self.categories = [self.nightly, self.les]