implémentation de la db dans le reminder
This commit is contained in:
parent
102fb48d91
commit
2cd81f9444
1 changed files with 38 additions and 26 deletions
|
@ -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)
|
||||||
|
async def _reminderLoop(self):
|
||||||
|
expiration = Reminder().recuperationExpiration(int(nowTimestampUTC()))
|
||||||
|
for expired in expiration:
|
||||||
|
message = f"<@{expired[4]}>"
|
||||||
|
reminder = expired[2]
|
||||||
|
if expired[1] == 1:
|
||||||
|
mentionList = getMentionInString(reminder)
|
||||||
|
for i in mentionList:
|
||||||
|
message += f" {i}"
|
||||||
|
channel = self.client.get_channel(expired[0])
|
||||||
|
try:
|
||||||
|
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")
|
||||||
|
|
||||||
# message = ctx.author.mention
|
links = ""
|
||||||
# if mention == 1:
|
findedURLs = getURLsInString(reminder)
|
||||||
# mentionList = getMentionInString(reminder)
|
for i in range(0, len(findedURLs)):
|
||||||
# for i in mentionList:
|
links += f"[Lien {i + 1}]({findedURLs[i]}) · "
|
||||||
# message += f" {i}"
|
if len(findedURLs) > 0:
|
||||||
# try:
|
finalEmbed.add_field(name = f"Lien{'s' if len(findedURLs) > 1 else ''}", value = links[:-3])
|
||||||
# if fromSlash != True:
|
await channel.send(message, embed = finalEmbed)
|
||||||
# await ctx.message.add_reaction(emoji = '✅')
|
Reminder().suppressionReminder(expired[5])
|
||||||
# except:
|
|
||||||
# pass
|
|
||||||
# finalEmbed = discord.Embed(description = cleanCodeStringWithMentionAndURLs(reminder), timestamp = datetime.utcnow(), color = discord.Colour.random())
|
|
||||||
# finalEmbed.set_footer(text=f"Message d'il y a {time}")
|
|
||||||
|
|
||||||
# links = ""
|
@_reminderLoop.before_loop
|
||||||
# findedURLs = getURLsInString(reminder)
|
async def __avant_reminderLoop(self):
|
||||||
# for i in range(0, len(findedURLs)):
|
await self.client.wait_until_ready()
|
||||||
# links += f"[Lien {i + 1}]({findedURLs[i]}) · "
|
|
||||||
# if len(findedURLs) > 0:
|
|
||||||
# finalEmbed.add_field(name = f"Lien{'s' if len(findedURLs) > 1 else ''}", value = links[:-3])
|
|
||||||
|
|
||||||
# return await ctx.send(message, embed = finalEmbed)
|
|
||||||
# await ctx.send(embed = embed)
|
|
||||||
|
|
Reference in a new issue