Reminders work

pull/4/head
Stijn De Clercq 2020-10-23 22:12:05 +02:00
parent 6682327f1e
commit 95bdc576e1
4 changed files with 17 additions and 10 deletions

View File

@ -61,8 +61,7 @@ class School(commands.Cog):
# Add all the user's courses # Add all the user's courses
def customizeSchedule(self, ctx, year, semester): def customizeSchedule(self, ctx, year, semester):
with open("files/schedules/{}{}.json".format(year, semester), "r") as fp: schedule = les.getSchedule(semester, year)
schedule = json.load(fp)
member = self.client.get_guild(int(constants.CallOfCode)).get_member(ctx.author.id) member = self.client.get_guild(int(constants.CallOfCode)).get_member(ctx.author.id)
for role in member.roles: for role in member.roles:

View File

@ -5,7 +5,7 @@ from enums.numbers import Numbers
from functions import timeFormatters from functions import timeFormatters
from functions.database import currency, poke, prison, birthdays, stats from functions.database import currency, poke, prison, birthdays, stats
import json import json
from random import random import random
import requests import requests
import time import time
@ -183,7 +183,7 @@ class Tasks(commands.Cog):
# Don't do it multiple times a day if bot dc's, ... # Don't do it multiple times a day if bot dc's, ...
with open("files/lastTasks.json", "r") as fp: with open("files/lastTasks.json", "r") as fp:
lastTasks = json.load(fp) lastTasks = json.load(fp)
if int(self.getCurrentHour()) == 21 and int(time.time()) - int(lastTasks["remind"]) > 10000: if int(self.getCurrentHour()) == 22 and int(time.time()) - int(lastTasks["remind"]) > 10000:
reminders = Reminders() reminders = Reminders()
for category in reminders.categories: for category in reminders.categories:
@ -200,9 +200,9 @@ class Tasks(commands.Cog):
else: else:
await userInstance.send(random.choice(category["messages"]), embed=category["embed"]) await userInstance.send(random.choice(category["messages"]), embed=category["embed"])
# with open("files/lastTasks.json", "w") as fp: with open("files/lastTasks.json", "w") as fp:
# lastTasks["remind"] = round(time.time()) lastTasks["remind"] = round(time.time())
# json.dump(lastTasks, fp) json.dump(lastTasks, fp)
def getCurrentHour(self): def getCurrentHour(self):
return timeFormatters.dateTimeNow().hour return timeFormatters.dateTimeNow().hour

View File

@ -1,3 +1,4 @@
from functions import les
from functions.database import remind from functions.database import remind
@ -11,6 +12,13 @@ class Reminders:
self._les = [int(user[0]) for user in rows if user[2]] self._les = [int(user[0]) for user in rows if user[2]]
self._lesMessages = ["Lessenrooster voor vandaag:"] self._lesMessages = ["Lessenrooster voor vandaag:"]
self.les = {"users": self._les, "messages": self._lesMessages, "embed": None} self.les = {"users": self._les, "messages": self._lesMessages, "embed": self.lesEmbed()}
self.categories = [self.nightly, self.les] self.categories = [self.nightly, self.les]
def lesEmbed(self):
day, dayDatetime, semester, year = les.parseArgs([])[1:]
schedule = les.getSchedule(semester, year)
return les.createEmbed(day, dayDatetime, semester, year, schedule)

View File

@ -17,7 +17,7 @@ def getOrAddUser(userid):
res = cursor.fetchall() res = cursor.fetchall()
if not res: if not res:
cursor.execute("INSERT INTO remind(userid) VALUES %s", (int(userid),)) cursor.execute("INSERT INTO remind(userid) VALUES(%s)", (int(userid),))
connection.commit() connection.commit()
return getOrAddUser(userid) return getOrAddUser(userid)
@ -36,7 +36,7 @@ def switchReminder(userid, column):
# Switch the column value # Switch the column value
to = not (res[columns.index(column)]) to = not (res[columns.index(column)])
cursor.execute("UPDATE remind SET %s = %s WHERE userid = %s", (column, to, int(userid),)) cursor.execute("UPDATE remind SET {} = %s WHERE userid = %s".format(column), (to, int(userid),))
connection.commit() connection.commit()
return to return to