From 5966bfef73285fbcb523a6fa90bcb4d446969fff Mon Sep 17 00:00:00 2001 From: xtaodada Date: Thu, 29 Jul 2021 15:05:41 +0800 Subject: [PATCH] =?UTF-8?q?chatbot=20=E6=99=BA=E8=83=BD=E8=81=8A=E5=A4=A9?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chatbot.py | 35 +++++++++++++++++++++++++++++++++++ list.json | 10 ++++++++++ 2 files changed, 45 insertions(+) create mode 100644 chatbot.py diff --git a/chatbot.py b/chatbot.py new file mode 100644 index 0000000..0d2588c --- /dev/null +++ b/chatbot.py @@ -0,0 +1,35 @@ +import json, requests +from urllib.parse import quote +from pagermaid.listener import listener +from pagermaid.utils import alias_command, obtain_message, lang, clear_emojis + + +@listener(is_plugin=True, outgoing=True, command=alias_command("chatbot"), + description="使用自然语言处理 (NLP) 来帮助用户通过文本进行交互。(支持回复)", + parameters="<字符串>") +async def chatbot(context): + try: + text = await obtain_message(context) + except ValueError: + await context.edit(lang('msg_ValueError')) + return + text = clear_emojis(text) + text = quote(text) + + try: + req_data = requests.get(f"https://api.affiliateplus.xyz/api/chatbot?message={text}" + f"&botname=pagermaid&ownername=xtao-labs&user=20") + except Exception as e: + await context.edit('出错了呜呜呜 ~ 无法访问 API ') + return + if not req_data.status_code == 200: + return await context.edit('出错了呜呜呜 ~ 无法访问 API ') + + try: + req_data = json.loads(req_data.text) + req_data = req_data["message"] + except Exception as e: + await context.edit("出错了呜呜呜 ~ 解析JSON时发生了错误。") + return + + await context.edit(req_data) diff --git a/list.json b/list.json index 43bbceb..2770331 100644 --- a/list.json +++ b/list.json @@ -669,6 +669,16 @@ "supported": true, "des-short": "抽象话转换", "des": "把普通的话转换成抽象话" + }, + { + "name": "chatbot", + "version": "1.0", + "section": "chat", + "maintainer": "xtaodada", + "size": "1.2 kb", + "supported": true, + "des-short": "智能聊天机器人。(支持回复)", + "des": "使用自然语言处理 (NLP) 来帮助用户通过文本进行交互。(支持回复)。\n指令:-chatbot" } ] }