From 4f5f868ed10f7f0e4d6bd572b792298b407307d3 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 8 Nov 2016 15:20:46 +0100 Subject: [PATCH] Improved Brawlhalla rank change code --- main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 0ae0ce57..40b221ab 100644 --- a/main.py +++ b/main.py @@ -208,11 +208,14 @@ async def brawlhalla_update_mmr(timeout): continue # Get the current mmr mmr = int(list(row.children)[7].string) + try: + old_mmr = db[player]["brawlhalla"]["mmr"] + except KeyError: + old_mmr = 0 # Compare the mmr with the value saved in the database - if mmr != db[player]["brawlhalla"]["mmr"]: + if mmr != old_mmr: # Send a message - loop.create_task(send_event(s.brawlhalla_new_mmr, player, mmr=mmr, - oldmmr=db[player]["brawlhalla"]["mmr"])) + loop.create_task(send_event(s.brawlhalla_new_mmr, player, mmr=mmr, oldmmr=old_mmr)) # Update database db[player]["brawlhalla"]["mmr"] = mmr f = open("db.json", "w")