Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/idlist/__init__.py

30 lines
1 KiB
Python
Raw Normal View History

2022-06-19 14:55:24 +00:00
# https://github.com/XeroAlpha/caidlist/blob/master/backend/API.md
2022-06-12 07:07:53 +00:00
import urllib.parse
2022-05-13 17:13:11 +00:00
2023-02-05 14:33:33 +00:00
from core.builtins import Bot
2022-07-31 08:27:58 +00:00
from core.component import on_command
2023-02-05 14:33:33 +00:00
from core.utils.http import get_url
2022-05-13 17:13:11 +00:00
api = 'https://ca.projectxero.top/idlist/search'
i = on_command('idlist')
2022-06-30 05:16:53 +00:00
@i.handle('<query> {查询MCBEID表。}')
2023-02-05 14:33:33 +00:00
async def _(msg: Bot.MessageSession):
2022-05-13 17:13:11 +00:00
query = msg.parsed_msg['<query>']
query_options = {'q': query, 'limit': '6'}
query_url = api + '?' + urllib.parse.urlencode(query_options)
2022-08-01 15:33:35 +00:00
resp = await get_url(query_url, 200, fmt='json')
2022-05-13 17:13:11 +00:00
result = resp['data']['result']
plain_texts = []
if result:
for x in result[0:5]:
plain_texts.append(f'{x["enumName"]}{x["key"]} -> {x["value"]}')
if resp['data']['count'] > 5:
2022-06-29 14:58:43 +00:00
plain_texts.append('...仅显示前5条结果查看更多')
plain_texts.append('https://ca.projectxero.top/idlist/' + resp['data']['hash'])
2022-05-21 16:04:29 +00:00
await msg.finish('\n'.join(plain_texts))
2022-05-13 17:13:11 +00:00
else:
2022-05-21 16:04:29 +00:00
await msg.finish('没有找到结果。')