mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +08:00
feat✨: 能不能好好说话
This commit is contained in:
parent
091ae93731
commit
bfa6896ef9
60
zhenxun/plugins/nbnhhsh.py
Normal file
60
zhenxun/plugins/nbnhhsh.py
Normal file
@ -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()
|
||||||
Loading…
Reference in New Issue
Block a user