iShotaBot/defs/guess.py

26 lines
808 B
Python
Raw Normal View History

2022-07-25 10:17:37 +00:00
import json
from init import request
2022-07-25 10:19:10 +00:00
async def guess_str(key):
2022-07-25 10:17:37 +00:00
if key == '':
return ''
text = {'text': key}
2022-07-25 10:20:20 +00:00
guess_json = (await request.post("https://lab.magiconch.com/api/nbnhhsh/guess", data=text)).json()
2022-07-25 10:17:37 +00:00
if len(guess_json) == 0:
return ""
guess_res = []
for num in range(len(guess_json)):
guess_res1 = json.loads(json.dumps(guess_json[num]))
guess_res1_name = guess_res1['name']
try:
guess_res1_ans = ", ".join(guess_res1['trans'])
except:
try:
guess_res1_ans = ", ".join(guess_res1['inputting'])
except:
guess_res1_ans = "尚未录入"
guess_res.extend([f"词组:{guess_res1_name}" + "\n释义:" + guess_res1_ans])
return "\n\n".join(guess_res)