Ajout fonctionnalité sondage
This commit is contained in:
parent
518c43e15e
commit
d963f743e6
1 changed files with 53 additions and 2 deletions
|
@ -1,9 +1,10 @@
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from random import randint, choice
|
from random import randint, choice, shuffle
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pytz import timezone
|
from pytz import timezone
|
||||||
|
import re
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Commands(bot))
|
bot.add_cog(Commands(bot))
|
||||||
|
@ -246,4 +247,54 @@ class Commands(commands.Cog):
|
||||||
if isinstance(error, commands.CheckFailure):
|
if isinstance(error, commands.CheckFailure):
|
||||||
await ctx.send("Tu n'as pas la permission de faire cette commande, demande à un professeur.")
|
await ctx.send("Tu n'as pas la permission de faire cette commande, demande à un professeur.")
|
||||||
else:
|
else:
|
||||||
await ctx.send("Une erreur est survenue, syntaxe: `.appel [ID salon vocal]`.")
|
await ctx.send("Une erreur est survenue, syntaxe: `.appel [ID salon vocal]`.")
|
||||||
|
|
||||||
|
@commands.command(name='sondage')
|
||||||
|
async def _sondage(self, ctx, *args):
|
||||||
|
"""Fais un sondage.\n ➡ Syntaxe: .sondage "<Question>" "<Proposition1>" "<Proposition...>" "<Proposition20>" """
|
||||||
|
args = list(args)
|
||||||
|
if len(args) > 2:
|
||||||
|
question = args[0].replace("<@!", "").replace(">", "").replace("<@", "")
|
||||||
|
for i in re.findall(r'\d+', question):
|
||||||
|
ii = self.user_or_nick(ctx.author.guild.get_member(int(i)))
|
||||||
|
try:
|
||||||
|
question = question.replace(i, ii)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
propositions = args[1:]
|
||||||
|
if len(propositions) <= 20:
|
||||||
|
message = ""
|
||||||
|
emojis = {}
|
||||||
|
emojis[0] = ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣', '🔟']
|
||||||
|
emojis[1] = [
|
||||||
|
'🟤', '🔴', '🟠', '🟡', '🟢', '🔵', '🟣', '🔘', '❤', '💜',
|
||||||
|
'🟫', '🟥', '🟧', '🟨', '🟩', '🟦', '🟪', '🔳', '🧡', '💙'
|
||||||
|
]
|
||||||
|
mixable = True
|
||||||
|
if len(propositions) <= 10:
|
||||||
|
emojis_chosen = emojis[randint(0, len(emojis) - 1)]
|
||||||
|
emojis_chosen = emojis_chosen[:10]
|
||||||
|
if len(propositions) <= 8:
|
||||||
|
emojis_chosen = emojis_chosen[:8]
|
||||||
|
else:
|
||||||
|
emojis_chosen = emojis[randint(1, len(emojis) - 1)]
|
||||||
|
if emojis[0][0] in emojis_chosen: # rajouter ici les listes qui ne doivent pas être mélanger
|
||||||
|
mixable = False
|
||||||
|
if mixable:
|
||||||
|
shuffle(emojis_chosen)
|
||||||
|
for i in range(len(args[1:])):
|
||||||
|
message += f"{emojis_chosen[i]} -> {propositions[i]}\n"
|
||||||
|
embed = discord.Embed(title = question, description = message,color = randint(0, 0xFFFFFF)).set_footer(text = self.user_or_nick(ctx.author), icon_url = ctx.author.avatar_url)
|
||||||
|
sondage = await ctx.send(embed = embed)
|
||||||
|
for i in range(len(args[1:])):
|
||||||
|
await sondage.add_reaction(emoji = emojis_chosen[i])
|
||||||
|
return await ctx.message.add_reaction(emoji = '✅')
|
||||||
|
else:
|
||||||
|
return await ctx.send(f"Désolé, mais tu as mis trop de possibilités (maximum : 20)")
|
||||||
|
else:
|
||||||
|
return await ctx.send(f'Désolé, mais il manque des arguments : `.sondage "<Question>" "<Proposition1>" "<Proposition...>" "<Proposition20>"`')
|
||||||
|
def user_or_nick(self, user):
|
||||||
|
if user.nick:
|
||||||
|
return f"{user.nick} ({user.name}#{user.discriminator})"
|
||||||
|
else:
|
||||||
|
return f"{user.name}#{user.discriminator}"
|
Reference in a new issue