4 releases
new 0.1.3 | Jan 16, 2025 |
---|---|
0.1.2 | Jan 16, 2025 |
0.1.1 | Jan 16, 2025 |
0.1.0 | Jan 16, 2025 |
#585 in Web programming
67 downloads per month
89KB
2K
SLoC
Momo Bot
Momo Bot是基于Kovi框架的群助手。
kovi-plugin-live-agent = "0.1"
核心特性
- 持久化聊天记录(仅支持Sqlite)
- 群事件回应,包括龙王,加入群聊,离开群聊,禁言,设置管理员等播报
可选特性(禁用的方式为删除相关配置项)
-
哔哩哔哩直播间开播、下播通知
-
对聊天记录、消息时间、发送者有认知的OpenAI助理
- 回应艾特和戳一戳
-
自动上传聊天图片和语音到对象存储(自定义上传脚本,会在后文展开说明)
-
命令导出最近n条聊天记录或日志为csv,并回复上传文件url(需启用对象存储)
-
常用群命令
- 禁言机器人
- 取消禁言机器人
- 更换AI模型
- 导出最近N条日志
- 导出最近N条本群内消息记录
最少配置如下(仅记录聊天记录)
[global]
max_sleep_sec = 8
[database]
max_connections = 5
log_table_name = "bot_log"
group_table_prefix = "message"
max_sleep_sec = 8
: 所有的事件(除了聊天记录)都会在随机睡眠0到8秒后调用处理函数max_connections = 5
: Sqlite连接池的最大连接数log_table_name = "bot_log"
: 所有持久化的日志都会写入名为bot_log
的数据库表group_table_prefix = "message"
: 群号1234的日志会被写入名为message1234
的数据库表
初次启动时会生成一个完整配置模板,修改后重启即可
[global]
max_sleep_sec = 8
[database]
max_connections = 5
log_table_name = "bot_log"
group_table_prefix = "message"
[object_storage]
script_path = "/a/b/c"
[[groups]]
id = 12345678
[groups.live]
room_id = "12345678"
online_msg = "XX开播了"
offline_msg = "XX下播了"
query_message = "查询直播间"
poll_interval_sec = 60
[groups.agent]
api_url = "https://api.openai.com/v1/chat/completions"
api_key = "API KEY"
model = "chatgpt-4o-latest"
dev_prompt = """
You are a cute and smart catgirl with a strong anime-style personality.
You are the loyal attendant of 你的昵称 and participate in group chats with a playful and engaging demeanor.
Speak only in Mandarin Chinese, and ensure your responses are concise, limited to 4 sentences.
"""
user_prompt = """
Group Members:
<!members!>
Recent Chat History:
<!history!>
New message from someone you <!know!>:
<!message!>
Please respond to this new message in the tone of a playful and lively catgirl.
Speak only in Mandarin Chinese, keep your response under 4 sentences, and stay in character.
"""
aware_history_segments = 30
[groups.agent.known_members]
12345678 = [
"你的昵称",
"你的主人",
]
23456789 = [
"张三",
"你的敌人",
]
[groups.command]
mute = "禁用聊天回复"
unmute = "启用聊天回复"
switch_model = "更换模型"
dump_history = "最近聊天记录"
dump_log = "最近日志"
admin_ids = [
1234,
5678,
]
[[groups]]
id = 12345678
[groups.live]
room_id = "12345678"
online_msg = "XX开播了"
offline_msg = "XX下播了"
query_message = "查询直播间"
poll_interval_sec = 60
[groups.agent]
api_url = "https://api.openai.com/v1/chat/completions"
api_key = "API KEY"
model = "chatgpt-4o-latest"
dev_prompt = """
You are a cute and smart catgirl with a strong anime-style personality.
You are the loyal attendant of 你的昵称 and participate in group chats with a playful and engaging demeanor.
Speak only in Mandarin Chinese, and ensure your responses are concise, limited to 4 sentences.
"""
user_prompt = """
Group Members:
<!members!>
Recent Chat History:
<!history!>
New message from someone you <!know!>:
<!message!>
Please respond to this new message in the tone of a playful and lively catgirl.
Speak only in Mandarin Chinese, keep your response under 4 sentences, and stay in character.
"""
aware_history_segments = 30
[groups.agent.known_members]
23456789 = [
"张三",
"你的敌人",
]
12345678 = [
"你的昵称",
"你的主人",
]
[groups.command]
mute = "禁用聊天回复"
unmute = "启用聊天回复"
switch_model = "更换模型"
dump_history = "最近聊天记录"
dump_log = "最近日志"
admin_ids = [
1234,
5678,
]
script_path = "/a/b/c"
: 导出命令、写入图片或语音类型群消息历史记录时被调用的可执行文件路径- 插件会将文件的路径作为第一个命令行参数传入
- 插件会收集标准输出并存入数据库(历史记录)或发送到群聊(导出命令)
- 当配置的可执行文件运行失败时,插件会收集标准错误并保存到日志
- 后文包含了一个示例脚本
groups
id = 12345678
: QQ群号为12345678live
room_id = "12345678"
: 哔哩哔哩直播间号为12345678online_msg = "XX开播了"
: 开播时会播报的信息前缀offline_msg = "XX下播了"
: 下播时会播报的信息前缀- 开播和下播通知会包含直播间标题,简介,热度,关注,关键帧或封面
query_message = "查询直播间"
: 在本群内发送“查询直播间”时回复本群主播的直播间信息poll_interval_sec = 60
: 每60秒轮询一次直播间状态
agent
api_url = "https://api.openai.com/v1/chat/completions"
: 不要改,目前仅支持OpenAI,配置留作后续可能支持的其他语言模型厂商api_key = "API KEY"
: OpenAI的密钥model = "chatgpt-4o-latest"
: 仅支持如下几个模型- gpt-4o
- chatgpt-4o-latest
- gpt-4o-mini
- o1-mini
- o1-preview
dev_prompt
,user_prompt
- 运行期插件会自动使用相应信息替换占位符
<!members!>
: 配置的known_members
<!history!>
: 从数据库读取的历史记录<!message!>
: 用户艾特时发送的信息<!know!>
: 用户是否在known_members
记录中- 会展开为"know/don't know"
- 运行期插件会自动使用相应信息替换占位符
aware_history_segments
: 对话时读取的消息记录,单位是Segment
而不是Message
,即一个对话框内每一种消息占用一个位置
command
: 插件运行时会在标准输出日志内包含每一个命令的正则表达式mute = "禁用聊天回复"
: 后面不跟参数unmute = "启用聊天回复"
: 后面不跟参数switch_model = "更换模型"
: 发送更换模型 o1-preview
更换模型为o1-preview
或其他前文提到的支持模型dump_history = "最近聊天记录"
: 发送最近聊天记录 N
调取N个记录dump_log = "最近日志"
: 发送最近日志 N
调取N个记录admin_ids = [1234, 5678]
: 仅QQ号为1234或5678的人有权限调用命令
在默认的配置下,匹配的命令正则如下
mute: 禁用聊天回复
unmute: 启用聊天回复
switch_model: 更换模型\s+(?<model>gpt4o|chatgpt-4o-latest|gpt-4o-mini|o1-mini|o1-preview)
dump_history: 最近聊天记录\s+(?<count>\d+)
dump_log: 最近日志\s+(?<count>\d+)
示例上传脚本
#!/usr/bin/env bash
if [ $# -lt 1 ]; then
echo "ERROR: upload.sh missing args"
exit 1
fi
SOURCE_FILE="$1"
FILE_NAME="$(basename "$SOURCE_FILE")"
EXTENSION="${FILE_NAME##*.}"
NEW_NAME="$(cat /proc/sys/kernel/random/uuid).$EXTENSION"
BUCKET="YOUR_BUCKET"
REGION="YOUR_REGION"
sudo cp "$SOURCE_FILE" "./$NEW_NAME"
sudo chown "$(whoami):" "./$NEW_NAME"
aws s3 cp "./$NEW_NAME" "s3://$BUCKET" > /dev/null
rm "./$NEW_NAME"
echo -n "https://${BUCKET}.s3.${REGION}.amazonaws.com/${NEW_NAME}"
表结构
bot_log
- time: ISO8601 时间,
YYYY-MM-DD HH:MM:SS
- level: DEBUG, INFO, WARN, ERROR
- content: 日志内容
message_table_prefix_XXXXXXX
- message_id: 消息id,详情参考Onebot v11文档
- time: ISO8601 时间,
YYYY-MM-DD HH:MM:SS
- sender_id: 发送者qq号
- sender_name: 发送者名称,优先级从高到低为 配置文件、群昵称,用户昵称,qq号
- type: Segment type,详情参考Onebot v11文档
- content: 原始Onebot Json返回的内容,图片和语音会被替换成本地路径
- interpret: 当类型是图片或语音时为上传后的url,其余情况下为附带信息
Dependencies
~40–56MB
~1M SLoC