From a1f44ff1af2605efe9b3a6a7db92a21fb801796a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 26 Sep 2020 03:02:04 +0200 Subject: [PATCH] complete trionfi --- royalpack/halloween2020/api_user_trionfi.py | 64 +++++++++++++++++++++ royalpack/halloween2020/trionfilist.py | 12 ++-- royalpack/stars/__init__.py | 2 + royalpack/tables/steam.py | 3 +- 4 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 royalpack/halloween2020/api_user_trionfi.py diff --git a/royalpack/halloween2020/api_user_trionfi.py b/royalpack/halloween2020/api_user_trionfi.py new file mode 100644 index 00000000..275411e7 --- /dev/null +++ b/royalpack/halloween2020/api_user_trionfi.py @@ -0,0 +1,64 @@ +import datetime +import royalnet.backpack.tables as rbt +import royalnet.constellation.api as rca +from .trionfistatus import TrionfiStatus + + +class ApiUserTrionfiStar(rca.ApiStar): + path = "/api/user/trionfi/v2" + + parameters = { + "get": { + "uid": "(Choose one) The id of the user to get information about.", + "alias": "(Choose one) The alias of the user to get information about.", + } + } + + auth = { + "get": True + } + + tags = ["user"] + + async def get_user(self, data: rca.ApiData): + uid = data.int("uid", optional=True) + alias = data.str("alias", optional=True) + + if uid: + user = await rbt.User.find(self.alchemy, data.session, uid) + elif alias: + user = await rbt.User.find(self.alchemy, data.session, alias) + else: + raise rca.MissingParameterError("Neither uid or alias were specified.") + + if user is None: + raise rca.NotFoundError("No such user.") + + return user + + @rca.magic + async def get(self, data: rca.ApiData) -> dict: + """Get Royalpack information about a user.""" + author = await data.user() + if len(author.steam) >= 1: + steam = author.steam[0] + if steam.trionfistatus is None: + TrionfiStatusT = self.alchemy.get(TrionfiStatus) + ts = TrionfiStatusT(steam=steam) + data.session.add(ts) + await data.session_commit() + if not steam.trionfistatus.zero: + steam.trionfistatus.zero = datetime.datetime.now() + await data.session_commit() + + 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], + "osu": [osu.json() for osu in user.osu], + "trivia": user.trivia_score.json() if user.trivia_score is not None else None, + } + return result diff --git a/royalpack/halloween2020/trionfilist.py b/royalpack/halloween2020/trionfilist.py index 01591daf..b44e05c9 100644 --- a/royalpack/halloween2020/trionfilist.py +++ b/royalpack/halloween2020/trionfilist.py @@ -9,7 +9,7 @@ trionfilist: List[TrionfoInfo] = [ roman="0", name="Il Folle", puzzle="UN VIAGGIO TI ATTENDE", - objective="Partecipa ai Trionfi Reali.", + objective="Trova la pagina dei Trionfi Reali.", check=NullCheck(), ), TrionfoInfo( @@ -18,7 +18,7 @@ trionfilist: List[TrionfoInfo] = [ roman="I", name="Il Mago", puzzle="L'ULTIMO GIORNO", - objective="Trova una /spell che possa fare almeno 250 danni.", + objective="Scopri una magia che possa fare più di 250 danni.", check=NullCheck(), ), TrionfoInfo( @@ -55,7 +55,7 @@ trionfilist: List[TrionfoInfo] = [ name="Il Papa", puzzle="ALLA DECIMASESTA ORA", objective="Completa la prima zona di [url=https://store.steampowered.com/app/247080]Crypt of the Necrodancer[" - "/url] (con qualsiasi personaggio).", + "/url] con qualsiasi personaggio.", check=CheckAchievementSteamGame(247080, "ACH_ZONE1_COMPLETE") ), TrionfoInfo( @@ -64,7 +64,7 @@ trionfilist: List[TrionfoInfo] = [ roman="VI", name="Gli Amanti", puzzle="ANCORA TRENTA MINUTI", - objective="Finisci l'Atto 3 di [url=https://store.steampowered.com/app/698780]Doki Doki Literature Club[" + objective="Gioca almeno mezz'ora a [url=https://store.steampowered.com/app/698780]Doki Doki Literature Club[" "/url].", check=CheckPlayedSteamGame(698780), ), @@ -74,7 +74,7 @@ trionfilist: List[TrionfoInfo] = [ roman="VII", name="Il Carro", puzzle="SOPRA UN CARRO", - objective="Gioca 5 incontri a [url=https://store.steampowered.com/app/326460/ShellShock_Live]ShellShock Live[" + objective="Gioca 5 incontri di [url=https://store.steampowered.com/app/326460/ShellShock_Live]ShellShock Live[" "/url].", check=CheckAchievementSteamGame(326460, "play5") ), @@ -209,7 +209,7 @@ trionfilist: List[TrionfoInfo] = [ roman="XXI", name="Il Mondo", puzzle="""44°35'45.0"N 11°02'58.9"E""", - objective="???", + objective="Attraverso i Trionfi, il segreto ti sarà lentamente rivelato...", check=NullCheck(), ), ] \ No newline at end of file diff --git a/royalpack/stars/__init__.py b/royalpack/stars/__init__.py index e87eb26b..745d5023 100644 --- a/royalpack/stars/__init__.py +++ b/royalpack/stars/__init__.py @@ -15,6 +15,7 @@ from .api_user_avatar import ApiUserAvatarStar from .api_auth_login_osu import ApiAuthLoginOsuStar from .api_diario_range import ApiDiarioRangeStar from .api_diario_latest import ApiDiarioLatestStar +from ..halloween2020.api_user_trionfi import ApiUserTrionfiStar # Enter the PageStars of your Pack here! available_page_stars = [ @@ -34,6 +35,7 @@ available_page_stars = [ ApiAuthLoginOsuStar, ApiDiarioRangeStar, ApiDiarioLatestStar, + ApiUserTrionfiStar, ] # Don't change this, it should automatically generate __all__ diff --git a/royalpack/tables/steam.py b/royalpack/tables/steam.py index f27ad88d..0dbdd297 100644 --- a/royalpack/tables/steam.py +++ b/royalpack/tables/steam.py @@ -77,7 +77,8 @@ class Steam: "dota": self.dota.json() if self.dota is not None else None, "brawlhalla": self.brawlhalla.json() if self.brawlhalla is not None else None, - "trionfistatus": self.trionfistatus.json() if self.trionfistatus is not None else None, + "trionfistatus": self.trionfistatus.json() if (self.trionfistatus is not None and self.trionfistatus.zero + is not None) else None, } def __repr__(self):