diff --git a/pyproject.toml b/pyproject.toml index 5b63fea4..99e47c53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ [tool.poetry] name = "royalpack" - version = "5.8.19" + version = "5.8.20" description = "A Royalnet command pack for the Royal Games community" authors = ["Stefano Pigozzi "] license = "AGPL-3.0+" diff --git a/royalpack/stars/__init__.py b/royalpack/stars/__init__.py index 6d144ff5..84e76752 100644 --- a/royalpack/stars/__init__.py +++ b/royalpack/stars/__init__.py @@ -15,6 +15,7 @@ from .api_polls_get import ApiPollsGet from .api_polls_list import ApiPollsList from .api_cvstats_latest import ApiCvstatsLatestStar from .api_cvstats_avg import ApiCvstatsAvgStar +from .api_user_get_ryg import ApiUserGetRygStar # Enter the PageStars of your Pack here! available_page_stars = [ @@ -34,6 +35,7 @@ available_page_stars = [ ApiPollsList, ApiCvstatsLatestStar, ApiCvstatsAvgStar, + ApiUserGetRygStar, ] # Don't change this, it should automatically generate __all__ diff --git a/royalpack/stars/api_user_get_ryg.py b/royalpack/stars/api_user_get_ryg.py new file mode 100644 index 00000000..235d8210 --- /dev/null +++ b/royalpack/stars/api_user_get_ryg.py @@ -0,0 +1,38 @@ +import royalnet.constellation.api as rca +import royalnet.utils as ru +import royalnet.backpack.tables as rbt + + +class ApiUserGetRygStar(rca.ApiStar): + summary = "Ottieni le informazioni su un utente della Royal Games." + + description = "" + + methods = ["GET"] + + path = "/api/user/get/ryg/v1" + + requires_auth = False + + parameters = {"id": "L'id dell'utente di cui vuoi vedere le informazioni."} + + tags = ["user"] + + async def api(self, data: rca.ApiData) -> dict: + user_id_str = data["id"] + try: + user_id = int(user_id_str) + except (ValueError, TypeError): + raise rca.InvalidParameterError("'id' is not a valid int.") + user: rbt.User = await ru.asyncify(data.session.query(self.alchemy.get(rbt.User)).get, user_id) + if user is None: + raise rca.NotFoundError("No such user.") + result = { + **user.json(), + "bio": user.bio.json(), + "fiorygi": user.fiorygi.fiorygi if user.fiorygi is not None else None, + "steam": [steam.json() for steam in user.steam], + "leagueoflegends": [leagueoflegends.json() for leagueoflegends in user.leagueoflegends], + "trivia": user.trivia_score.json() if user.trivia_score is not None else None + } + return result diff --git a/royalpack/tables/brawlhalla.py b/royalpack/tables/brawlhalla.py index 27b60d66..e7803fb3 100644 --- a/royalpack/tables/brawlhalla.py +++ b/royalpack/tables/brawlhalla.py @@ -1,7 +1,7 @@ from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declared_attr -import steam +import steam.steamid from ..types import BrawlhallaRank, BrawlhallaTier, BrawlhallaMetal @@ -23,7 +23,7 @@ class Brawlhalla: @property def steamid(self): - return steam.SteamID(self._steamid) + return steam.steamid.SteamID(self._steamid) @declared_attr def name(self): @@ -58,34 +58,51 @@ class Brawlhalla: @property def rating_2v2(self): - duos = sorted(self.duos, key=lambda d: -d.rating) + duos = sorted(self.duos, key=lambda d: -d.rating_2v2) if len(duos) == 0: return None return duos[0].rating_2v2 @property def tier_2v2(self): - duos = sorted(self.duos, key=lambda d: -d.rating) + duos = sorted(self.duos, key=lambda d: -d.rating_2v2) if len(duos) == 0: return None return duos[0].tier_2v2 @property def metal_2v2(self): - duos = sorted(self.duos, key=lambda d: -d.rating) + duos = sorted(self.duos, key=lambda d: -d.rating_2v2) if len(duos) == 0: return None return duos[0].metal_2v2 @property def rank_2v2(self): - duos = sorted(self.duos, key=lambda d: -d.rating) + duos = sorted(self.duos, key=lambda d: -d.rating_2v2) if len(duos) == 0: return None return duos[0].rank_2v2 + def json(self): + one_rank = self.rank_1v1 + two_rank = self.rank_2v2 + return { + "name": self.name, + "1v1": { + "rating": self.rating_1v1, + "metal": one_rank.metal.name, + "tier": one_rank.tier.name + }, + "2v2": { + "rating": self.rating_2v2, + "metal": two_rank.metal.name, + "tier": two_rank.tier.name + } + } + def __repr__(self): return f"" def __str__(self): - return f"[c]brawlhalla:{self.brawlhalla_id}[/c]" \ No newline at end of file + return f"[c]brawlhalla:{self.brawlhalla_id}[/c]" diff --git a/royalpack/tables/dota.py b/royalpack/tables/dota.py index 3c75b0b0..5887d756 100644 --- a/royalpack/tables/dota.py +++ b/royalpack/tables/dota.py @@ -3,7 +3,7 @@ from sqlalchemy import * from sqlalchemy.orm import relationship, backref from sqlalchemy.ext.declarative import declared_attr from ..types import DotaMedal, DotaStars, DotaRank -import steam +import steam.steamid class Dota: @@ -19,7 +19,7 @@ class Dota: @property def steamid(self): - return steam.SteamID(self._steamid) + return steam.steamid.SteamID(self._steamid) @declared_attr def _rank_tier(self): @@ -72,6 +72,19 @@ class Dota: def losses(self): return Column(Integer) + def json(self): + rank = self.rank + + return { + "rank": { + "raw": self._rank_tier, + "medal": rank.medal.name, + "rank": rank.stars.name + }, + "wins": self.wins, + "losses": self.losses + } + def __repr__(self): return f"" diff --git a/royalpack/tables/leagueoflegends.py b/royalpack/tables/leagueoflegends.py index 4636324a..02618748 100644 --- a/royalpack/tables/leagueoflegends.py +++ b/royalpack/tables/leagueoflegends.py @@ -249,6 +249,21 @@ class LeagueOfLegends: def mastery_score(self): return Column(Integer, nullable=False, default=0) + def json(self): + return { + "region": self.region, + "profile_icon_id": self.profile_icon_id, + "summoner_name": self.summoner_name, + "puuid": self.puuid, + "summoner_level": self.summoner_level, + "summoner_id": self.summoner_id, + "account_id": self.account_id, + "soloq": self.rank_soloq.json() if self.rank_soloq is not None else None, + "twtrq": self.rank_twtrq.json() if self.rank_twtrq is not None else None, + "flexq": self.rank_flexq.json() if self.rank_flexq is not None else None, + "tftq": self.rank_tftq.json() if self.rank_tftq is not None else None, + } + def __repr__(self): return f"<{self.__class__.__qualname__} {str(self)}>" diff --git a/royalpack/tables/steam.py b/royalpack/tables/steam.py index 4d165ec7..24007241 100644 --- a/royalpack/tables/steam.py +++ b/royalpack/tables/steam.py @@ -1,7 +1,7 @@ from sqlalchemy import * from sqlalchemy.orm import relationship, backref from sqlalchemy.ext.declarative import declared_attr -import steam +import steam.steamid class Steam: @@ -21,7 +21,7 @@ class Steam: @property def steamid(self): - return steam.SteamID(self._steamid) + return steam.steamid.SteamID(self._steamid) @declared_attr def persona_name(self): @@ -43,6 +43,19 @@ class Steam: def account_creation_date(self): return Column(DateTime) + def json(self): + return { + "steamid": self._steamid, + "persona_name": self.persona_name, + "profile_url": self.profile_url, + "avatar": self.avatar, + "primary_clan_id": self.primary_clan_id, + "account_creation_date": self.account_creation_date.isoformat(), + + "dota": self.dota.json() if self.dota is not None else None, + "brawlhalla": self.brawlhalla.json() if self.brawlhalla is not None else None + } + def __repr__(self): return f"" diff --git a/royalpack/tables/triviascores.py b/royalpack/tables/triviascores.py index b5650b5e..8f240983 100644 --- a/royalpack/tables/triviascores.py +++ b/royalpack/tables/triviascores.py @@ -42,5 +42,14 @@ class TriviaScore: def score(self) -> float: return (self.correct_answers + self.correct_answers * self.correct_rate) * 10 + def json(self): + return { + "correct": self.correct_answers, + "wrong": self.wrong_answers, + "total": self.total_answers, + "rate": self.correct_rate, + "score": self.score + } + def __repr__(self): return f"" diff --git a/royalpack/types/leagueleague.py b/royalpack/types/leagueleague.py index 85c82c88..7a965346 100644 --- a/royalpack/types/leagueleague.py +++ b/royalpack/types/leagueleague.py @@ -150,3 +150,16 @@ class LeagueLeague: fresh_blood=d["freshBlood"], veteran=d["veteran"], ) + + def json(self): + return { + "tier": self.tier.name if self.tier is not None else None, + "rank": self.rank.name if self.tier is not None else None, + "points": self.points, + "wins": self.wins, + "losses": self.losses, + "inactive": self.inactive, + "hot_streak": self.hot_streak, + "fresh_blood": self.fresh_blood, + "veteran": self.veteran, + } diff --git a/royalpack/version.py b/royalpack/version.py index f862606d..0cf3cb22 100644 --- a/royalpack/version.py +++ b/royalpack/version.py @@ -1 +1 @@ -semantic = "5.8.19" +semantic = "5.8.20"