meilleur articulation de la commande AVIS - affichage du remindme avec un embed - support des accords dans le remindme et meilleur gestion d'erreurs

This commit is contained in:
Mylloon 2021-05-11 15:39:06 +02:00
parent 47984b1682
commit af88144ad0

View file

@ -310,6 +310,20 @@ class Utils(commands.Cog):
pass pass
return stringMessage return stringMessage
def _cleanCodeStringWithMention(self, string):
string = f"`{string}`"
findedMention = []
for findingMention in re.findall(r'<@[!]?\d*>', string): # récupération mention dans la string
findedMention.append(findingMention)
findedMention = list(dict.fromkeys(findedMention)) # suppression doublon de mention
for i in range(0, len(findedMention)):
string = string.replace(findedMention[i], f"`{findedMention[i]}`") # conserve la mention dans le message
if string.startswith("``<@"): # conserve le format quand mention au début de la string
string = string[2:]
if string.endswith(">``"): # conserve le format quand mention à la fin de la string
string = string[:-2]
return string
@commands.command(name='sondage') @commands.command(name='sondage')
async def _sondage(self, ctx, *args): async def _sondage(self, ctx, *args):
"""Fais un sondage.\n ➡ Syntaxe: .sondage "<Question>" "<Proposition1>" "<Proposition...>" "<Proposition20>" """ """Fais un sondage.\n ➡ Syntaxe: .sondage "<Question>" "<Proposition1>" "<Proposition...>" "<Proposition20>" """
@ -365,18 +379,7 @@ class Utils(commands.Cog):
for findedId in re.findall(r'\d+', titre): # récupération mention dans titre for findedId in re.findall(r'\d+', titre): # récupération mention dans titre
titre = self._cleanUser(ctx, titre, findedId) titre = self._cleanUser(ctx, titre, findedId)
args = args[1:] args = args[1:]
demande = f"`{args[0]}`" embed = discord.Embed(title = titre, description = self._cleanCodeStringWithMention(args[0]), color = discord.Colour.random()).set_footer(text = self._userOrNick(ctx.author), icon_url = ctx.author.avatar_url)
findedMention = []
for findingMention in re.findall(r'<@[!]?\d*>', demande): # récupération mention dans la demande
findedMention.append(findingMention)
findedMention = list(dict.fromkeys(findedMention)) # suppression doublon de mention
for i in range(0, len(findedMention)):
demande = demande.replace(findedMention[i], f"`{findedMention[i]}`") # conserve la mention dans le message
if demande.startswith("``<@"): # conserve le format quand mention au début de la demande
demande = demande[2:]
if demande.endswith(">``"): # conserve le format quand mention à la fin de la demande
demande = demande[:-2]
embed = discord.Embed(title = titre, description = demande, color = discord.Colour.random()).set_footer(text = self._userOrNick(ctx.author), icon_url = ctx.author.avatar_url)
message = await ctx.send(embed = embed) message = await ctx.send(embed = embed)
reactions = ['', '🤷', ''] reactions = ['', '🤷', '']
for i in reactions: for i in reactions:
@ -388,21 +391,28 @@ class Utils(commands.Cog):
"""Met en place un rappel.\n ➡ Syntaxe: .reminder/remind/remindme <temps (d/h/m/s)> <message> """ """Met en place un rappel.\n ➡ Syntaxe: .reminder/remind/remindme <temps (d/h/m/s)> <message> """
embed = discord.Embed(color = 0xC41B1B) embed = discord.Embed(color = 0xC41B1B)
seconds = 0 seconds = 0
timestamp = datetime.utcnow()
if reminder: if reminder:
if time.lower().endswith("d"): try:
seconds += int(time[:-1]) * 60 * 60 * 24 if time.lower().endswith("d"):
counter = f"{seconds // 60 // 60 // 24} jours" seconds += int(time[:-1]) * 60 * 60 * 24
if time.lower().endswith("h"): _seconds = seconds // 60 // 60 // 24
seconds += int(time[:-1]) * 60 * 60 counter = f"{_seconds} jour{'s' if _seconds > 1 else ''}"
counter = f"{seconds // 60 // 60} heures" if time.lower().endswith("h"):
elif time.lower().endswith("m"): seconds += int(time[:-1]) * 60 * 60
seconds += int(time[:-1]) * 60 _seconds = seconds // 60 // 60
counter = f"{seconds // 60} minutes" counter = f"{_seconds} heure{'s' if _seconds > 1 else ''}"
elif time.lower().endswith("s"): elif time.lower().endswith("m"):
seconds += int(time[:-1]) seconds += int(time[:-1]) * 60
counter = f"{seconds} secondes" _seconds = seconds // 60
counter = f"{_seconds} minute{'s' if _seconds > 1 else ''}"
elif time.lower().endswith("s"):
seconds += int(time[:-1])
counter = f"{seconds} seconde{'s' if seconds > 1 else ''}"
except:
pass
if seconds == 0: if seconds == 0:
embed.add_field(name="Attention", value="Mauvais format pour l'heure, `d` pour jour, `h` pour heure, `m` pour minute, `s` pour seconde (ne fonctionne qu'avec une seule unité).") embed.add_field(name="Attention", value="Mauvais format pour le temps, `d` pour jour, `h` pour heure, `m` pour minute, `s` pour seconde (ne fonctionne qu'avec une seule unité).")
elif seconds < 300: # 5 * 60 elif seconds < 300: # 5 * 60
embed.add_field(name="Attention", value="Tu as spécifié une durée trop courte, la durée minimum étant de 5 minutes.") embed.add_field(name="Attention", value="Tu as spécifié une durée trop courte, la durée minimum étant de 5 minutes.")
elif seconds > 7776000: # 90 * 60 * 60 * 24 elif seconds > 7776000: # 90 * 60 * 60 * 24
@ -410,7 +420,7 @@ class Utils(commands.Cog):
else: else:
await ctx.send(f"Ok, je t'en parles dans {counter} !") await ctx.send(f"Ok, je t'en parles dans {counter} !")
await asyncio.sleep(seconds) await asyncio.sleep(seconds)
return await ctx.send(f"{ctx.author.mention}, voici ton message d'il y a {counter} :```{reminder}```") return await ctx.send(ctx.author.mention, embed = discord.Embed(description = self._cleanCodeStringWithMention(reminder), timestamp = timestamp, color = discord.Colour.random()).set_footer(text=f"Message d'il y a {counter}"))
else: else:
embed.add_field(name="Attention", value="Mauvaise syntaxe : reminder <temps> <message>") embed.add_field(name="Attention", value="Mauvaise syntaxe : reminder <temps> <message>")
await ctx.send(embed = embed) await ctx.send(embed = embed)