mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
should work
This commit is contained in:
parent
25eb63d60b
commit
cf584f29d2
3 changed files with 51 additions and 4 deletions
23
main.py
23
main.py
|
@ -30,7 +30,7 @@ token = file.read()
|
||||||
file.close()
|
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_status_change(timeout):
|
||||||
while True:
|
while True:
|
||||||
if discord_is_ready:
|
if discord_is_ready:
|
||||||
print("[Overwatch] Starting check...")
|
print("[Overwatch] Starting check...")
|
||||||
|
@ -45,6 +45,7 @@ async def overwatch_level_up(timeout):
|
||||||
# If some other error occours, skip the player
|
# If some other error occours, skip the player
|
||||||
print("[Overwatch] Request returned an unhandled exception.")
|
print("[Overwatch] Request returned an unhandled exception.")
|
||||||
else:
|
else:
|
||||||
|
# Check for levelups
|
||||||
if "level" not in db[player]["overwatch"] \
|
if "level" not in db[player]["overwatch"] \
|
||||||
or r["data"]["level"] > db[player]["overwatch"]["level"]:
|
or r["data"]["level"] > db[player]["overwatch"]["level"]:
|
||||||
# Send the message
|
# Send the message
|
||||||
|
@ -56,6 +57,24 @@ async def overwatch_level_up(timeout):
|
||||||
f = open("db.json", "w")
|
f = open("db.json", "w")
|
||||||
json.dump(db, f)
|
json.dump(db, f)
|
||||||
f.close()
|
f.close()
|
||||||
|
# Check for rank changes
|
||||||
|
if r["data"]["competitive"]["rank"] is not None:
|
||||||
|
if "rank" not in db[player]["overwatch"] \
|
||||||
|
or int(r["data"]["competitive"]["rank"]) != db[player]["overwatch"]["rank"]:
|
||||||
|
# Send the message
|
||||||
|
loop.create_task(send_event(eventmsg=s.overwatch_rank_change,
|
||||||
|
player=player,
|
||||||
|
oldmedal=overwatch.rank_to_medal(
|
||||||
|
db[player]["overwatch"]["rank"]),
|
||||||
|
oldrank=db[player]["overwatch"]["rank"],
|
||||||
|
rank=int(r["data"]["competitive"]["rank"]),
|
||||||
|
medal=overwatch.rank_to_medal(
|
||||||
|
int(r["data"]["competitive"]["rank"]))))
|
||||||
|
# Update database
|
||||||
|
db[player]["overwatch"]["rank"] = r["data"]["competitive"]["rank"]
|
||||||
|
f = open("db.json", "w")
|
||||||
|
json.dump(db, f)
|
||||||
|
f.close()
|
||||||
finally:
|
finally:
|
||||||
asyncio.sleep(1)
|
asyncio.sleep(1)
|
||||||
print("[Overwatch] Check completed successfully.")
|
print("[Overwatch] Check completed successfully.")
|
||||||
|
@ -226,7 +245,7 @@ async def send_event(eventmsg: str, player: str, **kwargs):
|
||||||
loop.create_task(telegram.send_message(msg, -2141322))
|
loop.create_task(telegram.send_message(msg, -2141322))
|
||||||
|
|
||||||
|
|
||||||
loop.create_task(overwatch_level_up(600))
|
loop.create_task(overwatch_status_change(600))
|
||||||
print("[Overwatch] Added level up check to the queue.")
|
print("[Overwatch] Added level up check to the queue.")
|
||||||
|
|
||||||
loop.create_task(league_rank_change(900))
|
loop.create_task(league_rank_change(900))
|
||||||
|
|
16
overwatch.py
16
overwatch.py
|
@ -1,5 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import requests
|
import requests
|
||||||
|
import strings as s
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,3 +32,18 @@ async def get_player_data(platform: str, region: str, battletag: str, **kwargs):
|
||||||
else:
|
else:
|
||||||
raise Exception("Unhandled API response.")
|
raise Exception("Unhandled API response.")
|
||||||
|
|
||||||
|
|
||||||
|
# Convert rank to a medal
|
||||||
|
def rank_to_medal(rank):
|
||||||
|
if int(rank) < 1500:
|
||||||
|
return s.overwatch_medal_list[0]
|
||||||
|
elif int(rank) < 2000:
|
||||||
|
return s.overwatch_medal_list[1]
|
||||||
|
elif int(rank) < 2500:
|
||||||
|
return s.overwatch_medal_list[2]
|
||||||
|
elif int(rank) < 3000:
|
||||||
|
return s.overwatch_medal_list[3]
|
||||||
|
elif int(rank) < 3500:
|
||||||
|
return s.overwatch_medal_list[4]
|
||||||
|
elif int(rank) < 4000:
|
||||||
|
return s.overwatch_medal_list[5]
|
||||||
|
|
12
strings.py
12
strings.py
|
@ -3,6 +3,18 @@
|
||||||
# {level} = new level
|
# {level} = new level
|
||||||
overwatch_level_up = "{player} è salito al livello **{level}** su _Overwatch_!"
|
overwatch_level_up = "{player} è salito al livello **{level}** su _Overwatch_!"
|
||||||
|
|
||||||
|
# Overwatch: Rank change!
|
||||||
|
overwatch_rank_change = "{player} è passato da {oldmedal} {oldrank} a **{medal} {division}** su _Overwatch_!"
|
||||||
|
|
||||||
|
# Overwatch: Medal list
|
||||||
|
overwatch_medal_list = ["Bronzo",
|
||||||
|
"Argento",
|
||||||
|
"Oro",
|
||||||
|
"Platino",
|
||||||
|
"Diamante",
|
||||||
|
"Master",
|
||||||
|
"Grandmaster"]
|
||||||
|
|
||||||
# League of Legends: Rank up!
|
# League of Legends: Rank up!
|
||||||
league_rank_up = "{player} è passato da {oldtier} {olddivision} a **{tier} {division}** su _League of Legends_!"
|
league_rank_up = "{player} è passato da {oldtier} {olddivision} a **{tier} {division}** su _League of Legends_!"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue