Пример #1
0
    async def getrecent(self,
                        user: osu.User,
                        limit: int = 1) -> osu.RecentScore:
        async with aiohttp.ClientSession() as cs:
            params = {
                'k': self.__token,
                'u': user.user_id,
                'type': 'id',
                'm': user.mode.id,
                'limit': limit
            }

            if user.server is not osu.Server.BANCHO:
                params.pop('k')

            try:
                async with cs.get(user.server.api_getrecent,
                                  params=params) as r:
                    if (res := await r.json()) == []:
                        raise ValueError("Response is empty.")
                    else:
                        return list(
                            map(
                                lambda recent: osu.RecentScore(
                                    recent, user.server, user.mode), res))
Пример #2
0
    async def getusrtop(self,
                        user: osu.User,
                        limit: int = 1) -> List[osu.RecentScore]:
        async with aiohttp.ClientSession() as cs:
            params = {
                'k': self.__token,
                'u': user.user_id,
                'type': 'id',
                'limit': limit,
                'm': user.mode.id
            }

            if user.server is not osu.Server.BANCHO:
                params.pop('k')
                if user.server is osu.Server.AKATSUKIRX:
                    params['rx'] = 1
                    if params['type'] == 'id':
                        params['id'] = user.user_id
                    else:
                        params['name'] = user.username

            async with cs.get(user.server.api_getusrtop, params=params) as r:
                res = await r.json()
                if res == []:
                    raise ValueError("Invalid query or API down.")
                else:
                    if user.server is osu.Server.AKATSUKIRX:
                        res = res['scores']
                    return list(map(lambda top: osu.RecentScore(top), res))