2024-05-29 02:10:33 +08:00
|
|
|
|
import ujson as json
|
|
|
|
|
|
from nonebot.plugin import PluginMetadata
|
|
|
|
|
|
from nonebot_plugin_alconna import Alconna, Args, Arparma, on_alconna
|
|
|
|
|
|
from nonebot_plugin_session import EventSession
|
|
|
|
|
|
|
|
|
|
|
|
from zhenxun.configs.utils import PluginExtraData
|
|
|
|
|
|
from zhenxun.services.log import logger
|
|
|
|
|
|
from zhenxun.utils.http_utils import AsyncHttpx
|
2024-08-11 15:57:33 +08:00
|
|
|
|
from zhenxun.utils.message import MessageUtils
|
2024-05-29 02:10:33 +08:00
|
|
|
|
|
|
|
|
|
|
__plugin_meta__ = PluginMetadata(
|
|
|
|
|
|
name="能不能好好说话",
|
|
|
|
|
|
description="能不能好好说话,说人话",
|
|
|
|
|
|
usage="""
|
|
|
|
|
|
说人话
|
|
|
|
|
|
指令:
|
|
|
|
|
|
nbnhhsh [文本]
|
|
|
|
|
|
能不能好好说话 [文本]
|
2024-08-11 15:57:33 +08:00
|
|
|
|
示例:
|
|
|
|
|
|
nbnhhsh xsx
|
2024-05-29 02:10:33 +08:00
|
|
|
|
""".strip(),
|
|
|
|
|
|
extra=PluginExtraData(author="HibiKier", version="0.1", aliases={"nbnhhsh"}).dict(),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
URL = "https://lab.magiconch.com/api/nbnhhsh/guess"
|
|
|
|
|
|
|
|
|
|
|
|
_matcher = on_alconna(
|
|
|
|
|
|
Alconna("nbnhhsh", Args["text", str]),
|
|
|
|
|
|
aliases={"能不能好好说话"},
|
|
|
|
|
|
priority=5,
|
|
|
|
|
|
block=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@_matcher.handle()
|
|
|
|
|
|
async def _(session: EventSession, arparma: Arparma, text: str):
|
|
|
|
|
|
response = await AsyncHttpx.post(
|
|
|
|
|
|
URL,
|
|
|
|
|
|
data=json.dumps({"text": text}), # type: ignore
|
|
|
|
|
|
timeout=5,
|
|
|
|
|
|
headers={"content-type": "application/json"},
|
|
|
|
|
|
)
|
|
|
|
|
|
try:
|
|
|
|
|
|
data = response.json()
|
|
|
|
|
|
tmp = ""
|
|
|
|
|
|
result = ""
|
|
|
|
|
|
for x in data:
|
|
|
|
|
|
trans = ""
|
|
|
|
|
|
if x.get("trans"):
|
|
|
|
|
|
trans = x["trans"][0]
|
|
|
|
|
|
elif x.get("inputting"):
|
|
|
|
|
|
trans = ",".join(x["inputting"])
|
|
|
|
|
|
tmp += f'{x["name"]} -> {trans}\n'
|
|
|
|
|
|
result += trans
|
|
|
|
|
|
logger.info(
|
|
|
|
|
|
f" 发送能不能好好说话: {text} -> {result}",
|
|
|
|
|
|
arparma.header_result,
|
|
|
|
|
|
session=session,
|
|
|
|
|
|
)
|
2024-08-11 15:57:33 +08:00
|
|
|
|
await MessageUtils.build_message(f"{tmp}={result}").send(reply_to=True)
|
2024-05-29 02:10:33 +08:00
|
|
|
|
except (IndexError, KeyError):
|
2024-08-11 15:57:33 +08:00
|
|
|
|
await MessageUtils.build_message("没有找到对应的翻译....").send()
|