1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Improved timeouts

This commit is contained in:
Steffo 2016-08-13 15:36:08 +02:00
parent 3de55d688b
commit 2b2a7051d4

18
main.py
View file

@ -8,6 +8,14 @@ import telegram
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
d_client = discord.Client() d_client = discord.Client()
discord_is_ready = False
# When Discord is ready, set discord_is_ready to True
@d_client.event
async def on_ready():
global discord_is_ready
discord_is_ready = True
# Get player database from the db.json file # Get player database from the db.json file
file = open("db.json") file = open("db.json")
@ -22,8 +30,7 @@ file.close()
# Every timeout seconds, update player status and check for levelups # Every timeout seconds, update player status and check for levelups
async def overwatch_level_up(timeout): async def overwatch_level_up(timeout):
while True: while True:
# Wait for the Discord client to be ready if discord_is_ready:
await d_client.wait_until_ready()
print("Checking for Overwatch updates.") print("Checking for Overwatch updates.")
# Update data for every player in list # Update data for every player in list
for player in db: for player in db:
@ -46,12 +53,13 @@ async def overwatch_level_up(timeout):
print("Check for Overwatch completed.") print("Check for Overwatch completed.")
# Wait for the timeout # Wait for the timeout
await asyncio.sleep(timeout) await asyncio.sleep(timeout)
else:
await asyncio.sleep(1)
# Every timeout seconds, update player league and check for rank changes # Every timeout seconds, update player league and check for rank changes
async def league_rank_change(timeout): async def league_rank_change(timeout):
while True: while True:
# Wait for the Discord client to be ready if discord_is_ready:
await d_client.wait_until_ready()
print("Checking for League of Legends updates.") print("Checking for League of Legends updates.")
# Update data for every player in list # Update data for every player in list
for player in db: for player in db:
@ -86,6 +94,8 @@ async def league_rank_change(timeout):
print("Check for League of Legends completed.") print("Check for League of Legends completed.")
# Wait for the timeout # Wait for the timeout
await asyncio.sleep(timeout) await asyncio.sleep(timeout)
else:
await asyncio.sleep(1)
print("Added Overwatch to the queue.") print("Added Overwatch to the queue.")
loop.create_task(overwatch_level_up(900)) loop.create_task(overwatch_level_up(900))