示例#1
0
文件: helper.py 项目: apollyon600/bot
async def get_from_name_uuid(name_uuid, *, session, with_history=False):
    try:
        async with session.get(f'https://api.ashcon.app/mojang/v2/user/{name_uuid}') as resp:
            json = await resp.json(content_type=None)

            if json is None or 'username' not in json or 'uuid' not in json:
                raise BadNameError(name_uuid) from None

            if with_history:
                return json['username'], json['uuid'].replace('-', ''), json['username_history']
            else:
                return json['username'], json['uuid'].replace('-', '')
    except (asyncio.TimeoutError, aiohttp.ClientConnectorError):
        raise ExternalAPIError('Could not connect to https://api.ashcon.app.') from None
    except aiohttp.ClientResponseError as e:
        if e.status == 429:
            raise ExternalAPIError('Ashcon API ratelimit has been reached!') from None
        else:
            raise BadNameError(name_uuid) from None
示例#2
0
文件: helper.py 项目: apollyon600/bot
async def get_event_estimate_time(endpoint, *, session):
    try:
        async with session.get(f'https://hypixel-api.inventivetalent.org/api/{endpoint}') as resp:
            json = await resp.json(content_type=None)
            if json is None or 'success' not in json:
                return None
            if not json['success']:
                return None
            return json['estimate']
    except asyncio.TimeoutError:
        raise ExternalAPIError('Could not connect to https://hypixel-api.inventivetalent.org.') from None
示例#3
0
文件: helper.py 项目: apollyon600/bot
async def get_item_price_stats(item_id, *, session):
    """
    Get item's price stats with item id.
    """
    try:
        async with session.get(f'https://auctions.craftlink.xyz/api/items/{item_id}/quickStats') as response:
            json = await response.json(content_type=None)
            if json is None or 'success' not in json:
                return None
            if not json['success']:
                return None
            return json['data']
    except asyncio.TimeoutError:
        raise ExternalAPIError('Could not connect to https://auctions.craftlink.xyz.') from None
示例#4
0
文件: helper.py 项目: apollyon600/bot
async def get_item_list(item_name, *, session):
    """
    Search with item name and return the first result's item id.
    """
    item_name = quote(item_name)
    try:
        async with session.get(f'https://auctions.craftlink.xyz/api/items/search?name={item_name}') as response:
            json = await response.json(content_type=None)
            if json is None or 'success' not in json:
                return None
            if not json['success']:
                return None
            return json['data']
    except asyncio.TimeoutError:
        raise ExternalAPIError('Could not connect to https://auctions.craftlink.xyz.') from None