diff --git a/src/cogs/reminder.py b/src/cogs/reminder.py index 33aed37..984f95d 100644 --- a/src/cogs/reminder.py +++ b/src/cogs/reminder.py @@ -150,7 +150,7 @@ class ReminderDiscord(commands.Cog): if fromSlash != True: 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) if refresh: await message.add_reaction("🔄") diff --git a/src/utils/reminder.py b/src/utils/reminder.py index ec507fe..2a9a6d3 100644 --- a/src/utils/reminder.py +++ b/src/utils/reminder.py @@ -70,11 +70,19 @@ class Reminder(Database): """ 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.""" reminders = Reminder().listeReminder(utilisateur.id, guildID) - 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: refresh = False else: @@ -119,6 +127,7 @@ async def listReaction(client, payload): infoDescription = findall(r"\*\*Rappels? de <@\!?(\d+)>\*\* • Page (\d+)\/(\d+)", embed["description"])[0] utilisateur = client.get_user(int(infoDescription[0])) page = int(infoDescription[1]) + refresh_message = None if payload.emoji.name == "⬅️": if page > 1: page -= 1 @@ -133,16 +142,11 @@ async def listReaction(client, payload): else: return False, False if payload.emoji.name == "🔄": - reminders = Reminder().listeReminder(utilisateur.id, payload.guild_id) - if len(reminders) > 0: - page = 1 - if -(-len(reminders) // 5) > 1 and message.reactions[0] != "⬅️": - for emoji in ["⬅️", "➡️"]: - await message.add_reaction(emoji) - else: - return False, False - embed, _, refresh = embedListe(utilisateur, payload.guild_id, page, embed["color"]) - if refresh: + refresh_message = message + embed, _, refresh = await embedListe(utilisateur, payload.guild_id, page, embed["color"], refresh_message) + if embed == False: + return False, False + if refresh == True: await message.add_reaction("🔄") else: for reaction in message.reactions: