global event

This commit is contained in:
Mylloon 2021-08-22 15:47:40 +02:00
parent d2bfe8cbe3
commit 4ec7313a72
3 changed files with 27 additions and 21 deletions

View file

@ -1,8 +1,7 @@
import discord import discord
from discord.ext import commands, tasks from discord.ext import commands, tasks
from discord_slash import cog_ext from discord_slash import cog_ext
from utils.reminder import Reminder from utils.reminder import Reminder, embedListeReminder
from utils.page import embedListeReminder, listReaction
from utils.core import getURLsInString, getMentionInString, isSlash, mySendHidden from utils.core import getURLsInString, getMentionInString, isSlash, mySendHidden
from utils.core import addReaction, mentionToUser, cleanCodeStringWithMentionAndURLs from utils.core import addReaction, mentionToUser, cleanCodeStringWithMentionAndURLs
from utils.time import stringTempsVersSecondes, nowUTC, intToDatetime, timedeltaToString from utils.time import stringTempsVersSecondes, nowUTC, intToDatetime, timedeltaToString
@ -178,20 +177,6 @@ class ReminderDiscord(commands.Cog, name="Reminder"):
else: else:
return await self._reminderlist(ctx, userorpage, True) return await self._reminderlist(ctx, userorpage, True)
@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
"""Triggered when a reaction is added"""
message, embed = await listReaction(0, self.client, payload)
if message:
await message.edit(embed = embed)
@commands.Cog.listener()
async def on_raw_reaction_remove(self, payload):
"""Triggered when a reaction is removed"""
message, embed = await listReaction(0, self.client, payload)
if message:
await message.edit(embed = embed)
@commands.command(name='reminderdelete', aliases=["reminddelete", "rd"]) @commands.command(name='reminderdelete', aliases=["reminddelete", "rd"])
async def _reminderdelete(self, ctx, *id): async def _reminderdelete(self, ctx, *id):
"""Suppprime un rappel.\n ➡ Syntaxe: {PREFIX}reminderdelete/rd <id>""" """Suppprime un rappel.\n ➡ Syntaxe: {PREFIX}reminderdelete/rd <id>"""

View file

@ -6,6 +6,7 @@ from discord_slash import SlashCommand
from discord.ext import commands from discord.ext import commands
from utils.reminder import Reminder from utils.reminder import Reminder
from utils.core import load, addReaction from utils.core import load, addReaction
from utils.page import listReaction
keys = load(["PREFIX", "TOKEN_DISCORD", "DEACTIVATE"]) keys = load(["PREFIX", "TOKEN_DISCORD", "DEACTIVATE"])
customPrefix = keys["PREFIX"] customPrefix = keys["PREFIX"]
@ -74,5 +75,20 @@ async def on_message(message):
prefix = await client.get_prefix(message) prefix = await client.get_prefix(message)
await ctx.send(f">>> Coucou !\nMon préfix est `{prefix}` et ma commande d'aide est `{prefix}help`") await ctx.send(f">>> Coucou !\nMon préfix est `{prefix}` et ma commande d'aide est `{prefix}help`")
"""Ses évenements sont pour le reminder et le todo"""
@client.event
async def on_raw_reaction_add(payload):
"""Triggered when a reaction is added"""
message, embed = await listReaction(client, payload)
if message:
await message.edit(embed = embed)
@client.event
async def on_raw_reaction_remove(payload):
"""Triggered when a reaction is removed"""
message, embed = await listReaction(client, payload)
if message:
await message.edit(embed = embed)
print("Connexion à Discord...", end = " ") print("Connexion à Discord...", end = " ")
client.run(keys["TOKEN_DISCORD"]) client.run(keys["TOKEN_DISCORD"])

View file

@ -1,8 +1,8 @@
from re import findall
from utils.reminder import embedListeReminder from utils.reminder import embedListeReminder
from utils.todo import embedListeToDo from utils.todo import embedListeToDo
from re import findall
async def listReaction(type: int, client, payload): async def listReaction(client, payload):
""" """
Gère le changement de page du reminderlist ou du todolist avec les réactions. Gère le changement de page du reminderlist ou du todolist avec les réactions.
Types: 0 -> reminder | 1 -> todo Types: 0 -> reminder | 1 -> todo
@ -18,7 +18,14 @@ async def listReaction(type: int, client, payload):
embed = message.embeds[0].to_dict() embed = message.embeds[0].to_dict()
if "description" in embed: # si c'est un embed avec une description if "description" in embed: # si c'est un embed avec une description
if len(findall(r"\*\*(Rappels?|To Do('s)?) de <@\!?\d+>\*\* • Page \d+\/\d+", embed["description"])) == 1: # si c'est le bon embed if len(findall(r"\*\*(Rappels?|To Do('s)?) de <@\!?\d+>\*\* • Page \d+\/\d+", embed["description"])) == 1: # si c'est le bon embed
infoDescription = findall(r"\*\*Rappels? de <@\!?(\d+)>\*\* • Page (\d+)\/(\d+)", embed["description"])[0] infoDescription = findall(r"\*\*(Rappels?|To Do('s)?) de <@\!?(\d+)>\*\* • Page (\d+)\/(\d+)", embed["description"])[0]
if "Rappel" in infoDescription[0]:
type = 0
elif "To Do" in infoDescription[0]:
type = 1
else:
raise Exception("Unknown type")
infoDescription = infoDescription[2:]
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 refresh_message = None
@ -44,8 +51,6 @@ async def listReaction(type: int, client, payload):
embed, _, refresh = await embedListeReminder(utilisateur, payload.guild_id, page, embed["color"], refresh_message) embed, _, refresh = await embedListeReminder(utilisateur, payload.guild_id, page, embed["color"], refresh_message)
elif type == 1: elif type == 1:
embed, _, refresh = await embedListeToDo(utilisateur, page, embed["color"], refresh_message) embed, _, refresh = await embedListeToDo(utilisateur, page, embed["color"], refresh_message)
else:
raise Exception("Unknown type")
if embed == False: if embed == False:
return False, False return False, False
if refresh == True: if refresh == True: