ajout méthode pour vérifier l'appartenance d'un rappel à un user

This commit is contained in:
Mylloon 2021-06-14 01:00:10 +02:00
parent 8e0f067062
commit 7d06794d93

View file

@ -5,7 +5,7 @@ class Reminder(Database):
super().__init__(r"db/bot.sqlite3") super().__init__(r"db/bot.sqlite3")
def creationTable(self): def creationTable(self):
"""Créer la table qui stocker les reminders""" """Créer la table qui stocker les reminders."""
requete = """ requete = """
CREATE TABLE IF NOT EXISTS reminder ( CREATE TABLE IF NOT EXISTS reminder (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
@ -22,7 +22,7 @@ class Reminder(Database):
self.requete(requete) self.requete(requete)
def ajoutReminder(self, messageID = int, channelID = int, mention = int, reminder = str, creation = int, expiration = int, userID = int, guildID = int): def ajoutReminder(self, messageID = int, channelID = int, mention = int, reminder = str, creation = int, expiration = int, userID = int, guildID = int):
"""Ajoute un reminder""" """Ajoute un reminder."""
requete = """ requete = """
INSERT INTO reminder ( INSERT INTO reminder (
message_id, channel_id, extrarg_id, reminder_str, creation_int, expiration_int, user_id, guild_id message_id, channel_id, extrarg_id, reminder_str, creation_int, expiration_int, user_id, guild_id
@ -33,7 +33,7 @@ class Reminder(Database):
self.requete(requete, [messageID, channelID, mention, reminder, creation, expiration, userID, guildID]) self.requete(requete, [messageID, channelID, mention, reminder, creation, expiration, userID, guildID])
def suppressionReminder(self, id = int): def suppressionReminder(self, id = int):
"""Supprime un reminder""" """Supprime un reminder."""
requete = """ requete = """
DELETE FROM reminder DELETE FROM reminder
WHERE id = ? WHERE id = ?
@ -41,7 +41,7 @@ class Reminder(Database):
self.requete(requete, id) self.requete(requete, id)
def listeReminder(self, userID = int, guildID = int): def listeReminder(self, userID = int, guildID = int):
"""Retourne la liste des reminders d'un utilisateur""" """Retourne la liste des reminders d'un utilisateur."""
requete = """ requete = """
SELECT reminder_str, creation_int, expiration_int, id FROM reminder SELECT reminder_str, creation_int, expiration_int, id FROM reminder
WHERE user_id = ? AND guild_id = ? WHERE user_id = ? AND guild_id = ?
@ -49,9 +49,21 @@ class Reminder(Database):
return self.affichageResultat(self.requete(requete, [userID, guildID])) return self.affichageResultat(self.requete(requete, [userID, guildID]))
def recuperationExpiration(self, time = int): def recuperationExpiration(self, time = int):
"""Récupère les reminders qui sont arrivés à expiration et ses infos""" """Récupère les reminders qui sont arrivés à expiration et ses infos."""
requete = """ requete = """
SELECT channel_id, extrarg_id, reminder_str, creation_int, user_id, id, message_id FROM reminder SELECT channel_id, extrarg_id, reminder_str, creation_int, user_id, id, message_id FROM reminder
WHERE expiration_int < ? WHERE expiration_int < ?
""" """
return self.affichageResultat(self.requete(requete, time)) return self.affichageResultat(self.requete(requete, time))
def appartenanceReminder(self, user = int, id = int):
"""Vérifie qu'un rappel appartiens à un utilisateur. Renvois False si le rappel n'existe pas."""
requete = """
SELECT user_id, id, message_id FROM reminder
WHERE id = ? AND user_id = ?
"""
resultat = self.affichageResultat(self.requete(requete, [id, user]))
if len(resultat) > 0:
return True
else:
return False