implémentation de la db dans le reminder

This commit is contained in:
Mylloon 2021-06-03 14:26:51 +02:00
parent 102fb48d91
commit 2cd81f9444

View file

@ -2,15 +2,14 @@ import discord
import time import time
import os import os
import re import re
import asyncio from discord.ext import commands, tasks
from discord.ext import commands
from random import randint, shuffle from random import randint, shuffle
from datetime import datetime from datetime import datetime
from pytz import timezone from pytz import timezone
from discord_slash import cog_ext from discord_slash import cog_ext
import shlex import shlex
from utils.core import map_list_among_us, get_age, getURLsInString, getMentionInString, cleanCodeStringWithMentionAndURLs from utils.core import map_list_among_us, get_age, getURLsInString, getMentionInString, cleanCodeStringWithMentionAndURLs
from utils.core import cleanUser, userOrNick, ageLayout, stringTempsVersSecondes, nowTimestamp from utils.core import cleanUser, userOrNick, ageLayout, stringTempsVersSecondes, nowTimestampCustom, intToTimestamp, nowTimestampUTC
from utils.reminder import Reminder from utils.reminder import Reminder
def setup(client): def setup(client):
@ -22,6 +21,7 @@ class Utils(commands.Cog):
def __init__(self, client): def __init__(self, client):
self.client = client self.client = client
self.customTimezone = os.environ['TIMEZONE'] self.customTimezone = os.environ['TIMEZONE']
self._reminderLoop.start()
@commands.command(name='ping') @commands.command(name='ping')
async def _ping(self, ctx, *arg): async def _ping(self, ctx, *arg):
@ -498,9 +498,13 @@ class Utils(commands.Cog):
elif seconds > 7776000: # 90 * 60 * 60 * 24 elif seconds > 7776000: # 90 * 60 * 60 * 24
embed.add_field(name="Attention", value="Tu as spécifié une durée trop longue, la durée maximum étant de 90 jours.") embed.add_field(name="Attention", value="Tu as spécifié une durée trop longue, la durée maximum étant de 90 jours.")
else: else:
now = int(nowTimestamp()) now = int(nowTimestampUTC())
Reminder().ajoutReminder(ctx.guild.id, ctx.channel.id, mention, reminder, now, now + seconds, ctx.author.id) messageID = None
if fromSlash != True:
messageID = ctx.message.id
Reminder().ajoutReminder(messageID, ctx.channel.id, mention, reminder, now, now + seconds, ctx.author.id)
return await ctx.send(f"Ok, je t'en parles dans {time} !") return await ctx.send(f"Ok, je t'en parles dans {time} !")
await ctx.send(embed = embed)
@cog_ext.cog_slash(name="reminder", description = "Met en place un rappel.") @cog_ext.cog_slash(name="reminder", description = "Met en place un rappel.")
async def __reminder(self, ctx, time, reminder = None): async def __reminder(self, ctx, time, reminder = None):
if reminder == None: if reminder == None:
@ -508,26 +512,34 @@ class Utils(commands.Cog):
else: else:
return await self._reminder(ctx, time, reminder, True) return await self._reminder(ctx, time, reminder, True)
@tasks.loop(minutes = 1)
# message = ctx.author.mention async def _reminderLoop(self):
# if mention == 1: expiration = Reminder().recuperationExpiration(int(nowTimestampUTC()))
# mentionList = getMentionInString(reminder) for expired in expiration:
# for i in mentionList: message = f"<@{expired[4]}>"
# message += f" {i}" reminder = expired[2]
# try: if expired[1] == 1:
# if fromSlash != True: mentionList = getMentionInString(reminder)
# await ctx.message.add_reaction(emoji = '✅') for i in mentionList:
# except: message += f" {i}"
# pass channel = self.client.get_channel(expired[0])
# finalEmbed = discord.Embed(description = cleanCodeStringWithMentionAndURLs(reminder), timestamp = datetime.utcnow(), color = discord.Colour.random()) try:
# finalEmbed.set_footer(text=f"Message d'il y a {time}") sourceMessage = await channel.fetch_message(expired[6])
await sourceMessage.add_reaction(emoji = '')
except:
pass
finalEmbed = discord.Embed(description = cleanCodeStringWithMentionAndURLs(reminder), timestamp = intToTimestamp(expired[3]), color = discord.Colour.random())
finalEmbed.set_footer(text=f"Message d'il y a {int(nowTimestampUTC()) - expired[3]} secondes")
# links = "" links = ""
# findedURLs = getURLsInString(reminder) findedURLs = getURLsInString(reminder)
# for i in range(0, len(findedURLs)): for i in range(0, len(findedURLs)):
# links += f"[Lien {i + 1}]({findedURLs[i]}) · " links += f"[Lien {i + 1}]({findedURLs[i]}) · "
# if len(findedURLs) > 0: if len(findedURLs) > 0:
# finalEmbed.add_field(name = f"Lien{'s' if len(findedURLs) > 1 else ''}", value = links[:-3]) finalEmbed.add_field(name = f"Lien{'s' if len(findedURLs) > 1 else ''}", value = links[:-3])
await channel.send(message, embed = finalEmbed)
Reminder().suppressionReminder(expired[5])
# return await ctx.send(message, embed = finalEmbed) @_reminderLoop.before_loop
# await ctx.send(embed = embed) async def __avant_reminderLoop(self):
await self.client.wait_until_ready()