From 74e25c81a592d740ccd5ab63bc0f441185f14498 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 8 Nov 2016 15:06:01 +0100 Subject: [PATCH] Improved league of legends level up code --- main.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index da2fc9b0..0ae0ce57 100644 --- a/main.py +++ b/main.py @@ -151,17 +151,16 @@ async def league_level_up(timeout): print("[League] Request returned an unhandled exception.") else: # Check for level changes + level = r["summonerLevel"] try: - level = db[player]["league"]["level"] + old_level = db[player]["league"]["level"] except KeyError: - - if "level" not in db[player]["league"] or r["summonerLevel"] > : + old_level = 0 + if level > old_level: # Send the message - loop.create_task(send_event(eventmsg=s.league_level_up, - player=player, - level=r["summonerLevel"])) + loop.create_task(send_event(eventmsg=s.league_level_up, player=player, level=level)) # Update database - db[player]["league"]["level"] = r["summonerLevel"] + db[player]["league"]["level"] = level f = open("db.json", "w") json.dump(db, f) f.close()