send reminder in DM if user left guild
This commit is contained in:
parent
86da4f6e70
commit
2935c6da83
2 changed files with 18 additions and 13 deletions
|
@ -25,21 +25,19 @@ class ReminderDiscord(commands.Cog, name="Reminder"):
|
|||
userID = expired[4] # personne qui a fait le rappel
|
||||
channel = self.client.get_channel(expired[0]) # salon du message
|
||||
finalEmbed = discord.Embed(description = cleanCodeStringWithMentionAndURLs(reminder), timestamp = intToDatetime(expired[3]), color = discord.Colour.random())
|
||||
guild = self.client.get_guild(expired[7])
|
||||
if expired[1] == 2 or channel == None or guild.get_member(expired[4]) is None:
|
||||
user = self.client.get_user(userID)
|
||||
if user == None: # si l'utilisateur n'est pas trouvé
|
||||
return Reminder().suppressionReminder(expired[5]) # suppression du rappel
|
||||
if expired[1] == 2: # s'il faut envoyer en DM le message
|
||||
user = self.client.get_user(userID)
|
||||
if user == None: # si l'utilisateur n'est pas trouvé
|
||||
return Reminder().suppressionReminder(expired[5]) # suppression du rappel
|
||||
channel = await user.create_dm() # envoie en DM
|
||||
userID = None # plus de mention
|
||||
sourceMessage = None # plus de message source
|
||||
channel, userID, sourceMessage = await self.reminderCheckDM(userID, expired[5])
|
||||
elif channel == None: # si le salon n'existe plus
|
||||
user = self.client.get_user(userID)
|
||||
if user == None: # si l'utilisateur n'est pas trouvé
|
||||
return Reminder().suppressionReminder(expired[5]) # suppression du rappel
|
||||
channel = await user.create_dm() # envoie en DM
|
||||
userID = None # plus de mention
|
||||
sourceMessage = None # plus de message source
|
||||
channel, userID, sourceMessage = await self.reminderCheckDM(userID, expired[5])
|
||||
finalEmbed.add_field(name = "Info", value = "Message envoyé en DM car le salon n'est plus disponible.")
|
||||
elif guild.get_member(expired[4]) is None: # si l'utilisateur n'est plus dans la guild
|
||||
channel, userID, sourceMessage = await self.reminderCheckDM(userID, expired[5])
|
||||
finalEmbed.add_field(name = "Info", value = f"Message envoyé en DM car vous avez quitté `{guild.name}`.")
|
||||
else:
|
||||
sourceMessage = expired[6]
|
||||
if sourceMessage != None: # vérification message avec slash command et que si c'est pas en DM
|
||||
|
@ -72,6 +70,13 @@ class ReminderDiscord(commands.Cog, name="Reminder"):
|
|||
async def __avant_reminderLoop(self):
|
||||
"""Wait to start the loop until the whole bot is ready"""
|
||||
await self.client.wait_until_ready()
|
||||
|
||||
async def reminderCheckDM(self, userID, reminderID):
|
||||
user = self.client.get_user(userID)
|
||||
if user == None: # si l'utilisateur n'est pas trouvé
|
||||
return Reminder().suppressionReminder(reminderID) # suppression du rappel
|
||||
channel = await user.create_dm() # envoie en DM
|
||||
return channel, None, None # plus de mention et plus de message source
|
||||
|
||||
@commands.command(name='reminder', aliases=["remind", "remindme", "rappel"])
|
||||
async def _reminder(self, ctx, time, *reminder):
|
||||
|
|
|
@ -55,7 +55,7 @@ class Reminder(Database):
|
|||
def recuperationExpiration(self, time: int):
|
||||
"""Récupère les reminders qui sont arrivés à expiration et ses infos."""
|
||||
requete = """
|
||||
SELECT channel_id, extrarg_id, reminder_str, creation_int, user_id, id, message_id FROM reminder
|
||||
SELECT channel_id, extrarg_id, reminder_str, creation_int, user_id, id, message_id, guild_id FROM reminder
|
||||
WHERE expiration_int < ?
|
||||
"""
|
||||
return self.affichageResultat(self.requete(requete, time))
|
||||
|
|
Reference in a new issue