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
|
2023-03-04 08:51:56 +00:00
|
|
|
|
from core.component import module
|
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'
|
|
|
|
|
|
2023-04-05 07:37:07 +00:00
|
|
|
|
i = module('idlist', support_languages=['zh_cn'])
|
2022-05-13 17:13:11 +00:00
|
|
|
|
|
|
|
|
|
|
2023-03-15 14:01:02 +00:00
|
|
|
|
@i.handle('<query> {{idlist.help}}')
|
2023-06-09 10:12:08 +00:00
|
|
|
|
async def _(msg: Bot.MessageSession, query: str):
|
2022-05-13 17:13:11 +00:00
|
|
|
|
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:
|
2023-03-15 13:02:08 +00:00
|
|
|
|
plain_texts.append(msg.locale.t('idlist.message.collapse'))
|
2022-06-29 14:58:43 +00:00
|
|
|
|
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:
|
2023-03-15 13:02:08 +00:00
|
|
|
|
await msg.finish(msg.locale.t('idlist.message.none'))
|