mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-22 04:16:07 +00:00
Merge pull request #51 from hissincn/master
增加多适配器支持,用于ws通道冲突时可用http适配器
This commit is contained in:
@@ -3,3 +3,4 @@ config.py
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
database.db
|
database.db
|
||||||
qchatgpt.log
|
qchatgpt.log
|
||||||
|
config.py
|
||||||
+11
-2
@@ -3,11 +3,13 @@ import logging
|
|||||||
|
|
||||||
# [必需] Mirai的配置
|
# [必需] Mirai的配置
|
||||||
# 请到配置mirai的步骤中的教程查看每个字段的信息
|
# 请到配置mirai的步骤中的教程查看每个字段的信息
|
||||||
|
# adapter: 选择适配器,目前支持HTTPAdapter和WebSocketAdapter
|
||||||
# host: 运行mirai的主机地址
|
# host: 运行mirai的主机地址
|
||||||
# port: 运行mirai的主机端口
|
# port: 运行mirai的主机端口
|
||||||
# verifyKey: mirai-api-http的verifyKey
|
# verifyKey: mirai-api-http的verifyKey
|
||||||
# qq: 机器人的QQ号
|
# qq: 机器人的QQ号
|
||||||
mirai_http_api_config = {
|
mirai_http_api_config = {
|
||||||
|
"adapter": "HTTPAdapter",
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
"port": 8080,
|
"port": 8080,
|
||||||
"verifyKey": "yirimirai",
|
"verifyKey": "yirimirai",
|
||||||
@@ -28,9 +30,13 @@ openai_config = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
# 管理员QQ号,用于接收报错等通知,为0时不发送通知
|
# [可选] 机器人的配置
|
||||||
admin_qq = 0
|
#user_name: 管理员(主人)的名字
|
||||||
|
#bot_name: 机器人的名字
|
||||||
|
user_name = 'You'
|
||||||
|
bot_name = 'Bot'
|
||||||
|
|
||||||
|
# [可选] 情景预设(机器人人格)
|
||||||
# 每个会话的预设信息,影响所有会话,无视指令重置
|
# 每个会话的预设信息,影响所有会话,无视指令重置
|
||||||
# 可以通过这个字段指定某些情况的回复,可直接用自然语言描述指令
|
# 可以通过这个字段指定某些情况的回复,可直接用自然语言描述指令
|
||||||
# 例如: 如果我之后想获取帮助,请你说“输入!help获取帮助”,
|
# 例如: 如果我之后想获取帮助,请你说“输入!help获取帮助”,
|
||||||
@@ -38,6 +44,9 @@ admin_qq = 0
|
|||||||
# 可参考 https://github.com/PlexPt/awesome-chatgpt-prompts-zh
|
# 可参考 https://github.com/PlexPt/awesome-chatgpt-prompts-zh
|
||||||
default_prompt = "如果我之后想获取帮助,请你说“输入!help获取帮助”"
|
default_prompt = "如果我之后想获取帮助,请你说“输入!help获取帮助”"
|
||||||
|
|
||||||
|
# 管理员QQ号,用于接收报错等通知,为0时不发送通知
|
||||||
|
admin_qq = 0
|
||||||
|
|
||||||
# 群内响应规则
|
# 群内响应规则
|
||||||
# 符合此消息的群内消息即使不包含at机器人也会响应
|
# 符合此消息的群内消息即使不包含at机器人也会响应
|
||||||
# 支持消息前缀匹配及正则表达式匹配
|
# 支持消息前缀匹配及正则表达式匹配
|
||||||
|
|||||||
@@ -53,7 +53,9 @@ def dump_session(session_name: str):
|
|||||||
|
|
||||||
# 从配置文件获取会话预设信息
|
# 从配置文件获取会话预设信息
|
||||||
def get_default_prompt():
|
def get_default_prompt():
|
||||||
return "You:{}\nBot:好的\n".format(config.default_prompt) if hasattr(config, 'default_prompt') and \
|
user_name = config.user_name if hasattr(config, 'user_name') and config.user_name != '' else 'You'
|
||||||
|
bot_name = config.bot_name if hasattr(config, 'bot_name') and config.bot_name != '' else 'Bot'
|
||||||
|
return user_name+":{}\n"+bot_name+":好的\n".format(config.default_prompt) if hasattr(config, 'default_prompt') and \
|
||||||
config.default_prompt != "" else ''
|
config.default_prompt != "" else ''
|
||||||
|
|
||||||
|
|
||||||
@@ -81,8 +83,8 @@ class Session:
|
|||||||
|
|
||||||
prompt = get_default_prompt()
|
prompt = get_default_prompt()
|
||||||
|
|
||||||
user_name = 'You'
|
user_name = config.user_name if hasattr(config, 'user_name') and config.user_name != '' else 'You'
|
||||||
bot_name = 'Bot'
|
bot_name = config.bot_name if hasattr(config, 'bot_name') and config.bot_name != '' else 'Bot'
|
||||||
|
|
||||||
create_timestamp = 0
|
create_timestamp = 0
|
||||||
|
|
||||||
|
|||||||
+12
-2
@@ -4,7 +4,7 @@ import os
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
import openai.error
|
import openai.error
|
||||||
from mirai import At, GroupMessage, MessageEvent, Mirai, Plain, StrangerMessage, WebSocketAdapter, FriendMessage, Image
|
from mirai import At, GroupMessage, MessageEvent, Mirai, Plain, StrangerMessage, WebSocketAdapter,HTTPAdapter, FriendMessage, Image
|
||||||
|
|
||||||
import config
|
import config
|
||||||
import pkg.openai.session
|
import pkg.openai.session
|
||||||
@@ -73,7 +73,8 @@ class QQBotManager:
|
|||||||
else:
|
else:
|
||||||
self.reply_filter = pkg.qqbot.filter.ReplyFilter([])
|
self.reply_filter = pkg.qqbot.filter.ReplyFilter([])
|
||||||
|
|
||||||
bot = Mirai(
|
if mirai_http_api_config['adapter'] == "WebSocketAdapter":
|
||||||
|
bot = Mirai(
|
||||||
qq=mirai_http_api_config['qq'],
|
qq=mirai_http_api_config['qq'],
|
||||||
adapter=WebSocketAdapter(
|
adapter=WebSocketAdapter(
|
||||||
verify_key=mirai_http_api_config['verifyKey'],
|
verify_key=mirai_http_api_config['verifyKey'],
|
||||||
@@ -81,6 +82,15 @@ class QQBotManager:
|
|||||||
port=mirai_http_api_config['port']
|
port=mirai_http_api_config['port']
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
elif mirai_http_api_config['adapter'] == "HTTPAdapter":
|
||||||
|
bot = Mirai(
|
||||||
|
qq=mirai_http_api_config['qq'],
|
||||||
|
adapter=HTTPAdapter(
|
||||||
|
verify_key=mirai_http_api_config['verifyKey'],
|
||||||
|
host=mirai_http_api_config['host'],
|
||||||
|
port=mirai_http_api_config['port']
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@bot.on(FriendMessage)
|
@bot.on(FriendMessage)
|
||||||
async def on_friend_message(event: FriendMessage):
|
async def on_friend_message(event: FriendMessage):
|
||||||
|
|||||||
Reference in New Issue
Block a user