diff --git a/league_rpc_linux/__main__.py b/league_rpc_linux/__main__.py index 8362e38..f41d9ed 100644 --- a/league_rpc_linux/__main__.py +++ b/league_rpc_linux/__main__.py @@ -10,6 +10,7 @@ from league_rpc_linux.colors import Colors from league_rpc_linux.const import ( ALL_GAME_DATA_URL, + CHAMPION_NAME_CONVERT_MAP, DEFAULT_CLIENT_ID, DISCORD_PROCESS_NAMES, LEAGUE_OF_LEGENDS_LOGO, @@ -108,7 +109,11 @@ def main(cli_args: argparse.Namespace): while player_state() == "InGame": rpc.update( # type:ignore large_image=skin_asset, - large_text=skin_name if skin_name else champ_name, + large_text=skin_name + if skin_name + else CHAMPION_NAME_CONVERT_MAP.get( + champ_name, champ_name + ), details=gamemode, state=f"In Game {f'· {get_kda()} · lvl: {get_level()} · gold: {get_gold()}' if not cli_args.no_stats else ''}", small_image=LEAGUE_OF_LEGENDS_LOGO, @@ -131,7 +136,11 @@ def main(cli_args: argparse.Namespace): break rpc.update( # type:ignore large_image=skin_asset, - large_text=skin_name if skin_name else champ_name, + large_text=skin_name + if skin_name + else CHAMPION_NAME_CONVERT_MAP.get( + champ_name, champ_name + ), details=gamemode, state=f"In Game {f'· {get_kda()} · {get_creepscore()}' if not cli_args.no_stats else ''}", small_image=LEAGUE_OF_LEGENDS_LOGO, diff --git a/league_rpc_linux/champion.py b/league_rpc_linux/champion.py index 0016477..845030d 100644 --- a/league_rpc_linux/champion.py +++ b/league_rpc_linux/champion.py @@ -9,15 +9,27 @@ ALL_GAME_DATA_URL, BASE_SKIN_URL, CHAMPION_NAME_CONVERT_MAP, + DDRAGON_CHAMPION_DATA, GAME_MODE_CONVERT_MAP, ) from league_rpc_linux.kda import get_gold, get_level +from league_rpc_linux.latest_version import get_latest_version from league_rpc_linux.polling import wait_until_exists from league_rpc_linux.username import get_summoner_name urllib3.disable_warnings() +def get_specific_champion_data(name: str) -> dict[str, Any]: + response = requests.get( + url=DDRAGON_CHAMPION_DATA.format_map( + {"version": get_latest_version(), "name": name} + ), + timeout=15, + ) + return response.json() + + def gather_ingame_information() -> tuple[str, str, int, str, int, int]: """ Get the current playing champion name. @@ -55,7 +67,7 @@ def gather_ingame_information() -> tuple[str, str, int, str, int, int]: print("-" * 50) if champion_name: print( - f"{Colors.yellow}Champion name found {Colors.green}({champion_name}),{Colors.yellow} continuing..{Colors.reset}" + f"{Colors.yellow}Champion name found {Colors.green}({CHAMPION_NAME_CONVERT_MAP.get(champion_name, champion_name)}),{Colors.yellow} continuing..{Colors.reset}" ) if skin_name: print( @@ -81,22 +93,37 @@ def gather_ingame_information() -> tuple[str, str, int, str, int, int]: def gather_league_data( parsed_data: dict[str, Any], summoners_name: str, -) -> tuple[Optional[str], Optional[int], Optional[str]]: +) -> tuple[Optional[str], int, Optional[str]]: """ If the gamemode is LEAGUE, gather the relevant information and return it to RPC. """ champion_name: Optional[str] = None - skin_id: Optional[int] = None + skin_id: int = 0 skin_name: Optional[str] = None + skin_ids = [] + for player in parsed_data["allPlayers"]: if player["summonerName"] == summoners_name: - champion_name = CHAMPION_NAME_CONVERT_MAP.get( - player["championName"], - player["championName"], - ) + raw_champion_name = player["rawChampionName"].split("_")[-1] + champion_data = get_specific_champion_data(name=raw_champion_name) + + champion_name = champion_data["data"][raw_champion_name]["id"] + skin_id = player["skinID"] - skin_name = player.get("skinName") + + skin_ids = [ + i["num"] for i in champion_data["data"][raw_champion_name]["skins"] + ] + + if skin_id: + while skin_id not in skin_ids: + skin_id -= 1 + + for i in champion_data["data"][raw_champion_name]["skins"]: + if skin_id == i["num"]: + skin_name = i["name"] + break break continue return champion_name, skin_id, skin_name diff --git a/league_rpc_linux/const.py b/league_rpc_linux/const.py index 9ec76fc..0e5057d 100644 --- a/league_rpc_linux/const.py +++ b/league_rpc_linux/const.py @@ -14,6 +14,12 @@ "https://raw.communitydragon.org/latest/game/assets/ux/summonericons/profileicon" ) +DDRAGON_CHAMPION_DATA = ( + "https://ddragon.leagueoflegends.com/cdn/{version}/data/en_US/champion/{name}.json" +) + +DDRAGON_API_VERSIONS = "https://ddragon.leagueoflegends.com/api/versions.json" + MAP_ICON_CONVERT_MAP = { 11: "classic_sru", 12: "aram", @@ -37,27 +43,37 @@ } CHAMPION_NAME_CONVERT_MAP = { - "Aurelion Sol": "AurelionSol", - "Bel'Veth": "Belveth", - "Cho'Gath": "Chogath", - "Dr. Mundo": "DrMundo", - "Jarvan IV": "JarvanIV", - "Kai'Sa": "Kaisa", - "Kha'Zix": "Khazix", - "Kog'Maw": "KogMaw", - "K'Sante": "KSante", - "Lee Sin": "LeeSin", - "Master Yi": "MasterYi", - "Miss Fortune": "MissFortune", - "Nunu & Willump": "Nunu", - "Rek'Sai": "RekSai", - "Renata Glasc": "Renata", - "Tahm Kench": "TahmKench", - "Twisted Fate": "TwistedFate", - "Vel'Koz": "Velkoz", - "Wukong": "MonkeyKing", - "Xin Zhao": "XinZhao", + "AurelionSol": "Aurelion Sol", + "Belveth": "Bel'Veth", + "Chogath": "Cho'Gath", + "DrMundo": "Dr. Mundo", + "JarvanIV": "Jarvan IV", + "Kaisa": "Kai'Sa", + "Khazix": "Kha'Zix", + "KogMaw": "Kog'Maw", + "KSante": "K'Sante", + "LeeSin": "Lee Sin", + "MasterYi": "Master Yi", + "MissFortune": "Miss Fortune", + "Nunu": "Nunu & Willump", + "RekSai": "Rek'Sai", + "Renata": "Renata Glasc", + "TahmKench": "Tahm Kench", + "TwistedFate": "Twisted Fate", + "Velkoz": "Vel'Koz", + "MonkeyKing": "Wukong", + "XinZhao": "Xin Zhao", } LEAGUE_RANKED_EMBLEM = "https://github.com/Its-Haze/league-assets/blob/master/ranked_emblems/{tier}.png?raw=true" LEAGUE_CHERRY_RANKED_EMBLEM = "https://github.com/Its-Haze/league-assets/blob/master/cherry_rated_medallions/{tier}.png?raw=true" + + +RANKED_TYPE_MAPPER = { + "RANKED_SOLO_5x5": "Ranked Solo/Duo", + "RANKED_FLEX_SR": "Ranked Flex", + "RANKED_TFT": "Teamfight Tactics (Ranked)", + "RANKED_TFT_DOUBLE_UP": "Teamfight Tactics (Double Up Workshop)", + "RANKED_TFT_TURBO": "Teamfight Tactics (Hyper Roll)", + "CHERRY": "Arena", +} diff --git a/league_rpc_linux/latest_version.py b/league_rpc_linux/latest_version.py new file mode 100644 index 0000000..ede1b3b --- /dev/null +++ b/league_rpc_linux/latest_version.py @@ -0,0 +1,11 @@ +import requests + +from league_rpc_linux.const import DDRAGON_API_VERSIONS + + +def get_latest_version() -> str: + response = requests.get(url=DDRAGON_API_VERSIONS, timeout=15) + + data = response.json() + latest_version = data[0] + return latest_version diff --git a/league_rpc_linux/lcu_api/base_data.py b/league_rpc_linux/lcu_api/base_data.py index 9d3101b..3cca94b 100644 --- a/league_rpc_linux/lcu_api/base_data.py +++ b/league_rpc_linux/lcu_api/base_data.py @@ -65,6 +65,7 @@ async def gather_queue_data(connection: Connection, data: ClientData): ) lobby_queue_info = await lobby_queue_info_raw.json() data.queue = lobby_queue_info[LolGameQueuesQueue.NAME] + data.queue_type = lobby_queue_info[LolGameQueuesQueue.TYPE] data.max_players = int( lobby_queue_info[LolGameQueuesQueue.MAXIMUM_PARTICIPANT_LIST_SIZE] ) diff --git a/league_rpc_linux/lcu_api/lcu_connector.py b/league_rpc_linux/lcu_api/lcu_connector.py index dceedf0..ef70ee9 100644 --- a/league_rpc_linux/lcu_api/lcu_connector.py +++ b/league_rpc_linux/lcu_api/lcu_connector.py @@ -148,6 +148,7 @@ async def in_lobby(connection: Connection, event: WebsocketEventResponse) -> Non lobby_queue_info = await lobby_queue_info_raw.json() data.queue = lobby_queue_info[LolGameQueuesQueue.NAME] + data.queue_type = lobby_queue_info[LolGameQueuesQueue.TYPE] data.queue_is_ranked = lobby_queue_info[LolGameQueuesQueue.IS_RANKED] rpc_updater.delay_update(module_data) diff --git a/league_rpc_linux/models/client_data.py b/league_rpc_linux/models/client_data.py index c8e4d11..7106721 100644 --- a/league_rpc_linux/models/client_data.py +++ b/league_rpc_linux/models/client_data.py @@ -20,6 +20,7 @@ class ClientData: max_players: int = 0 # max players in lobby players: int = 0 # players in lobby queue: str = "" + queue_type = "" queue_id: int = -1 queue_is_ranked: bool = False summoner_icon: int = 0 diff --git a/league_rpc_linux/models/rpc_updater.py b/league_rpc_linux/models/rpc_updater.py index 5f6c284..f7a2298 100644 --- a/league_rpc_linux/models/rpc_updater.py +++ b/league_rpc_linux/models/rpc_updater.py @@ -10,6 +10,7 @@ LEAGUE_OF_LEGENDS_LOGO, MAP_ICON_CONVERT_MAP, PROFILE_ICON_BASE_URL, + RANKED_TYPE_MAPPER, SMALL_TEXT, ) from league_rpc_linux.lcu_api.lcu_connector import ModuleData @@ -124,7 +125,7 @@ def show_ranked_data( ) -> tuple[str, ...]: large_text = small_text = small_image = "" - match module_data.client_data.queue: + match RANKED_TYPE_MAPPER.get(module_data.client_data.queue_type): case "Ranked Solo/Duo": summoner_rank = module_data.client_data.summoner_rank if summoner_rank.tier: