예제 #1
0
 async def get_unlocked_achievements(self, game_id: str, context: Any) -> List[Achievement]:
     if not context:
         return []
     comm_ids: List[CommunicationId] = (await self.get_game_communication_ids([game_id]))[game_id]
     if not self._is_game(comm_ids):
         raise InvalidParams()
     return self._get_game_trophies_from_cache(comm_ids, context)[0]
예제 #2
0
    async def import_games_achievements(self, game_ids: Iterable[TitleId]):
        try:
            comm_ids = await self.get_game_communication_ids(game_ids)
            trophy_titles = await self._psn_client.get_trophy_titles()
        except ApplicationError as error:
            for game_id in game_ids:
                self.game_achievements_import_failure(game_id, error)

        # make a map
        trophy_titles = {trophy_title.communication_id: trophy_title for trophy_title in trophy_titles}
        requests = []
        for game_id, comm_id in comm_ids.items():
            if not self._is_game(comm_id):
                self.game_achievements_import_failure(game_id, InvalidParams())
                continue
            trophy_title = trophy_titles.get(comm_id)
            if trophy_title is None:
                self.game_achievements_import_success(game_id, [])
                continue
            trophies = self._trophies_cache.get(comm_id, trophy_title.last_update_time)
            if trophies is not None:
                self.game_achievements_import_success(game_id, trophies)
                continue
            requests.append(self._import_game_achievements(game_id, comm_id))
        await asyncio.gather(*requests)
예제 #3
0
    async def pass_login_credentials(self, step, credentials, cookies):
        try:
            morsels = dicts_to_morsels(cookies)
        except Exception:
            raise InvalidParams()

        auth_info = await self._do_auth(morsels)
        self._store_cookies(morsels)
        return auth_info
예제 #4
0
 async def get_unlocked_achievements(self, game_id: str,
                                     context: Any) -> List[Achievement]:
     if not context:
         return []
     trophy_title_infos: List[TrophyTitleInfo] = (
         await self.get_game_trophies_map([game_id]))[game_id]
     if not self._is_game(trophy_title_infos):
         raise InvalidParams()
     return self._get_game_trophies_from_cache(
         [tti.communication_id for tti in trophy_title_infos], context)[0]
예제 #5
0
 async def handle():
     try:
         result = await callback(params)
         await self._send_response(request_id, result)
     except TypeError:
         await self._send_error(request_id, InvalidParams())
     except NotImplementedError:
         await self._send_error(request_id, MethodNotFound())
     except ApplicationError as error:
         await self._send_error(request_id, error)
     except Exception as e:  #pylint: disable=broad-except
         logging.exception(
             "Unexpected exception raised in plugin handler")
         await self._send_error(request_id, UnknownError(str(e)))
예제 #6
0
        async def get_game_comm_id():
            comm_id: CommunicationId = (await self.get_game_communication_ids([game_id]))[game_id]
            if not self._is_game(comm_id):
                raise InvalidParams()

            return comm_id