adding refresh button
This commit is contained in:
parent
69ea7bf5db
commit
6f6bd3ac11
2 changed files with 84 additions and 66 deletions
|
@ -1,7 +1,7 @@
|
|||
import discord
|
||||
from discord.ext import commands, tasks
|
||||
from discord_slash import cog_ext
|
||||
from utils.reminder import Reminder
|
||||
from utils.reminder import Reminder, embedListe, listReaction
|
||||
from utils.core import getURLsInString, getMentionInString, isSlash, mySendHidden, mentionToUser, cleanCodeStringWithMentionAndURLs
|
||||
from utils.time import stringTempsVersSecondes, nowUTC, intToDatetime, timedeltaToString
|
||||
|
||||
|
@ -150,9 +150,11 @@ class ReminderDiscord(commands.Cog):
|
|||
if fromSlash != True:
|
||||
await ctx.message.add_reaction(emoji = '✅')
|
||||
|
||||
embed, pageMAX = Reminder().embedListe(utilisateur, ctx.guild.id, page)
|
||||
embed, pageMAX, refresh = embedListe(utilisateur, ctx.guild.id, page)
|
||||
message = await ctx.send(embed = embed)
|
||||
if pageMAX > 1:
|
||||
if refresh:
|
||||
await message.add_reaction("🔄")
|
||||
elif pageMAX > 1:
|
||||
for emoji in ["⬅️", "➡️"]:
|
||||
await message.add_reaction(emoji)
|
||||
@cog_ext.cog_slash(name="reminderlist", description = "Affiche la liste des rappels d'un utilisateur.")
|
||||
|
@ -164,13 +166,13 @@ class ReminderDiscord(commands.Cog):
|
|||
|
||||
@commands.Cog.listener()
|
||||
async def on_raw_reaction_add(self, payload):
|
||||
message, embed = await Reminder().listReaction(self.client, payload)
|
||||
message, embed = await listReaction(self.client, payload)
|
||||
if message:
|
||||
await message.edit(embed = embed)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_raw_reaction_remove(self, payload):
|
||||
message, embed = await Reminder().listReaction(self.client, payload)
|
||||
message, embed = await listReaction(self.client, payload)
|
||||
if message:
|
||||
await message.edit(embed = embed)
|
||||
|
||||
|
|
|
@ -70,11 +70,15 @@ class Reminder(Database):
|
|||
"""
|
||||
return True if self.affichageResultat(self.requete(requete, [id, userID, guildID]))[0][0] == 1 else False
|
||||
|
||||
def embedListe(self, utilisateur, guildID, page, color = None):
|
||||
"""Fais l'embed d'une page pour l'affichage de la liste des reminders d'un utilisateur"""
|
||||
reminders = self.listeReminder(utilisateur.id, guildID)
|
||||
def embedListe(utilisateur, guildID, page, color = 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 pageMAX > 1:
|
||||
refresh = False
|
||||
else:
|
||||
refresh = True
|
||||
if color == None:
|
||||
color = Colour.random()
|
||||
embed = Embed(description = f"**Rappel{'s' if len(reminders) > 1 else ''} de {utilisateur.mention}** • Page {page}/{pageMAX}", color = color)
|
||||
|
@ -97,10 +101,11 @@ class Reminder(Database):
|
|||
else:
|
||||
embed.add_field(name = "\u200b", value = f"L'utilisateur n'a aucun rappel en attente ou page n°{page} vide !")
|
||||
embed.set_footer(text = "Les rappels qui ont déjà expirés vont apparaître dans quelques instants.\nIls peuvent avoir jusqu'à 1 minute de retard maximum.")
|
||||
return (embed, pageMAX)
|
||||
return (embed, pageMAX, refresh)
|
||||
|
||||
async def listReaction(self, client, payload):
|
||||
if payload.emoji.name in ["⬅️", "➡️"]:
|
||||
async def listReaction(client, payload):
|
||||
"""Gère le changement de page du reminderlist avec les réactions."""
|
||||
if payload.emoji.name in ["⬅️", "🔄", "➡️"]:
|
||||
if payload.event_type == "REACTION_ADD":
|
||||
if payload.member.bot == True:
|
||||
return False, False
|
||||
|
@ -126,13 +131,24 @@ class Reminder(Database):
|
|||
if page + 1 <= int(infoDescription[2]):
|
||||
page += 1
|
||||
else:
|
||||
if len(findall(r"L'utilisateur n'a aucun rappel en attente ou page n°\d+ vide !", embed["fields"][0]["value"])) == 1:
|
||||
if len(self.listeReminder(utilisateur.id, payload.guild_id)) > 0:
|
||||
page += 1
|
||||
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:
|
||||
await message.add_reaction("🔄")
|
||||
else:
|
||||
return False, False
|
||||
embed, _ = Reminder().embedListe(utilisateur, payload.guild_id, page, embed["color"])
|
||||
for reaction in message.reactions:
|
||||
if str(reaction) == "🔄":
|
||||
users = await reaction.users().flatten()
|
||||
for user in users:
|
||||
await message.remove_reaction("🔄", user)
|
||||
return message, embed
|
||||
return False, False
|
||||
|
|
Reference in a new issue