From bfa6896ef9bd5d4ec1576024447b9236ea29129f Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Wed, 29 May 2024 02:10:33 +0800 Subject: [PATCH] =?UTF-8?q?feat=E2=9C=A8:=20=E8=83=BD=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E5=A5=BD=E5=A5=BD=E8=AF=B4=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhenxun/plugins/nbnhhsh.py | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 zhenxun/plugins/nbnhhsh.py diff --git a/zhenxun/plugins/nbnhhsh.py b/zhenxun/plugins/nbnhhsh.py new file mode 100644 index 00000000..7c46d51e --- /dev/null +++ b/zhenxun/plugins/nbnhhsh.py @@ -0,0 +1,60 @@ +import ujson as json +from nonebot.plugin import PluginMetadata +from nonebot_plugin_alconna import Alconna, Args, Arparma, on_alconna +from nonebot_plugin_saa import Text +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 + +__plugin_meta__ = PluginMetadata( + name="能不能好好说话", + description="能不能好好说话,说人话", + usage=""" + 说人话 + 指令: + nbnhhsh [文本] + 能不能好好说话 [文本] + """.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, + ) + await Text(f"{tmp}={result}").send(reply=True) + except (IndexError, KeyError): + await Text("没有找到对应的翻译....").send()