removing a call to the database

This commit is contained in:
Mylloon 2021-07-30 20:30:03 +02:00
parent 12d4c833dd
commit a7b1defaad
2 changed files with 17 additions and 13 deletions

View file

@ -150,7 +150,7 @@ class ReminderDiscord(commands.Cog):
if fromSlash != True: if fromSlash != True:
await ctx.message.add_reaction(emoji = '') await ctx.message.add_reaction(emoji = '')
embed, pageMAX, refresh = embedListe(utilisateur, ctx.guild.id, page) embed, pageMAX, refresh = await embedListe(utilisateur, ctx.guild.id, page)
message = await ctx.send(embed = embed) message = await ctx.send(embed = embed)
if refresh: if refresh:
await message.add_reaction("🔄") await message.add_reaction("🔄")

View file

@ -70,11 +70,19 @@ class Reminder(Database):
""" """
return True if self.affichageResultat(self.requete(requete, [id, userID, guildID]))[0][0] == 1 else False return True if self.affichageResultat(self.requete(requete, [id, userID, guildID]))[0][0] == 1 else False
def embedListe(utilisateur, guildID, page, color = None): async def embedListe(utilisateur, guildID, page, color = None, refresh_message = None):
"""Fais l'embed d'une page pour l'affichage de la liste des reminders d'un utilisateur.""" """Fais l'embed d'une page pour l'affichage de la liste des reminders d'un utilisateur."""
reminders = Reminder().listeReminder(utilisateur.id, guildID) reminders = Reminder().listeReminder(utilisateur.id, guildID)
pageMAX = -(-len(reminders) // 5) pageMAX = -(-len(reminders) // 5)
if refresh_message:
if len(reminders) > 0:
if pageMAX > 1 and refresh_message.reactions[0] != "⬅️":
for emoji in ["⬅️", "➡️"]:
await refresh_message.add_reaction(emoji)
else:
return (False, False, False)
if pageMAX > 1: if pageMAX > 1:
refresh = False refresh = False
else: else:
@ -119,6 +127,7 @@ async def listReaction(client, payload):
infoDescription = findall(r"\*\*Rappels? de <@\!?(\d+)>\*\* • Page (\d+)\/(\d+)", embed["description"])[0] infoDescription = findall(r"\*\*Rappels? de <@\!?(\d+)>\*\* • Page (\d+)\/(\d+)", embed["description"])[0]
utilisateur = client.get_user(int(infoDescription[0])) utilisateur = client.get_user(int(infoDescription[0]))
page = int(infoDescription[1]) page = int(infoDescription[1])
refresh_message = None
if payload.emoji.name == "⬅️": if payload.emoji.name == "⬅️":
if page > 1: if page > 1:
page -= 1 page -= 1
@ -133,16 +142,11 @@ async def listReaction(client, payload):
else: else:
return False, False return False, False
if payload.emoji.name == "🔄": if payload.emoji.name == "🔄":
reminders = Reminder().listeReminder(utilisateur.id, payload.guild_id) refresh_message = message
if len(reminders) > 0: embed, _, refresh = await embedListe(utilisateur, payload.guild_id, page, embed["color"], refresh_message)
page = 1 if embed == False:
if -(-len(reminders) // 5) > 1 and message.reactions[0] != "⬅️":
for emoji in ["⬅️", "➡️"]:
await message.add_reaction(emoji)
else:
return False, False return False, False
embed, _, refresh = embedListe(utilisateur, payload.guild_id, page, embed["color"]) if refresh == True:
if refresh:
await message.add_reaction("🔄") await message.add_reaction("🔄")
else: else:
for reaction in message.reactions: for reaction in message.reactions: