Ajout de la commande 'whois'

This commit is contained in:
Mylloon 2020-11-10 19:04:01 +01:00
parent 020c0fab44
commit 50fa74cba8

View file

@ -2,6 +2,8 @@ import discord
from discord.ext import commands from discord.ext import commands
from random import randint, choice from random import randint, choice
import time import time
from datetime import datetime
from pytz import timezone
def setup(bot): def setup(bot):
bot.add_cog(Commands(bot)) bot.add_cog(Commands(bot))
@ -147,4 +149,62 @@ class Commands(commands.Cog):
embed.add_field(name='Channels', value=f'{text} textuelles\n{voice} vocales') embed.add_field(name='Channels', value=f'{text} textuelles\n{voice} vocales')
# ca peut être utile de connaitre quel version le bot utilise sans devoir se connecter a distance au serveur qui fait tourner le bot # ca peut être utile de connaitre quel version le bot utilise sans devoir se connecter a distance au serveur qui fait tourner le bot
embed.set_footer(text=f'Basé sur discord.py {discord.__version__}') embed.set_footer(text=f'Basé sur discord.py {discord.__version__}')
await ctx.send(embed=embed) await ctx.send(embed=embed)
@commands.command()
async def whois(self, ctx, *user: discord.Member):
"""Affiche les infos sur l'utilisateur.\n ➡ Syntaxe: .whois [user]"""
if len(user) <= 1:
if user == ():
user = [ctx.author]
nom = f"{user[0].name}#{user[0].discriminator}"
if user[0].nick:
nom = f"{user[0].nick} ({user[0].name}#{user[0].discriminator})"
embed = discord.Embed(color = randint(0, 0xFFFFFF)).set_author(name = nom, icon_url = user[0].avatar_url)
embed.add_field(name = "ID", value = user[0].id)
value = str(user[0].created_at.astimezone(timezone('Europe/Paris')))[:-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 = "Âge du compte", value = self.age_layout(self.get_age(user[0].created_at)))
embed.add_field(name = "Mention", value = user[0].mention)
value = str(user[0].joined_at.astimezone(timezone('Europe/Paris')))[:-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 = "Est sur le serveur depuis", value = self.age_layout(self.get_age(user[0].joined_at)))
return await ctx.send(embed = embed)
await ctx.send("Tu mentionnes trop d'utilisateurs : `.whois [@Membre]`")
def get_age(self, date):
joursRestants = datetime.now() - date
years = joursRestants.total_seconds() / (365.242 * 24 * 3600)
months = (years - int(years)) * 12
days = (months - int(months)) * (365.242 / 12)
hours = (days - int(days)) * 24
minutes = (hours - int(hours)) * 60
seconds = (minutes - int(minutes)) * 60
return (int(years), int(months), int(days), int(hours), int(minutes), int(seconds))
def age_layout(self, tuple):
time = {}
time[0], time[1], time[2], time[3], time[4], time[5] = "an", "mois", "jour", "heure", "minute", "seconde"
for i in range(len(tuple)):
if tuple[i] > 1 and i != 1:
time[i] = time[i] + "s"
message = ""
if tuple[5] > 0: # pour les secondes
affichage = [5] # on affiche que : seconde
if tuple[4] > 0:
affichage = [4, 5] # on affiche : minute + seconde
if tuple[3] > 0:
affichage = [3, 4, 5] # on affiche : heure + minute + seconde
if tuple[2] > 0:
affichage = [2, 3, 4] # on affiche : jour + heure + minute
if tuple[1] > 0:
affichage = [1, 2, 3] # on affiche : mois + jour + heure
if tuple[0] > 0:
affichage = [0, 1, 3] # on affiche : an + mois + heure
for i in affichage:
message = message + f", {tuple[i]} {time[i]}"
return message[2:]