Skip to content

Commit

Permalink
Merge pull request #38 from Its-Haze/fix/broken-riot-id-change-patch-…
Browse files Browse the repository at this point in the history
…14-10

Fix leagueRPC to work on patch 14.10 API
  • Loading branch information
Its-Haze authored May 16, 2024
2 parents be7a6fa + 6f4290f commit fe47354
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion league_rpc/__version__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Set version number of package."""

__version__ = "v2.1.0"
__version__ = "v2.1.1"
import requests

RELEASES_PAGE = "https://github.com/Its-Haze/league-rpc/releases"
Expand Down
6 changes: 3 additions & 3 deletions league_rpc/champion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from league_rpc.kda import get_gold, get_level
from league_rpc.latest_version import get_latest_version
from league_rpc.username import get_summoner_name
from league_rpc.username import get_riot_id
from league_rpc.utils.color import Color
from league_rpc.utils.const import (
ALL_GAME_DATA_URL,
Expand Down Expand Up @@ -35,7 +35,7 @@ def gather_ingame_information() -> tuple[str, str, int, str, int, int]:
Get the current playing champion name.
"""
all_game_data_url = ALL_GAME_DATA_URL
your_summoner_name: str = get_summoner_name()
your_summoner_name: str = get_riot_id()

champion_name: str | None = None
skin_id: int | None = None
Expand Down Expand Up @@ -106,7 +106,7 @@ def gather_league_data(
skin_ids: list[int] = []

for player in parsed_data["allPlayers"]:
if player["summonerName"] == summoners_name:
if player["riotId"] == summoners_name:
raw_champion_name: str = player["rawChampionName"].split("_")[-1]
champion_data: dict[str, Any] = get_specific_champion_data(
name=raw_champion_name
Expand Down
13 changes: 7 additions & 6 deletions league_rpc/kda.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import urllib3
from requests import Response

from league_rpc.username import get_summoner_name
from league_rpc.username import get_riot_id
from league_rpc.utils.polling import wait_until_exists

urllib3.disable_warnings()
Expand Down Expand Up @@ -68,13 +68,14 @@ def get_creepscore() -> str:

def get_current_user_stats() -> Response | None:
"""
Request data from playerscores?summonerName and return the response.
Request data from playerscores?riotId and return the response.
"""
your_summoner_name = get_summoner_name()
if your_summoner_name:
your_riot_id = get_riot_id()
if your_riot_id:
# If the summoner name is not found, we don't want the KDA.

player_score_url = f"https://127.0.0.1:2999/liveclientdata/playerscores?summonerName={your_summoner_name}"
player_score_url = (
f"https://127.0.0.1:2999/liveclientdata/playerscores?riotId={your_riot_id}"
)
if response := wait_until_exists(url=player_score_url):
return response
return None
Expand Down
18 changes: 12 additions & 6 deletions league_rpc/username.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
from typing import Any

import urllib3

from league_rpc.utils.polling import wait_until_exists

urllib3.disable_warnings()


def get_summoner_name(with_discriminator: bool = False) -> str:
def get_riot_id(without_discriminator: bool = False) -> str:
"""
Gets the current summoner name.
if with_discriminator is True, the function will return a summoners name with #EUW / #EUNE etc
Defaults to not include it.
if without_discriminator is True, the function will not return a summoners name with #EUW / #EUNE etc
Defaults to include it.
"""
url = "https://127.0.0.1:2999/liveclientdata/activeplayername"

url = "https://127.0.0.1:2999/liveclientdata/playerlist"
if response := wait_until_exists(
url=url,
custom_message="""
Summoner name could not be found.
Contact @haze.dev on discord, or submit a ticket on Github.
""",
):
name = str(response.json())
return name if with_discriminator else name.split("#", maxsplit=1)[0]
_response: list[dict[str, Any]] = response.json()
name_without_discriminator = _response[0]["riotIdGameName"]
riot_id = _response[0]["riotId"]

return name_without_discriminator if without_discriminator else riot_id

return ""

0 comments on commit fe47354

Please sign in to comment.