envoie message en DM quand salon indisponible reminder
This commit is contained in:
parent
7d06794d93
commit
51c545535a
1 changed files with 26 additions and 11 deletions
|
@ -499,6 +499,8 @@ class Utils(commands.Cog):
|
||||||
mention = 1
|
mention = 1
|
||||||
seconds = stringTempsVersSecondes(time)
|
seconds = stringTempsVersSecondes(time)
|
||||||
if type(seconds) != int:
|
if type(seconds) != int:
|
||||||
|
if fromSlash != True:
|
||||||
|
await ctx.message.add_reaction(emoji = '❓')
|
||||||
return await ctx.send(seconds)
|
return await ctx.send(seconds)
|
||||||
if seconds == 0:
|
if seconds == 0:
|
||||||
embed.add_field(name="Attention", value="Mauvais format pour le temps, `d` pour jour, `h` pour heure, `m` pour minute, `s` pour seconde\nMet un `@` accolée à l'unité pour mentionner les gens mentionner dans ton message.")
|
embed.add_field(name="Attention", value="Mauvais format pour le temps, `d` pour jour, `h` pour heure, `m` pour minute, `s` pour seconde\nMet un `@` accolée à l'unité pour mentionner les gens mentionner dans ton message.")
|
||||||
|
@ -527,27 +529,40 @@ class Utils(commands.Cog):
|
||||||
async def _reminderLoop(self):
|
async def _reminderLoop(self):
|
||||||
expiration = Reminder().recuperationExpiration(int(nowUTC()))
|
expiration = Reminder().recuperationExpiration(int(nowUTC()))
|
||||||
for expired in expiration:
|
for expired in expiration:
|
||||||
message = f"<@{expired[4]}>"
|
|
||||||
reminder = expired[2]
|
reminder = expired[2]
|
||||||
if expired[1] == 1:
|
userID = expired[4]
|
||||||
mentionList = getMentionInString(reminder)
|
|
||||||
for i in mentionList:
|
|
||||||
message += f" {i}"
|
|
||||||
channel = self.client.get_channel(expired[0])
|
channel = self.client.get_channel(expired[0])
|
||||||
|
finalEmbed = discord.Embed(description = cleanCodeStringWithMentionAndURLs(reminder), timestamp = intToDatetime(expired[3]), color = discord.Colour.random())
|
||||||
|
if channel == None:
|
||||||
|
user = self.client.get_user(userID)
|
||||||
|
if user == None: # si l'utilisateur n'est pas trouvé
|
||||||
|
return Reminder().suppressionReminder(expired[5])
|
||||||
|
channel = await user.create_dm()
|
||||||
|
userID = None
|
||||||
|
finalEmbed.add_field(name = "Info", value = "Message envoyé en DM car le salon n'est plus disponible.")
|
||||||
|
else:
|
||||||
sourceMessage = expired[6]
|
sourceMessage = expired[6]
|
||||||
if sourceMessage != None:
|
if sourceMessage != None:
|
||||||
sourceMessage = await channel.fetch_message(sourceMessage)
|
sourceMessage = await channel.fetch_message(sourceMessage)
|
||||||
await sourceMessage.add_reaction(emoji = '✅')
|
await sourceMessage.add_reaction(emoji = '✅')
|
||||||
finalEmbed = discord.Embed(description = cleanCodeStringWithMentionAndURLs(reminder), timestamp = intToDatetime(expired[3]), color = discord.Colour.random())
|
|
||||||
finalEmbed.set_footer(text=f"Message d'il y a {timedeltaToString(int(nowUTC()) - expired[3])}")
|
finalEmbed.set_footer(text=f"Message d'il y a {timedeltaToString(int(nowUTC()) - expired[3])}")
|
||||||
|
|
||||||
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])
|
||||||
|
message = ""
|
||||||
|
if userID != None:
|
||||||
|
message = f"<@{userID}>"
|
||||||
|
if expired[1] == 1:
|
||||||
|
mentionList = getMentionInString(reminder)
|
||||||
|
for i in mentionList:
|
||||||
|
message += f" {i}"
|
||||||
|
try:
|
||||||
await channel.send(message, embed = finalEmbed)
|
await channel.send(message, embed = finalEmbed)
|
||||||
|
except: # les DM sont fermés
|
||||||
|
return Reminder().suppressionReminder(expired[5])
|
||||||
Reminder().suppressionReminder(expired[5])
|
Reminder().suppressionReminder(expired[5])
|
||||||
@_reminderLoop.before_loop
|
@_reminderLoop.before_loop
|
||||||
async def __avant_reminderLoop(self):
|
async def __avant_reminderLoop(self):
|
||||||
|
|
Reference in a new issue