workign on bot but python

This commit is contained in:
Camille CAMBIUM 2022-11-19 06:13:47 +01:00
parent e101c9718d
commit e6b2b312ee
2 changed files with 61 additions and 23 deletions

View File

@ -4,12 +4,14 @@ ADD . /app/
WORKDIR /app
RUN apt-get update -yq \
&& apt-get install curl gnupg -yq \
&& curl -sL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get install nodejs -yq \
&& apt-get clean -y \
&& npm i
&& apt-get install libffi-dev \
&& apt-get install libnacl-dev \
&& apt-get install python3-dev \
&& apt-get install python3-pip \
&& python3 -m pip install -U discord.py \
&& python3 -m pip install -U asyncio \
&& python3 -m pip install -U requests \
CMD node bot.js
CMD python3 bot.py

View File

@ -1,41 +1,77 @@
import discord
import asyncio
import time
import json
import requests
import colorama
intents = discord.Intents.default()
intents = discord.Intents.all()
client = discord.Client(intents=intents)
def logger(type, message):
color = colorama.Fore.WHITE
if type == 'info':
color = colorama.Fore.GREEN
if type == 'warn':
color = colorama.Fore.YELLOW
if type == 'error':
color = colorama.Fore.RED
print(f"{colorama.Fore.BLUE}[{color}{type.upper()}{colorama.Fore.BLUE}]{colorama.Fore.WHITE}{message}")
async def get_json():
url = 'https://preprod.42ctf.org/api/bot/discord?token=test'
params = dict(
origin='Chicago,IL',
destination='Los+Angeles,CA',
waypoints='Joplin,MO|Oklahoma+City,OK',
sensor='false'
)
resp = requests.get(url=url, params=params)
resp = requests.get(url=url)
data = resp.json()
return data
async def routine():
async def put_role(guild, userid, rank):
logger("info", f"userid {userid} has rank {rank}")
member = guild.get_member(user_id=userid)
if not member:
logger("warn", f"member with userid {userid} not found")
return
if rank < 1: # if rank is not in the top 50 or invalid
logger("error", f"rank {rank} is invalid")
return
if rank > 50:
await member.remove_roles(guild.get_role(role_id=943545946309029958))
await member.remove_roles(guild.get_role(role_id=943545892030517278))
await member.remove_roles(guild.get_role(role_id=943545814758854686))
return
if rank > 10: # if rank is not in the top 10
role = guild.get_role(role_id=943545946309029958)
await member.remove_roles(guild.get_role(role_id=943545892030517278))
await member.remove_roles(guild.get_role(role_id=943545814758854686))
await member.add_roles(role)
return
if rank > 1: # if rank is not top 1
role = guild.get_role(role_id=943545892030517278)
await member.remove_roles(guild.get_role(role_id=943545814758854686))
await member.remove_roles(guild.get_role(role_id=943545946309029958))
await member.add_roles(role)
return
if rank == 1: # if rank is top 1
role = guild.get_role(role_id=943545814758854686)
await member.remove_roles(guild.get_role(role_id=943545946309029958))
await member.remove_roles(guild.get_role(role_id=943545892030517278))
await member.add_roles(role)
return
async def routine(guild):
logger("info", "routine started")
while 1:
print("doing something here")
data = await get_json()
# print(data, type(data))
for key in data:
print(f'{key}, {data[key]}')
await put_role(guild, int(key), int(data[key]))
time.sleep(5000)
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
logger("info", "logged as " + client.user.name)
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.playing, name='etre refait en python'))
await routine()
guild = client.get_guild(943459216901955604)
await routine(guild)
client.run('OTQzNTA2NTgxMjkzNzc2OTQ3.GQ2l77.IyrlZv8-ESoXfL1MfSQw_ec3sXqOV1eh9PdNh4')