From 355bdeacf0439d18509cb3fc5e61ce13860b04fd Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 8 Nov 2016 15:03:46 +0100 Subject: [PATCH] Improved league of legends rank change code --- main.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 9477e591..da2fc9b0 100644 --- a/main.py +++ b/main.py @@ -105,18 +105,19 @@ async def league_rank_change(timeout): else: # Convert tier into a number tier_number = league.ranklist.index(r["tier"]) - roman_number = league.roman.index(r["entries"][0]["division"]) + roman_number = league.roman.index(r["entries"][0]["division"]) # Potrebbe non funzionare + try: + old_tier_number = db[player]["league"]["tier"] + old_roman_number = db[player]["league"]["division"] + except KeyError: + # Bronze VI? + old_tier_number = 0 + old_roman_number = 5 # Check for tier changes - if tier_number != db[player]["league"]["tier"] \ - or roman_number != db[player]["league"]["division"]: + if tier_number != old_tier_number or roman_number != old_roman_number: # Send the message - loop.create_task(send_event(eventmsg=s.league_rank_up, - player=player, - tier=s.league_tier_list[tier_number], - division=r["entries"][0]["division"], - oldtier=s.league_tier_list[db[player]["league"]["tier"]], - olddivision= - s.league_roman_list[db[player]["league"]["division"]])) + loop.create_task(send_event(eventmsg=s.league_rank_up, player=player, tier=s.league_tier_list[tier_number], division=s.league_roman_list[roman_number], + oldtier=s.league_tier_list[old_tier_number], olddivision=s.league_roman_list[old_roman_number])) # Update database db[player]["league"]["tier"] = tier_number db[player]["league"]["division"] = roman_number @@ -150,7 +151,11 @@ async def league_level_up(timeout): print("[League] Request returned an unhandled exception.") else: # Check for level changes - if "level" not in db[player]["league"] or r["summonerLevel"] > db[player]["league"]["level"]: + try: + level = db[player]["league"]["level"] + except KeyError: + + if "level" not in db[player]["league"] or r["summonerLevel"] > : # Send the message loop.create_task(send_event(eventmsg=s.league_level_up, player=player,