chatbot 智能聊天机器人

This commit is contained in:
xtaodada 2021-07-29 15:05:41 +08:00
parent 707c8114f3
commit 5966bfef73
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
2 changed files with 45 additions and 0 deletions

35
chatbot.py Normal file
View File

@ -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)

View File

@ -669,6 +669,16 @@
"supported": true, "supported": true,
"des-short": "抽象话转换", "des-short": "抽象话转换",
"des": "把普通的话转换成抽象话" "des": "把普通的话转换成抽象话"
},
{
"name": "chatbot",
"version": "1.0",
"section": "chat",
"maintainer": "xtaodada",
"size": "1.2 kb",
"supported": true,
"des-short": "智能聊天机器人。(支持回复)",
"des": "使用自然语言处理 (NLP) 来帮助用户通过文本进行交互。(支持回复)。\n指令-chatbot"
} }
] ]
} }