2016-08-12 13:55:59 +00:00
|
|
|
import asyncio
|
|
|
|
import discord
|
2016-08-12 15:23:45 +00:00
|
|
|
import json
|
|
|
|
import overwatch
|
2016-08-12 15:48:35 +00:00
|
|
|
|
|
|
|
loop = asyncio.get_event_loop()
|
2016-08-12 15:23:45 +00:00
|
|
|
d_client = discord.Client()
|
|
|
|
|
|
|
|
# Get player database from the db.json file
|
|
|
|
file = open("db.json")
|
|
|
|
db = json.load(file)
|
|
|
|
file.close()
|
2016-08-12 13:55:59 +00:00
|
|
|
|
2016-08-12 14:01:05 +00:00
|
|
|
# Get the discord bot token from "discordtoken.txt"
|
|
|
|
f = open("discordtoken.txt", "r")
|
|
|
|
token = f.read()
|
|
|
|
f.close()
|
|
|
|
|
2016-08-12 15:23:45 +00:00
|
|
|
# List overwatch players
|
|
|
|
ow_players = list()
|
|
|
|
for player in db:
|
|
|
|
if db[player]["overwatch"] is not None:
|
|
|
|
ow_players.append(db[player]["overwatch"])
|
|
|
|
|
2016-08-12 17:21:43 +00:00
|
|
|
# Every 300 seconds, update player status and check for levelups
|
|
|
|
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)
|