changement sondage/avis try:except:
This commit is contained in:
parent
05d8c40cb7
commit
316e95760b
1 changed files with 23 additions and 22 deletions
|
@ -249,14 +249,14 @@ class Utils(commands.Cog):
|
||||||
value = str(user[0].created_at.astimezone(timezone(os.environ['TIMEZONE'])))[:-13].replace('-', '/').split()
|
value = str(user[0].created_at.astimezone(timezone(os.environ['TIMEZONE'])))[:-13].replace('-', '/').split()
|
||||||
embed.add_field(name = "Compte créé le", value = f"{value[0][8:]}/{value[0][5:-3]}/{value[0][:4]} à {value[1]}")
|
embed.add_field(name = "Compte créé le", value = f"{value[0][8:]}/{value[0][5:-3]}/{value[0][:4]} à {value[1]}")
|
||||||
|
|
||||||
embed.add_field(name = "Âge du compte", value = self._age_layout(self._get_age(user[0].created_at)))
|
embed.add_field(name = "Âge du compte", value = self._ageLayout(self._get_age(user[0].created_at)))
|
||||||
|
|
||||||
embed.add_field(name = "Mention", value = user[0].mention)
|
embed.add_field(name = "Mention", value = user[0].mention)
|
||||||
|
|
||||||
value = str(user[0].joined_at.astimezone(timezone(os.environ['TIMEZONE'])))[:-13].replace('-', '/').split()
|
value = str(user[0].joined_at.astimezone(timezone(os.environ['TIMEZONE'])))[:-13].replace('-', '/').split()
|
||||||
embed.add_field(name = "Serveur rejoint le", value = f"{value[0][8:]}/{value[0][5:-3]}/{value[0][:4]} à {value[1]}")
|
embed.add_field(name = "Serveur rejoint le", value = f"{value[0][8:]}/{value[0][5:-3]}/{value[0][:4]} à {value[1]}")
|
||||||
|
|
||||||
embed.add_field(name = "Est sur le serveur depuis", value = self._age_layout(self._get_age(user[0].joined_at)))
|
embed.add_field(name = "Est sur le serveur depuis", value = self._ageLayout(self._get_age(user[0].joined_at)))
|
||||||
await ctx.message.add_reaction(emoji = '✅')
|
await ctx.message.add_reaction(emoji = '✅')
|
||||||
return await ctx.send(embed = embed)
|
return await ctx.send(embed = embed)
|
||||||
await ctx.send("Tu mentionnes trop d'utilisateurs : `.whois [@Membre]`")
|
await ctx.send("Tu mentionnes trop d'utilisateurs : `.whois [@Membre]`")
|
||||||
|
@ -269,7 +269,7 @@ class Utils(commands.Cog):
|
||||||
minutes = (hours - int(hours)) * 60
|
minutes = (hours - int(hours)) * 60
|
||||||
seconds = (minutes - int(minutes)) * 60
|
seconds = (minutes - int(minutes)) * 60
|
||||||
return (int(years), int(months), int(days), int(hours), int(minutes), int(seconds))
|
return (int(years), int(months), int(days), int(hours), int(minutes), int(seconds))
|
||||||
def _age_layout(self, tuple):
|
def _ageLayout(self, tuple):
|
||||||
time = {}
|
time = {}
|
||||||
time[0], time[1], time[2], time[3], time[4], time[5] = "an", "mois", "jour", "heure", "minute", "seconde"
|
time[0], time[1], time[2], time[3], time[4], time[5] = "an", "mois", "jour", "heure", "minute", "seconde"
|
||||||
for i in range(len(tuple)):
|
for i in range(len(tuple)):
|
||||||
|
@ -292,6 +292,22 @@ class Utils(commands.Cog):
|
||||||
message = message + f", {tuple[i]} {time[i]}"
|
message = message + f", {tuple[i]} {time[i]}"
|
||||||
return message[2:]
|
return message[2:]
|
||||||
|
|
||||||
|
def _userOrNick(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}"
|
||||||
|
|
||||||
|
def _cleanUser(self, ctx, stringMessage, stringID, option = 0):
|
||||||
|
associatedId = self._userOrNick(ctx.author.guild.get_member(int(stringID)))
|
||||||
|
try:
|
||||||
|
stringMessage = stringMessage.replace(stringID, associatedId)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return stringMessage
|
||||||
|
|
||||||
@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>" """
|
||||||
|
@ -299,11 +315,7 @@ class Utils(commands.Cog):
|
||||||
if len(args) > 2:
|
if len(args) > 2:
|
||||||
question = args[0].replace("<@!", "").replace(">", "").replace("<@", "")
|
question = args[0].replace("<@!", "").replace(">", "").replace("<@", "")
|
||||||
for i in re.findall(r'\d+', question):
|
for i in re.findall(r'\d+', question):
|
||||||
ii = self.user_or_nick(ctx.author.guild.get_member(int(i)))
|
question = self._cleanUser(ctx, question, i)
|
||||||
try:
|
|
||||||
question = question.replace(i, ii)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
propositions = args[1:]
|
propositions = args[1:]
|
||||||
if len(propositions) <= 20:
|
if len(propositions) <= 20:
|
||||||
message = ""
|
message = ""
|
||||||
|
@ -327,7 +339,7 @@ class Utils(commands.Cog):
|
||||||
shuffle(emojis_chosen)
|
shuffle(emojis_chosen)
|
||||||
for i in range(len(args[1:])):
|
for i in range(len(args[1:])):
|
||||||
message += f"{emojis_chosen[i]} -> {propositions[i]}\n"
|
message += f"{emojis_chosen[i]} -> {propositions[i]}\n"
|
||||||
embed = discord.Embed(title = question, description = message,color = discord.Colour.random()).set_footer(text = self.user_or_nick(ctx.author), icon_url = ctx.author.avatar_url)
|
embed = discord.Embed(title = question, description = message,color = discord.Colour.random()).set_footer(text = self._userOrNick(ctx.author), icon_url = ctx.author.avatar_url)
|
||||||
sondage = await ctx.send(embed = embed)
|
sondage = await ctx.send(embed = embed)
|
||||||
for i in range(len(args[1:])):
|
for i in range(len(args[1:])):
|
||||||
await sondage.add_reaction(emoji = emojis_chosen[i])
|
await sondage.add_reaction(emoji = emojis_chosen[i])
|
||||||
|
@ -336,13 +348,6 @@ class Utils(commands.Cog):
|
||||||
return await ctx.send(f"Désolé, mais tu as mis trop de possibilités (maximum : 20)")
|
return await ctx.send(f"Désolé, mais tu as mis trop de possibilités (maximum : 20)")
|
||||||
else:
|
else:
|
||||||
return await ctx.send(f'Désolé, mais il manque des arguments : `.sondage "<Question>" "<Proposition1>" "<Proposition...>" "<Proposition20>"`')
|
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 == 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'])
|
@commands.command(name='avis', aliases=['vote'])
|
||||||
async def _avis(self, ctx, *args):
|
async def _avis(self, ctx, *args):
|
||||||
|
@ -356,13 +361,9 @@ class Utils(commands.Cog):
|
||||||
else:
|
else:
|
||||||
titre = args[0].replace("<@!", "").replace(">", "").replace("<@", "")
|
titre = args[0].replace("<@!", "").replace(">", "").replace("<@", "")
|
||||||
for findedId in re.findall(r'\d+', titre):
|
for findedId in re.findall(r'\d+', titre):
|
||||||
associatedId = self.user_or_nick(ctx.author.guild.get_member(int(findedId)))
|
titre = self._cleanUser(ctx, titre, findedId)
|
||||||
try:
|
|
||||||
titre = titre.replace(findedId, associatedId)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
args = args[1:]
|
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)
|
embed = discord.Embed(title = titre, description = f"```{args[0]}```", 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:
|
||||||
|
|
Reference in a new issue