2022-01-08 11:23:31 +00:00
|
|
|
import traceback
|
|
|
|
|
2022-01-03 09:13:42 +00:00
|
|
|
import ujson as json
|
|
|
|
|
2022-08-04 07:52:42 +00:00
|
|
|
from core.logger import Logger
|
2023-02-05 14:33:33 +00:00
|
|
|
from core.utils.http import post_url
|
2023-04-15 08:18:51 +00:00
|
|
|
from core.utils.i18n import Locale
|
2022-01-03 09:13:42 +00:00
|
|
|
|
2022-01-20 12:13:03 +00:00
|
|
|
|
2023-04-15 08:18:51 +00:00
|
|
|
async def nbnhhsh(term: str, locale: Locale):
|
2022-01-03 09:13:42 +00:00
|
|
|
'''查询nbnhhsh。
|
|
|
|
:param term: 需要查询的term。
|
|
|
|
:returns: 查询结果。'''
|
|
|
|
try:
|
2022-01-08 14:03:09 +00:00
|
|
|
url = 'https://lab.magiconch.com/api/nbnhhsh/guess'
|
|
|
|
req = json.dumps({'text': term})
|
2023-01-15 11:29:15 +00:00
|
|
|
data = await post_url(url, data=req, headers={'Content-Type': 'application/json', 'Accept': '*/*',
|
|
|
|
'Content-Length': str(len(req))}, fmt='json')
|
|
|
|
Logger.debug(data)
|
2022-07-26 09:54:43 +00:00
|
|
|
try:
|
|
|
|
result = data[0]
|
|
|
|
except IndexError:
|
2023-04-15 09:28:18 +00:00
|
|
|
return f'[{locale.t("meme.message.nbnhhsh")}] {locale.t("meme.message.not_found")}'
|
2022-01-03 09:13:42 +00:00
|
|
|
if 'trans' in result:
|
|
|
|
trans = result['trans']
|
|
|
|
count = trans.__len__()
|
2023-04-15 09:28:18 +00:00
|
|
|
return f'[{locale.t("meme.message.nbnhhsh")}] {locale.t("meme.message.nbnhhsh.result", result=count)}{"、".join(trans)}'
|
2022-01-03 09:13:42 +00:00
|
|
|
elif 'inputting' in result and result['inputting'] != []:
|
|
|
|
inputting = result['inputting']
|
|
|
|
count = inputting.__len__()
|
2023-04-15 09:28:18 +00:00
|
|
|
return f'[{locale.t("meme.message.nbnhhsh")}] {locale.t("meme.message.nbnhhsh.result.ai", result=count)}{"、".join(inputting)}'
|
2022-01-03 09:13:42 +00:00
|
|
|
else:
|
2023-04-15 09:28:18 +00:00
|
|
|
return f'[{locale.t("meme.message.nbnhhsh")}] {locale.t("meme.message.not_found")}'
|
2022-01-08 11:23:31 +00:00
|
|
|
except Exception:
|
|
|
|
traceback.print_exc()
|
2023-04-15 09:28:18 +00:00
|
|
|
return f'[{locale.t("meme.message.nbnhhsh")}] {locale.t("meme.message.error")}'
|