iShotaBot/defs/guess.py

28 lines
822 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):
2023-01-12 13:19:54 +00:00
if key == "":
return ""
text = {"text": key}
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]))
2023-01-12 13:19:54 +00:00
guess_res1_name = guess_res1["name"]
2022-07-25 10:17:37 +00:00
try:
2023-01-12 13:19:54 +00:00
guess_res1_ans = ", ".join(guess_res1["trans"])
2022-07-25 10:17:37 +00:00
except:
try:
2023-01-12 13:19:54 +00:00
guess_res1_ans = ", ".join(guess_res1["inputting"])
2022-07-25 10:17:37 +00:00
except:
guess_res1_ans = "尚未录入"
guess_res.extend([f"词组:{guess_res1_name}" + "\n释义:" + guess_res1_ans])
return "\n\n".join(guess_res)