From fcdd2a9685421c054864efb93cee42675a5e0ba7 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 9 Jan 2017 08:37:09 +0100 Subject: [PATCH] Show the actual medal --- main.py | 26 ++++++++++++++------------ overwatch.py | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 149412ec..8e89ccf5 100644 --- a/main.py +++ b/main.py @@ -3,12 +3,12 @@ import discord import json import opendota -#import overwatch -#import league +import overwatch +import league import strings as s import telegram import bs4 -#import brawlhalla +import brawlhalla loop = asyncio.get_event_loop() d_client = discord.Client() @@ -71,7 +71,9 @@ async def overwatch_status_change(timeout): oldrank = 0 if rank != oldrank: # Send the message - loop.create_task(send_event(eventmsg=s.overwatch_rank_change, player=player, change=rank-oldrank, rank=rank, medal=overwatch.rank_to_medal(rank))) + loop.create_task(send_event(eventmsg=s.overwatch_rank_change, + player=player, change=rank-oldrank, + rank=rank, medal=overwatch.url_to_medal(r["data"]["competitive"]["rank_img"]))) # Update database db[player]["overwatch"]["rank"] = rank f = open("db.json", "w") @@ -307,17 +309,17 @@ async def send_event(eventmsg: str, player: str, **kwargs): # Send the message loop.create_task(telegram.send_message(msg, -2141322)) -#loop.create_task(overwatch_status_change(600)) -#print("[Overwatch] Added level up check to the queue.") +loop.create_task(overwatch_status_change(600)) +print("[Overwatch] Added level up check to the queue.") -#loop.create_task(league_rank_change(900)) -#print("[League] Added rank change check to the queue.") +loop.create_task(league_rank_change(900)) +print("[League] Added rank change check to the queue.") -#loop.create_task(league_level_up(900)) -#print("[League] Added level change check to the queue.") +loop.create_task(league_level_up(900)) +print("[League] Added level change check to the queue.") -#loop.create_task(brawlhalla_update_mmr(7200)) -#print("[Brawlhalla] Added mmr change check to the queue.") +loop.create_task(brawlhalla_update_mmr(7200)) +print("[Brawlhalla] Added mmr change check to the queue.") loop.create_task(opendota_last_match(600)) print("[OpenDota] Added last match check to the queue.") diff --git a/overwatch.py b/overwatch.py index 4de8e41d..6519ab3f 100644 --- a/overwatch.py +++ b/overwatch.py @@ -49,3 +49,26 @@ def rank_to_medal(rank): return s.overwatch_medal_list[5] elif int(rank) < 4000: return s.overwatch_medal_list[6] + else: + # TODO: what + raise Exception("Mi sfugge qualcosa.") + + +# Convert an url to a medal +def url_to_medal(rank: str): + if rank == "https://blzgdapipro-a.akamaihd.net/game/rank-icons/season-2/rank-1.png": + return s.overwatch_medal_list[0] + elif rank == "https://blzgdapipro-a.akamaihd.net/game/rank-icons/season-2/rank-2.png": + return s.overwatch_medal_list[1] + elif rank == "https://blzgdapipro-a.akamaihd.net/game/rank-icons/season-2/rank-3.png": + return s.overwatch_medal_list[2] + elif rank == "https://blzgdapipro-a.akamaihd.net/game/rank-icons/season-2/rank-4.png": + return s.overwatch_medal_list[3] + elif rank == "https://blzgdapipro-a.akamaihd.net/game/rank-icons/season-2/rank-5.png": + return s.overwatch_medal_list[4] + elif rank == "https://blzgdapipro-a.akamaihd.net/game/rank-icons/season-2/rank-6.png": + return s.overwatch_medal_list[5] + elif rank == "https://blzgdapipro-a.akamaihd.net/game/rank-icons/season-2/rank-7.png": + return s.overwatch_medal_list[6] + else: + raise NotFoundException("The medal does not exist.") \ No newline at end of file