workign on bot but python
This commit is contained in:
parent
e101c9718d
commit
e6b2b312ee
|
@ -4,12 +4,14 @@ ADD . /app/
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apt-get update -yq \
|
RUN apt-get update -yq \
|
||||||
&& apt-get install curl gnupg -yq \
|
&& apt-get install libffi-dev \
|
||||||
&& curl -sL https://deb.nodesource.com/setup_16.x | bash - \
|
&& apt-get install libnacl-dev \
|
||||||
&& apt-get install nodejs -yq \
|
&& apt-get install python3-dev \
|
||||||
&& apt-get clean -y \
|
&& apt-get install python3-pip \
|
||||||
&& npm i
|
&& 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
|
||||||
|
|
||||||
|
|
70
src/bot.py
70
src/bot.py
|
@ -1,41 +1,77 @@
|
||||||
import discord
|
import discord
|
||||||
import asyncio
|
import asyncio
|
||||||
import time
|
import time
|
||||||
import json
|
|
||||||
import requests
|
import requests
|
||||||
|
import colorama
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.all()
|
||||||
|
|
||||||
client = discord.Client(intents=intents)
|
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():
|
async def get_json():
|
||||||
url = 'https://preprod.42ctf.org/api/bot/discord?token=test'
|
url = 'https://preprod.42ctf.org/api/bot/discord?token=test'
|
||||||
|
resp = requests.get(url=url)
|
||||||
params = dict(
|
|
||||||
origin='Chicago,IL',
|
|
||||||
destination='Los+Angeles,CA',
|
|
||||||
waypoints='Joplin,MO|Oklahoma+City,OK',
|
|
||||||
sensor='false'
|
|
||||||
)
|
|
||||||
|
|
||||||
resp = requests.get(url=url, params=params)
|
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
return data
|
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:
|
while 1:
|
||||||
print("doing something here")
|
|
||||||
data = await get_json()
|
data = await get_json()
|
||||||
# print(data, type(data))
|
|
||||||
for key in data:
|
for key in data:
|
||||||
print(f'{key}, {data[key]}')
|
await put_role(guild, int(key), int(data[key]))
|
||||||
time.sleep(5000)
|
time.sleep(5000)
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
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 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')
|
client.run('OTQzNTA2NTgxMjkzNzc2OTQ3.GQ2l77.IyrlZv8-ESoXfL1MfSQw_ec3sXqOV1eh9PdNh4')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue