mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-24 03:54:20 +00:00
Moved even more stuff around
This commit is contained in:
parent
17a2250290
commit
8fea42680e
2 changed files with 15 additions and 10 deletions
23
main.py
23
main.py
|
@ -16,18 +16,23 @@ f = open("discordtoken.txt", "r")
|
||||||
token = f.read()
|
token = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Start discord bot client but ignore events
|
|
||||||
async def discord_connect():
|
|
||||||
await d_client.login(token)
|
|
||||||
print("Discord login was successful!")
|
|
||||||
d_client.connect() # Something's not right here...
|
|
||||||
print("Discord connection was successful!")
|
|
||||||
|
|
||||||
# List overwatch players
|
# List overwatch players
|
||||||
ow_players = list()
|
ow_players = list()
|
||||||
for player in db:
|
for player in db:
|
||||||
if db[player]["overwatch"] is not None:
|
if db[player]["overwatch"] is not None:
|
||||||
ow_players.append(db[player]["overwatch"])
|
ow_players.append(db[player]["overwatch"])
|
||||||
|
|
||||||
# Connect to Discord
|
# Every 300 seconds, update player status and check for levelups
|
||||||
loop.run_until_complete(discord_connect())
|
async def overwatch_level_up(timeout):
|
||||||
|
while True:
|
||||||
|
# Update data for every player in list
|
||||||
|
for ow_player in ow_players:
|
||||||
|
r = await overwatch.get_player_data(**ow_player)
|
||||||
|
if r["data"]["level"] > ow_player["level"]:
|
||||||
|
await d_client.send_message(d_client.get_channel("213655027842154508"), "Level up!")
|
||||||
|
ow_player["level"] = r["data"]["level"]
|
||||||
|
# Wait for the timeout
|
||||||
|
await asyncio.sleep(timeout)
|
||||||
|
|
||||||
|
loop.create_task(overwatch_level_up(30))
|
||||||
|
d_client.run(token)
|
|
@ -3,7 +3,7 @@ import requests
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
# Get player data
|
# Get player data
|
||||||
async def get_player_data(platform: str, region: str, battletag: str):
|
async def get_player_data(platform: str, region: str, battletag: str, **kwargs):
|
||||||
# Unofficial API requires - for discriminator numbers
|
# Unofficial API requires - for discriminator numbers
|
||||||
battletag = battletag.replace("#", "-")
|
battletag = battletag.replace("#", "-")
|
||||||
# GET the json unofficial API response
|
# GET the json unofficial API response
|
||||||
|
|
Loading…
Reference in a new issue