-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66c1fc2
commit c1763c7
Showing
9 changed files
with
367 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,49 @@ | ||
from bot.utils import CHAMPS, VERSION | ||
from dataclasses import dataclass | ||
from bot.utils import get_version, get_champs | ||
|
||
@dataclass | ||
class Champ: | ||
def __init__(self, champ): | ||
self.champ = CHAMPS[champ]['id'] | ||
self.title = CHAMPS[self.champ]['title'] | ||
self.img = f"https://ddragon.leagueoflegends.com/cdn/{VERSION}/img/champion/{CHAMPS[self.champ]['image']['full']}" | ||
self.desc = CHAMPS[self.champ]['blurb'] | ||
self.tags = ' '.join(CHAMPS[self.champ]['tags']) | ||
self.stats = f'Health: {CHAMPS[self.champ]["stats"]["hp"]} \n \ | ||
Move Speed: {CHAMPS[self.champ]["stats"]["movespeed"]} \n \ | ||
Attack Damage: {CHAMPS[self.champ]["stats"]["attackdamage"]} \n \ | ||
Attack Range: {CHAMPS[self.champ]["stats"]["attackrange"]} \n \ | ||
Attack Speed: {CHAMPS[self.champ]["stats"]["attackspeed"]}' | ||
self.url = f'https://www.op.gg/champion/{self.champ}/statistics' | ||
self.real = True | ||
self.name = CHAMPS[champ]['name'] | ||
|
||
"""Model for representing a League of Legends champ""" | ||
title: str | ||
champ: str | ||
name: str | ||
img: str | ||
desc: str | ||
tags: str | ||
stats: str | ||
url: str | ||
|
||
class Champs: | ||
"""Singleton class to dynamically generates a champ upon request""" | ||
def real_champ(self, name): | ||
"""Check if a champ is real""" | ||
_name = name.lower().replace(' ', '') | ||
for champ in get_champs(): | ||
if champ.lower() == _name: | ||
return champ | ||
return None | ||
|
||
def get_champ(self, champ): | ||
"""Generate the Champ Model object""" | ||
champ_id = get_champs()[champ]['id'] | ||
title = get_champs()[champ_id]['title'] | ||
img = f"https://ddragon.leagueoflegends.com/cdn/{get_version()}/img/champion/{get_champs()[champ_id]['image']['full']}" | ||
desc = get_champs()[champ_id]['blurb'] | ||
tags = ' '.join(get_champs()[champ_id]['tags']) | ||
stats = f'Health: {get_champs()[champ_id]["stats"]["hp"]} \n \ | ||
Move Speed: {get_champs()[champ_id]["stats"]["movespeed"]} \n \ | ||
Attack Damage: {get_champs()[champ_id]["stats"]["attackdamage"]} \n \ | ||
Attack Range: {get_champs()[champ_id]["stats"]["attackrange"]} \n \ | ||
Attack Speed: {get_champs()[champ_id]["stats"]["attackspeed"]}' | ||
url = f'https://www.op.gg/champion/{champ_id}/statistics' | ||
name = get_champs()[champ_id]['name'] | ||
return Champ( | ||
title=title, | ||
champ=champ_id, | ||
name=name, | ||
img=img, | ||
desc=desc, | ||
tags=tags, | ||
stats=stats, | ||
url=url | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from dataclasses import dataclass | ||
import requests | ||
from riotwatcher import LolWatcher | ||
from bot.utils import RIOT_API_KEY, get_version, get_champs | ||
|
||
@dataclass | ||
class Player(): | ||
"""Model for representing League of Legends player""" | ||
name: str | ||
url: str | ||
level: str | ||
icon_img: str | ||
ranksolo: str | ||
rank5: str | ||
win: str | ||
champ: str | ||
img: str | ||
|
||
class Players(): | ||
"""Singleton class to dynamically generates player data""" | ||
def __init__(self): | ||
self.riot = LolWatcher(RIOT_API_KEY) | ||
|
||
def get_player(self, name, region="na1", prefix="na"): | ||
if prefix == "kr": prefix = "www" | ||
try: | ||
player_info = self.riot.summoner.by_name(region, name) | ||
player_stats = self.riot.league.by_summoner(region, player_info['id']) | ||
except Exception as e: | ||
print(f'Unable to load plater data from Riot API: \n {e}') | ||
return None | ||
else: | ||
_name = player_info['name'] | ||
url = f'https://{prefix}.op.gg/summoner/userName={name}' | ||
level = player_info['summonerLevel'] | ||
icon_img = f"https://ddragon.leagueoflegends.com/cdn/{get_version()}/img/profileicon/{player_info['profileIconId']}.png" | ||
try: | ||
if len(player_stats) >= 2: | ||
for i in player_stats: | ||
if i["queueType"] == "RANKED_SOLO_5x5": | ||
ranksolo = f'{i["tier"].lower().capitalize()} {i["rank"]} {i["leaguePoints"]} LP' | ||
elif i["queueType"] == "RANKED_FLEX_SR": | ||
rank5 = f'{i["tier"].lower().capitalize()} {i["rank"]} {i["leaguePoints"]} LP' | ||
else: | ||
ranksolo = f'{player_stats[0]["tier"].lower().capitalize()} {player_stats[0]["rank"]} {player_stats[0]["leaguePoints"]} LP' | ||
rank5 = None | ||
except IndexError: | ||
ranksolo = 'Unranked' | ||
rank5 = 'Unranked' | ||
if ranksolo != 'Unranked': | ||
win = f'{round((player_stats[0]["wins"] / (player_stats[0]["wins"] + player_stats[0]["losses"])) * 100)}%' | ||
else: | ||
win = 'N/A' | ||
try: | ||
mastery = requests.get(f'https://{region}.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/{player_info["id"]}?api_key={RIOT_API_KEY}').json() | ||
for champ in get_champs(): | ||
if get_champs()[champ]['key'] == str(mastery[0]['championId']): | ||
_champ = f"{get_champs()[champ]['name']} {mastery[0]['championPoints']}" | ||
img = f"https://ddragon.leagueoflegends.com/cdn/{get_version()}/img/champion/{get_champs()[champ]['image']['full']}" | ||
break | ||
except: | ||
champ = "N/A" | ||
img = "N/A" | ||
|
||
return Player( | ||
name=_name, | ||
url=url, | ||
level=level, | ||
icon_img=icon_img, | ||
ranksolo=ranksolo, | ||
rank5=rank5, | ||
win=win, | ||
champ=_champ, | ||
img=img | ||
) |
Oops, something went wrong.