From f62a4b37a666ba23cddad6ae57c3ddc873452d1b Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 7 May 2021 16:38:16 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20commande=20avis=20+=20fix=20probleme=20?= =?UTF-8?q?r=C3=A9cup=C3=A9ration=20ID=20lors=20d'un=20copi=C3=A9=20coll?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cogs/utils.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/cogs/utils.py b/src/cogs/utils.py index 33c392e..0bc7e09 100644 --- a/src/cogs/utils.py +++ b/src/cogs/utils.py @@ -337,7 +337,34 @@ class Utils(commands.Cog): else: return await ctx.send(f'Désolé, mais il manque des arguments : `.sondage "" "" "" ""`') def user_or_nick(self, user): + if user == None: + return "Utilisateur inconnu" # Mauvais copié/collé -> changement d'ID if user.nick: return f"{user.nick} ({user.name}#{user.discriminator})" else: return f"{user.name}#{user.discriminator}" + + @commands.command(name='avis', aliases=['vote']) + async def _avis(self, ctx, *args): + """Demande un avis.⁢⁢⁢⁢⁢\n ➡ Syntaxe: .avis "[Titre]" "" """ + args = list(args) + if len(args) > 2 or len(args) == 0: + return await ctx.send("Désolé, la syntaxe est mauvaise.") + else: + if len(args) == 1: + titre = "Nouveau vote" + else: + titre = args[0].replace("<@!", "").replace(">", "").replace("<@", "") + for findedId in re.findall(r'\d+', titre): + associatedId = self.user_or_nick(ctx.author.guild.get_member(int(findedId))) + try: + titre = titre.replace(findedId, associatedId) + except: + pass + args = args[1:] + embed = discord.Embed(title = titre, description = f"```{args[0]}```", color = discord.Colour.random()).set_footer(text = self.user_or_nick(ctx.author), icon_url = ctx.author.avatar_url) + message = await ctx.send(embed = embed) + reactions = ['✅', '🤷', '❌'] + for i in reactions: + await message.add_reaction(emoji = i) + return await ctx.message.delete()