diff --git a/pyproject.toml b/pyproject.toml index f75f6d8e..f3000f41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ [tool.poetry] name = "royalpack" - version = "5.8.22" + version = "5.8.23" 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 84e76752..6137b1cc 100644 --- a/royalpack/stars/__init__.py +++ b/royalpack/stars/__init__.py @@ -16,6 +16,7 @@ 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 +from .api_user_find_ryg import ApiUserFindRygStar # Enter the PageStars of your Pack here! available_page_stars = [ @@ -36,6 +37,7 @@ available_page_stars = [ ApiCvstatsLatestStar, ApiCvstatsAvgStar, ApiUserGetRygStar, + ApiUserFindRygStar, ] # Don't change this, it should automatically generate __all__ diff --git a/royalpack/stars/api_user_find_ryg.py b/royalpack/stars/api_user_find_ryg.py new file mode 100644 index 00000000..60d3fe68 --- /dev/null +++ b/royalpack/stars/api_user_find_ryg.py @@ -0,0 +1,38 @@ +import royalnet.constellation.api as rca +import royalnet.utils as ru +import royalnet.backpack.tables as rbt +from .api_user_get_ryg import ApiUserGetRygStar + + +class ApiUserFindRygStar(ApiUserGetRygStar): + summary = "Ottieni le informazioni su un utente della Royal Games." + + description = "" + + methods = ["GET"] + + path = "/api/user/find/ryg/v1" + + requires_auth = False + + parameters = {"alias": "L'alias dell'utente di cui vuoi vedere le informazioni."} + + tags = ["user"] + + async def get_user(self, data: rca.ApiData): + user = await rbt.User.find(self.alchemy, data.session, data["alias"]) + if user is None: + raise rca.NotFoundError("No such user.") + return user + + async def api(self, data: rca.ApiData) -> dict: + user = await self.get_user(data) + result = { + **user.json(), + "bio": user.bio.json() if user.bio is not None else None, + "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/stars/api_user_get_ryg.py b/royalpack/stars/api_user_get_ryg.py index ef5350de..31d22350 100644 --- a/royalpack/stars/api_user_get_ryg.py +++ b/royalpack/stars/api_user_get_ryg.py @@ -18,7 +18,7 @@ class ApiUserGetRygStar(rca.ApiStar): tags = ["user"] - async def api(self, data: rca.ApiData) -> dict: + async def get_user(self, data: rca.ApiData): user_id_str = data["id"] try: user_id = int(user_id_str) @@ -27,6 +27,10 @@ class ApiUserGetRygStar(rca.ApiStar): 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.") + return user + + async def api(self, data: rca.ApiData) -> dict: + user = await self.get_user(data) result = { **user.json(), "bio": user.bio.json() if user.bio is not None else None, diff --git a/royalpack/tables/brawlhalla.py b/royalpack/tables/brawlhalla.py index e7803fb3..aa8555eb 100644 --- a/royalpack/tables/brawlhalla.py +++ b/royalpack/tables/brawlhalla.py @@ -43,6 +43,8 @@ class Brawlhalla: @property def rank_1v1(self): + if self.metal_1v1 is None: + return None return BrawlhallaRank(metal=self.metal_1v1, tier=self.tier_1v1) @rank_1v1.setter @@ -93,12 +95,12 @@ class Brawlhalla: "rating": self.rating_1v1, "metal": one_rank.metal.name, "tier": one_rank.tier.name - }, + } if one_rank is not None else None, "2v2": { "rating": self.rating_2v2, "metal": two_rank.metal.name, "tier": two_rank.tier.name - } + } if two_rank is not None else None } def __repr__(self): diff --git a/royalpack/tables/dota.py b/royalpack/tables/dota.py index 5887d756..8ff9ccdc 100644 --- a/royalpack/tables/dota.py +++ b/royalpack/tables/dota.py @@ -80,7 +80,7 @@ class Dota: "raw": self._rank_tier, "medal": rank.medal.name, "rank": rank.stars.name - }, + } if self._rank_tier is not None else None, "wins": self.wins, "losses": self.losses } diff --git a/royalpack/version.py b/royalpack/version.py index 3ad08f3f..a756789d 100644 --- a/royalpack/version.py +++ b/royalpack/version.py @@ -1 +1 @@ -semantic = "5.8.22" +semantic = "5.8.23"