-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
75 lines (65 loc) · 3.27 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from src.view.rank import get_user_image, get_user_rank, get_user_profile, get_user_last
from src.view.token_config_bot import token
from src.model.database import Database
from src.controller.bot_controller import BotController
import requests
import discord
from discord.ext import commands
intents = discord.Intents.all()
client = commands.Bot(command_prefix = '!', intents=intents)
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
bot_controller = BotController()
@client.command()
async def rank(ctx, username: str):
r = requests.get(f'https://api.www.root-me.org/{username}', headers=headers)
if r.status_code == 200:
embed = discord.Embed(title=username, description="Voici le classement de " + username, color=0x00ff00)
image_url = get_user_image(username)
embed.set_thumbnail(url=image_url)
points, position, top, challs, comprom = get_user_rank(username)
if points == -1:
await ctx.send('Erreur lors de la récupération des données')
return
embed.add_field(name="Points", value=points, inline=False)
embed.add_field(name="Position", value=position, inline=False)
embed.add_field(name="Top", value=top, inline=False)
embed.add_field(name="Challenges", value=challs, inline=False)
embed.add_field(name="Compromissions", value=comprom, inline=False)
# Mise à jour des points et ajout de l'utilisateur si nécessaire
bot_controller.add_new_user(username)
bot_controller.update_user_points(username, points)
await ctx.send(embed=embed)
else:
await ctx.send('Erreur lors de la récupération des données')
@client.command()
async def profile(ctx, username: str):
r = requests.get(f'https://api.www.root-me.org/{username}', headers=headers)
if r.status_code == 200:
embed = discord.Embed(title=username, description="Voici le profil de " + username, color=0x00ff00)
image_url = get_user_image(username)
embed.set_thumbnail(url=image_url)
scores = get_user_profile(username)
embed.add_field(name="Score", value=scores, inline=False)
await ctx.send(embed=embed)
else:
await ctx.send('Erreur lors de la récupération des données')
@client.command()
async def last(ctx, username: str):
r = requests.get(f'https://api.www.root-me.org/{username}', headers=headers)
if r.status_code == 200:
embed = discord.Embed(title=username, description="Voici les dernières résolutions de " + username, color=0x00ff00)
image_url = get_user_image(username)
embed.set_thumbnail(url=image_url)
last = get_user_last(username)
embed.add_field(name="Challenges", value=last, inline=False)
await ctx.send(embed=embed)
else:
await ctx.send('Erreur lors de la récupération des données')
@client.command()
async def embed(ctx):
embed = discord.Embed(title="Titre", description="Description", color=0x00ff00)
embed.add_field(name="Champ 1", value="Valeur 1", inline=False)
embed.add_field(name="Champ 2", value="Valeur 2", inline=False)
embed.set_footer(text="Un truc de ce genre")
await ctx.send(embed=embed)
client.run(token)