mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Improved timeouts
This commit is contained in:
parent
3de55d688b
commit
2b2a7051d4
1 changed files with 63 additions and 53 deletions
18
main.py
18
main.py
|
@ -8,6 +8,14 @@ import telegram
|
|||
|
||||
loop = asyncio.get_event_loop()
|
||||
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
|
||||
file = open("db.json")
|
||||
|
@ -22,8 +30,7 @@ file.close()
|
|||
# Every timeout seconds, update player status and check for levelups
|
||||
async def overwatch_level_up(timeout):
|
||||
while True:
|
||||
# Wait for the Discord client to be ready
|
||||
await d_client.wait_until_ready()
|
||||
if discord_is_ready:
|
||||
print("Checking for Overwatch updates.")
|
||||
# Update data for every player in list
|
||||
for player in db:
|
||||
|
@ -46,12 +53,13 @@ async def overwatch_level_up(timeout):
|
|||
print("Check for Overwatch completed.")
|
||||
# Wait for the timeout
|
||||
await asyncio.sleep(timeout)
|
||||
else:
|
||||
await asyncio.sleep(1)
|
||||
|
||||
# Every timeout seconds, update player league and check for rank changes
|
||||
async def league_rank_change(timeout):
|
||||
while True:
|
||||
# Wait for the Discord client to be ready
|
||||
await d_client.wait_until_ready()
|
||||
if discord_is_ready:
|
||||
print("Checking for League of Legends updates.")
|
||||
# Update data for every player in list
|
||||
for player in db:
|
||||
|
@ -86,6 +94,8 @@ async def league_rank_change(timeout):
|
|||
print("Check for League of Legends completed.")
|
||||
# Wait for the timeout
|
||||
await asyncio.sleep(timeout)
|
||||
else:
|
||||
await asyncio.sleep(1)
|
||||
|
||||
print("Added Overwatch to the queue.")
|
||||
loop.create_task(overwatch_level_up(900))
|
||||
|
|
Loading…
Reference in a new issue