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

wow finalmente il codice di overwatch è quasi leggibile

This commit is contained in:
Steffo 2016-11-07 22:29:37 +01:00
parent 2ca9675f31
commit 6e85449799
2 changed files with 19 additions and 21 deletions

38
main.py
View file

@ -46,34 +46,32 @@ async def overwatch_status_change(timeout):
print("[Overwatch] Request returned an unhandled exception.") print("[Overwatch] Request returned an unhandled exception.")
else: else:
# Check for levelups # Check for levelups
if "level" not in db[player]["overwatch"] \ level = r["data"]["level"]
or r["data"]["level"] > db[player]["overwatch"]["level"]: try:
oldlevel = db[player]["overwatch"]["level"]
except KeyError:
oldlevel = 0
if level > oldlevel:
# Send the message # Send the message
loop.create_task(send_event(eventmsg=s.overwatch_level_up, loop.create_task(send_event(eventmsg=s.overwatch_level_up, player=player, level=level))
player=player,
level=r["data"]["level"]))
# Update database # Update database
db[player]["overwatch"]["level"] = r["data"]["level"] db[player]["overwatch"]["level"] = level
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 # Check for rank changes
if r["data"]["competitive"]["rank"] is not None: rank = r["data"]["competitive"]["rank"]
if "rank" not in db[player]["overwatch"] \ if rank is not None:
or int(r["data"]["competitive"]["rank"]) != db[player]["overwatch"]["rank"]: rank = int(rank)
if "rank" not in db[player]["overwatch"]: try:
db[player]["overwatch"]["rank"] = 0 oldrank = int(db[player]["overwatch"]["rank"])
except KeyError:
oldrank = 0
if rank != oldrank:
# Send the message # Send the message
loop.create_task(send_event(eventmsg=s.overwatch_rank_change, loop.create_task(send_event(eventmsg=s.overwatch_rank_change, player=player, change=oldrank-rank, rank=rank, medal=overwatch.rank_to_medal(rank)))
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 # Update database
db[player]["overwatch"]["rank"] = int(r["data"]["competitive"]["rank"]) db[player]["overwatch"]["rank"] = rank
f = open("db.json", "w") f = open("db.json", "w")
json.dump(db, f) json.dump(db, f)
f.close() f.close()

View file

@ -4,7 +4,7 @@
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!
overwatch_rank_change = "{player} è passato da {oldmedal} {oldrank} a **{medal} {rank}** su _Overwatch_!" overwatch_rank_change = "{player} è ora **{medal} {rank}** ({change}) su _Overwatch_!"
# Overwatch: Medal list # Overwatch: Medal list
overwatch_medal_list = ["Nulla", overwatch_medal_list = ["Nulla",