alemonjs-aichat 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/lib/api.js +0 -292
- package/lib/assets/113574575_p0_master1200-BncvWC99.jpg +0 -0
- package/lib/assets/113574575_p0_master1200.jpg.js +0 -4
- package/lib/assets/main.css-DlHMK5k-.css +0 -1
- package/lib/assets/main.css.js +0 -4
- package/lib/config.js +0 -231
- package/lib/data/help.json.js +0 -115
- package/lib/emoji.js +0 -120
- package/lib/image/conponent/help.js +0 -51
- package/lib/index.js +0 -9
- package/lib/middleware/mw.js +0 -89
- package/lib/redis.js +0 -12
- package/lib/response/affection/res.js +0 -33
- package/lib/response/config/res.js +0 -44
- package/lib/response/help/res.js +0 -23
- package/lib/response/setting/res.js +0 -212
- package/lib/response/zreply/res.js +0 -322
- package/lib/s3.js +0 -96
- package/lib/types.js +0 -1
package/lib/emoji.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
const emojiMap = {
|
|
2
|
-
4: "得意",
|
|
3
|
-
5: "流泪",
|
|
4
|
-
8: "睡",
|
|
5
|
-
9: "大哭",
|
|
6
|
-
10: "尴尬",
|
|
7
|
-
12: "调皮",
|
|
8
|
-
14: "微笑",
|
|
9
|
-
16: "酷",
|
|
10
|
-
21: "可爱",
|
|
11
|
-
23: "傲慢",
|
|
12
|
-
24: "饥饿",
|
|
13
|
-
25: "困",
|
|
14
|
-
26: "惊恐",
|
|
15
|
-
27: "流汗",
|
|
16
|
-
28: "憨笑",
|
|
17
|
-
29: "悠闲",
|
|
18
|
-
30: "奋斗",
|
|
19
|
-
32: "疑问",
|
|
20
|
-
33: "嘘",
|
|
21
|
-
34: "晕",
|
|
22
|
-
38: "敲打",
|
|
23
|
-
39: "再见",
|
|
24
|
-
41: "发抖",
|
|
25
|
-
42: "爱情",
|
|
26
|
-
43: "跳跳",
|
|
27
|
-
49: "拥抱",
|
|
28
|
-
53: "蛋糕",
|
|
29
|
-
60: "咖啡",
|
|
30
|
-
63: "玫瑰",
|
|
31
|
-
66: "爱心",
|
|
32
|
-
74: "太阳",
|
|
33
|
-
75: "月亮",
|
|
34
|
-
76: "赞",
|
|
35
|
-
78: "握手",
|
|
36
|
-
79: "胜利",
|
|
37
|
-
85: "飞吻",
|
|
38
|
-
89: "西瓜",
|
|
39
|
-
96: "冷汗",
|
|
40
|
-
97: "擦汗",
|
|
41
|
-
98: "抠鼻",
|
|
42
|
-
99: "鼓掌",
|
|
43
|
-
100: "糗大了",
|
|
44
|
-
101: "坏笑",
|
|
45
|
-
102: "左哼哼",
|
|
46
|
-
103: "右哼哼",
|
|
47
|
-
104: "哈欠",
|
|
48
|
-
106: "委屈",
|
|
49
|
-
109: "左亲亲",
|
|
50
|
-
111: "可怜",
|
|
51
|
-
116: "示爱",
|
|
52
|
-
118: "抱拳",
|
|
53
|
-
120: "拳头",
|
|
54
|
-
122: "爱你",
|
|
55
|
-
123: "NO",
|
|
56
|
-
124: "OK",
|
|
57
|
-
125: "转圈",
|
|
58
|
-
129: "挥手",
|
|
59
|
-
144: "喝彩",
|
|
60
|
-
147: "棒棒糖",
|
|
61
|
-
171: "茶",
|
|
62
|
-
173: "泪奔",
|
|
63
|
-
174: "无奈",
|
|
64
|
-
175: "卖萌",
|
|
65
|
-
176: "小纠结",
|
|
66
|
-
179: "doge",
|
|
67
|
-
180: "惊喜",
|
|
68
|
-
181: "骚扰",
|
|
69
|
-
182: "笑哭",
|
|
70
|
-
183: "我最美",
|
|
71
|
-
201: "点赞",
|
|
72
|
-
203: "托脸",
|
|
73
|
-
212: "托腮",
|
|
74
|
-
214: "啵啵",
|
|
75
|
-
219: "蹭一蹭",
|
|
76
|
-
222: "抱抱",
|
|
77
|
-
227: "拍手",
|
|
78
|
-
232: "佛系",
|
|
79
|
-
240: "喷脸",
|
|
80
|
-
243: "甩头",
|
|
81
|
-
246: "加油抱抱",
|
|
82
|
-
262: "脑阔疼",
|
|
83
|
-
264: "捂脸",
|
|
84
|
-
265: "辣眼睛",
|
|
85
|
-
266: "哦哟",
|
|
86
|
-
267: "头秃",
|
|
87
|
-
268: "问号脸",
|
|
88
|
-
269: "暗中观察",
|
|
89
|
-
270: "emm",
|
|
90
|
-
271: "吃瓜",
|
|
91
|
-
272: "呵呵哒",
|
|
92
|
-
273: "我酸了",
|
|
93
|
-
277: "汪汪",
|
|
94
|
-
278: "汗",
|
|
95
|
-
281: "无眼笑",
|
|
96
|
-
282: "敬礼",
|
|
97
|
-
284: "面无表情",
|
|
98
|
-
285: "摸鱼",
|
|
99
|
-
287: "哦",
|
|
100
|
-
289: "睁眼",
|
|
101
|
-
290: "敲开心",
|
|
102
|
-
293: "摸锦鲤",
|
|
103
|
-
294: "期待",
|
|
104
|
-
297: "拜谢",
|
|
105
|
-
298: "元宝",
|
|
106
|
-
299: "牛啊",
|
|
107
|
-
305: "右亲亲",
|
|
108
|
-
306: "牛气冲天",
|
|
109
|
-
307: "喵喵",
|
|
110
|
-
314: "仔细分析",
|
|
111
|
-
315: "加油",
|
|
112
|
-
318: "崇拜",
|
|
113
|
-
319: "比心",
|
|
114
|
-
320: "庆祝",
|
|
115
|
-
322: "拒绝",
|
|
116
|
-
324: "吃糖",
|
|
117
|
-
326: "生气",
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export { emojiMap };
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import fileUrl from '../../assets/main.css.js';
|
|
3
|
-
import help from '../../data/help.json.js';
|
|
4
|
-
import { LinkStyleSheet } from 'jsxp';
|
|
5
|
-
import fileUrl$1 from '../../assets/113574575_p0_master1200.jpg.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @param param0
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
function App() {
|
|
12
|
-
return (React.createElement("html", null,
|
|
13
|
-
React.createElement("head", null,
|
|
14
|
-
React.createElement(LinkStyleSheet, { src: fileUrl })),
|
|
15
|
-
React.createElement("body", { className: "bg-cover p-4", style: { backgroundImage: `url(${fileUrl$1})` } },
|
|
16
|
-
React.createElement("h2", { className: "text-2xl text-white font-bold italic drop-shadow-md" }, help.title),
|
|
17
|
-
React.createElement("div", { className: "flex gap-2 mb-4 text-white italic drop-shadow-md" },
|
|
18
|
-
React.createElement("span", { className: "text-[#e8deba] " },
|
|
19
|
-
help.name,
|
|
20
|
-
" ",
|
|
21
|
-
help.version),
|
|
22
|
-
" ",
|
|
23
|
-
React.createElement("span", { className: "text-gray-400" }, "by"),
|
|
24
|
-
" ",
|
|
25
|
-
React.createElement("span", { className: "text-[#e8deba] " }, help.by)),
|
|
26
|
-
help.list.map((item, index) => (React.createElement("div", { key: index, className: " border-b last:border-0 bg-black/60 rounded-lg overflow-hidden mb-4 text-white backdrop-blur-xs" },
|
|
27
|
-
React.createElement("h2", { className: "p-4 text-lg font-semibold bg-black/30 border-b border-white/20" }, item.group.title),
|
|
28
|
-
React.createElement("div", null, Array.from({
|
|
29
|
-
length: Math.ceil(item.group.items.length / 3),
|
|
30
|
-
}).map((_, rowIndex) => {
|
|
31
|
-
const rowItems = item.group.items.slice(rowIndex * 3, rowIndex * 3 + 3);
|
|
32
|
-
return (React.createElement("div", { key: rowIndex, className: `flex flex-wrap ${rowIndex % 2 === 1 ? "bg-black/30" : ""}` }, Array.from({ length: 3 }).map((_, subIndex) => {
|
|
33
|
-
const subItem = rowItems[subIndex];
|
|
34
|
-
// 判断是否为最后一列
|
|
35
|
-
const isLastCol = subIndex === 2;
|
|
36
|
-
// 判断是否为最后一行
|
|
37
|
-
const isLastRow = rowIndex === Math.ceil(item.group.items.length / 3) - 1;
|
|
38
|
-
if (subItem) {
|
|
39
|
-
return (React.createElement("div", { key: subIndex, className: `w-1/3 p-4 box-border${isLastCol ? "" : " border-r border-white/20"}${isLastRow ? "" : " border-b border-white/20"}` },
|
|
40
|
-
React.createElement("div", { className: "text-[#B8AE8E] font-bold text-lg" }, subItem.cmd),
|
|
41
|
-
React.createElement("div", null, subItem.desc)));
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
// 空白格子
|
|
45
|
-
return (React.createElement("div", { key: subIndex, className: `w-1/3 p-2 box-border${isLastCol ? "" : " border-r border-white/20"}${isLastRow ? "" : " border-b border-white/20"}` }));
|
|
46
|
-
}
|
|
47
|
-
})));
|
|
48
|
-
}))))))));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export { App as default };
|
package/lib/index.js
DELETED
package/lib/middleware/mw.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { useClient } from 'alemonjs';
|
|
2
|
-
import { API } from '@alemonjs/onebot';
|
|
3
|
-
|
|
4
|
-
const selects = onSelects(["message.create", "private.message.create"]);
|
|
5
|
-
// 中间件
|
|
6
|
-
var mw = onMiddleware(selects, async (event, next) => {
|
|
7
|
-
// const config = getConfigValue();
|
|
8
|
-
// 新增字段
|
|
9
|
-
event["user_id"] = event.UserId; // 用户QQ号
|
|
10
|
-
event["msg"] = event.MessageText; // 消息内容
|
|
11
|
-
event["guid"] = event.ChannelId ?? event.UserId; // 群号或用户QQ号
|
|
12
|
-
event["uidkey"] = `${event["guid"]}:${event.UserName}(${event.UserId})`; // 唯一标识
|
|
13
|
-
event["nickname"] = `${event.UserName}(${event.UserId})`; // 昵称(用户名+QQ号)
|
|
14
|
-
// console.log('event["nickname"]', event["nickname"]);
|
|
15
|
-
// console.log("event.IsMaster", event.UserId, config.master_id, event.IsMaster);
|
|
16
|
-
if (event.Platform == "testone") {
|
|
17
|
-
// 处理图片消息
|
|
18
|
-
event["img"] = event.value
|
|
19
|
-
.filter((item) => item.type === "image" || item.type === "Image")
|
|
20
|
-
.map((item) => item.value);
|
|
21
|
-
// 处理at消息
|
|
22
|
-
event["at"] = event.value
|
|
23
|
-
.filter((item) => item.type === "at" || item.type === "Mention")
|
|
24
|
-
.map((item) => ({
|
|
25
|
-
type: "at",
|
|
26
|
-
data: { qq: item.value, nickname: item.options.name },
|
|
27
|
-
}));
|
|
28
|
-
// 是否at机器人
|
|
29
|
-
event["atBot"] = event["at"].find((item) => item.data.qq.toString() === "794161769");
|
|
30
|
-
// 模拟机器人信息
|
|
31
|
-
event["bot"] = {
|
|
32
|
-
nickname: "小咸鱼",
|
|
33
|
-
user_id: "794161769",
|
|
34
|
-
};
|
|
35
|
-
// 判断event.value是否为数组
|
|
36
|
-
if (Array.isArray(event.value)) {
|
|
37
|
-
event["originalMsg"] = event.value; // 原始消息内容
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
// onebot平台特有处理 //
|
|
41
|
-
if (event.Platform == "onebot") {
|
|
42
|
-
// 获取客户端
|
|
43
|
-
const [client] = useClient(event, API);
|
|
44
|
-
// 获取群成员存入redis
|
|
45
|
-
const botInfo = await client.getLoginInfo();
|
|
46
|
-
event["self_id"] = event.value.self_id; // 机器人QQ号
|
|
47
|
-
event["originalMsg"] = event.value.message; // 原始消息内容
|
|
48
|
-
// 处理at消息
|
|
49
|
-
event["at"] = await Promise.all(event.value.message
|
|
50
|
-
.filter((item) => item.type === "at")
|
|
51
|
-
.map(async (item) => {
|
|
52
|
-
const atInfo = await client.send({
|
|
53
|
-
action: "get_stranger_info",
|
|
54
|
-
params: { user_id: item.data.qq, no_cache: true },
|
|
55
|
-
});
|
|
56
|
-
return {
|
|
57
|
-
type: "at",
|
|
58
|
-
data: { qq: item.data.qq, nickname: atInfo[0].data.nickname },
|
|
59
|
-
};
|
|
60
|
-
}));
|
|
61
|
-
console.log('event["at"]', event["at"]);
|
|
62
|
-
// 是否at机器人
|
|
63
|
-
event["atBot"] = event["at"].find((item) => item.data.qq == event.self_id);
|
|
64
|
-
// 处理图片消息
|
|
65
|
-
event["img"] = event.value.message
|
|
66
|
-
.filter((item) => item.type === "image" || item.type === "Image")
|
|
67
|
-
.map((item) => item.data.url);
|
|
68
|
-
// 判断是否为群管理员
|
|
69
|
-
event["isAdmin"] =
|
|
70
|
-
event.value.sender.role === "admin" ||
|
|
71
|
-
event.value.sender.role === "owner";
|
|
72
|
-
event["bot"] = botInfo[0].data; // 机器人信息
|
|
73
|
-
// 处理回复消息
|
|
74
|
-
const replyData = event.value.message.find((item) => item.type === "reply");
|
|
75
|
-
if (replyData) {
|
|
76
|
-
const msg = await client.getMsg({
|
|
77
|
-
message_id: Number(replyData.data.id),
|
|
78
|
-
});
|
|
79
|
-
console.log("msg[0].data;", JSON.stringify(msg[0].data, null, 2));
|
|
80
|
-
if (msg && msg[0] && msg[0].data) {
|
|
81
|
-
event["reply"] = msg[0].data;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// 常用于兼容其他框架或增强event功能
|
|
86
|
-
next();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
export { mw as default };
|
package/lib/redis.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { getConfigValue } from 'alemonjs';
|
|
2
|
-
import Redis from 'ioredis';
|
|
3
|
-
|
|
4
|
-
const value = getConfigValue();
|
|
5
|
-
const redisConfig = {
|
|
6
|
-
host: value.redis?.host ?? "localhost",
|
|
7
|
-
port: value.redis?.port ?? 6379,
|
|
8
|
-
password: value.redis?.password ?? "",
|
|
9
|
-
};
|
|
10
|
-
const redis = new Redis(redisConfig);
|
|
11
|
-
|
|
12
|
-
export { redis };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { getAffectionLevel, resetAllAffectionLevels, resetAffectionLevel } from '../../config.js';
|
|
2
|
-
import { useMessage, Text } from 'alemonjs';
|
|
3
|
-
import { Regular } from 'alemonjs/utils';
|
|
4
|
-
|
|
5
|
-
const selects = onSelects(["message.create", "private.message.create"]);
|
|
6
|
-
const regular$1 = /(\/|#)(查看)?好感度?$/i;
|
|
7
|
-
const regular$2 = /(\/|#)(重置|清空)(全部|所有)?好感度?$/i;
|
|
8
|
-
const regular = Regular.or(regular$1, regular$2);
|
|
9
|
-
var res = onResponse(selects, async (e, next) => {
|
|
10
|
-
// 创建
|
|
11
|
-
const [message] = useMessage(e);
|
|
12
|
-
// 查看好感度
|
|
13
|
-
if (regular$1.test(e.msg)) {
|
|
14
|
-
const affections = await getAffectionLevel(e.uidkey);
|
|
15
|
-
message.send(format(Text(`当前用户\`${e.UserName}\`的好感度为: ${affections}。`)));
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
// 重置好感度
|
|
19
|
-
if (regular$2.test(e.msg)) {
|
|
20
|
-
if ((e.msg.includes("全部") && e.IsMaster) ||
|
|
21
|
-
(e.msg.includes("所有") && e.IsMaster)) {
|
|
22
|
-
await resetAllAffectionLevels();
|
|
23
|
-
message.send(format(Text(`已重置所有用户的好感度。`)));
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
await resetAffectionLevel(e.uidkey);
|
|
27
|
-
message.send(format(Text(`已重置用户\`${e.UserName}\`的好感度。`)));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
next();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
export { res as default, regular, selects };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { getAIConfig, getAIList, getPromptList, clearAIChatHistory } from '../../config.js';
|
|
2
|
-
import { useMessage, Text } from 'alemonjs';
|
|
3
|
-
import { Regular } from 'alemonjs/utils';
|
|
4
|
-
|
|
5
|
-
const selects = onSelects(["message.create", "private.message.create"]);
|
|
6
|
-
const regular$1 = /(\/|#)(ai配置|当前提示词|查看提示词)?$/i;
|
|
7
|
-
const regular$2 = /(\/|#)ai列表$/i;
|
|
8
|
-
const regular$3 = /(\/|#)提示词列表$/i;
|
|
9
|
-
const regular$4 = /(\/|#)清空对话$/i;
|
|
10
|
-
const regular$5 = /(\/|#)清空(所有|全部)对话$/i;
|
|
11
|
-
const regular = Regular.or(regular$1, regular$2, regular$3, regular$4, regular$5);
|
|
12
|
-
var res = onResponse(selects, async (e, next) => {
|
|
13
|
-
// 创建
|
|
14
|
-
const [message] = useMessage(e);
|
|
15
|
-
const config = await getAIConfig(e.guid);
|
|
16
|
-
// 查看AI配置
|
|
17
|
-
if (regular$1.test(e.msg)) {
|
|
18
|
-
// 发送消息
|
|
19
|
-
message.send(format(Text(`当前AI配置:\n`), Text(`模型: ${config.model}\n`), Text(`提示词: ${config.systemPrompt}`)));
|
|
20
|
-
}
|
|
21
|
-
// 查看AI列表
|
|
22
|
-
if (regular$2.test(e.msg)) {
|
|
23
|
-
const ailist = await getAIList();
|
|
24
|
-
message.send(format(Text("当前AI列表:\n"), Text(ailist.length ? ailist.join("\n") : "暂无AI配置")));
|
|
25
|
-
}
|
|
26
|
-
// 查看提示词列表
|
|
27
|
-
if (regular$3.test(e.msg)) {
|
|
28
|
-
const prompts = await getPromptList();
|
|
29
|
-
message.send(format(Text("当前提示词列表:\n"), Text(prompts.length ? prompts.join("\n") : "暂无提示词")));
|
|
30
|
-
}
|
|
31
|
-
// 清空对话
|
|
32
|
-
if (regular$4.test(e.msg)) {
|
|
33
|
-
await clearAIChatHistory(e.guid);
|
|
34
|
-
message.send(format(Text("对话已清空")));
|
|
35
|
-
}
|
|
36
|
-
// 清空所有对话
|
|
37
|
-
if (regular$5.test(e.msg) && e.IsMaster) {
|
|
38
|
-
await clearAIChatHistory();
|
|
39
|
-
message.send(format(Text("所有对话已清空")));
|
|
40
|
-
}
|
|
41
|
-
next();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
export { res as default, regular, selects };
|
package/lib/response/help/res.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { getAIConfig } from '../../config.js';
|
|
2
|
-
import { useMessage, Image, Text } from 'alemonjs';
|
|
3
|
-
import { renderComponentToBuffer } from 'jsxp';
|
|
4
|
-
import App from '../../image/conponent/help.js';
|
|
5
|
-
|
|
6
|
-
const selects = onSelects(["message.create", "private.message.create"]);
|
|
7
|
-
const regular = /(\/|#)(ai)?(指令|帮助|菜单|功能)$/i;
|
|
8
|
-
var res = onResponse(selects, async (e) => {
|
|
9
|
-
// 创建
|
|
10
|
-
const [message] = useMessage(e);
|
|
11
|
-
const img = await renderComponentToBuffer("help", App, {});
|
|
12
|
-
if (img)
|
|
13
|
-
message.send(format(Image(img)));
|
|
14
|
-
const config = await getAIConfig(e.guid);
|
|
15
|
-
if (config.host.trim() === "" ||
|
|
16
|
-
config.key.trim() === "" ||
|
|
17
|
-
config.model.trim() === "") {
|
|
18
|
-
message.send(format(Text("当前配置不完整,请使用 /切换ai 指令切换到可用的配置")));
|
|
19
|
-
}
|
|
20
|
-
return;
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export { res as default, regular, selects };
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { addAI, switchAI, addPrompt, deletePrompt, switchPrompt, deleteAI, affectionSwitch, getAIList, getAIConfig } from '../../config.js';
|
|
2
|
-
import { redis } from '../../redis.js';
|
|
3
|
-
import { uploadImageToR2 } from '../../s3.js';
|
|
4
|
-
import { useMessage, Text } from 'alemonjs';
|
|
5
|
-
import { Regular } from 'alemonjs/utils';
|
|
6
|
-
|
|
7
|
-
const selects = onSelects(["message.create", "private.message.create"]);
|
|
8
|
-
const regular$1 = /(\/|#)添加ai$/i;
|
|
9
|
-
const regular$2 = /(\/|#)添加ai\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/i;
|
|
10
|
-
const regular$3 = /(\/|#)(切换)(ai|配置) ?(.*)/i;
|
|
11
|
-
const regular$4 = /(\/|#)添加提示词$/i;
|
|
12
|
-
const regular$5 = /(\/|#)添加提示词 (\S+) ([\s\S]+)/i;
|
|
13
|
-
const regular$6 = /(\/|#)(删除)(提示词|提示词列表) ?(.*)/i;
|
|
14
|
-
const regular$7 = /(\/|#)(切换|设置)提示词 ?(.*)$/i;
|
|
15
|
-
const regular$8 = /(\/|#)清空提示词$/i;
|
|
16
|
-
const regular$10 = /(\/|#)删除ai\s(\S+)$/i;
|
|
17
|
-
const regular$11 = /(\/|#)(开启|启用|关闭|禁用)好感度$/i;
|
|
18
|
-
const regular$13 = /(\/|#)(开启|关闭)聊天$/i;
|
|
19
|
-
const regular$14 = /(\/|#)(开启|关闭)语音回复$/i;
|
|
20
|
-
const regular$15 = /(\/|#)(开启|关闭)工具$/i;
|
|
21
|
-
const test = /(\/|#)测试$/i;
|
|
22
|
-
const regular = Regular.or(regular$1, regular$2, regular$3, regular$4, regular$5, regular$6, regular$7, regular$8, regular$10, regular$11, regular$13, regular$14);
|
|
23
|
-
var res = onResponse(selects, async (e, next) => {
|
|
24
|
-
// 创建
|
|
25
|
-
const [message] = useMessage(e);
|
|
26
|
-
// 测试
|
|
27
|
-
if (test.test(e.msg)) {
|
|
28
|
-
uploadImageToR2("./public/image_out/1769259547338.jpg").then((url) => {
|
|
29
|
-
console.log("上传成功,图片URL:", url);
|
|
30
|
-
});
|
|
31
|
-
// message.send(
|
|
32
|
-
// format(
|
|
33
|
-
// Text("测试消息"),
|
|
34
|
-
// ImageFile("./public/image_out/1769257917858.jpg"),
|
|
35
|
-
// ),
|
|
36
|
-
// );
|
|
37
|
-
// const a = await availableTools.StableDiffusionGenerateImage({
|
|
38
|
-
// prompt: "a cat playing with a ball",
|
|
39
|
-
// });
|
|
40
|
-
// if (a.length > 0) {
|
|
41
|
-
// message.send(format(ImageFile(a[0].url)));
|
|
42
|
-
// }
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
// 添加AI配置
|
|
46
|
-
if (regular$1.test(e.msg)) {
|
|
47
|
-
message.send(format(Text("请按照 格式:/添加ai <名称> <主机地址> <api_key> <模型> 进行添加")));
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
// 处理添加AI配置
|
|
51
|
-
if (regular$2.test(e.msg)) {
|
|
52
|
-
const match = e.msg.match(regular$2);
|
|
53
|
-
if (!match) {
|
|
54
|
-
message.send(format(Text("格式错误,请按照 格式:/添加ai <名称> <主机地址> <api_key> <模型> 进行添加")));
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const [, , name, host, key, model] = match;
|
|
58
|
-
await addAI(e.guid, name, host, key, model);
|
|
59
|
-
message.send(format(Text(`AI ${name} 添加成功!`)));
|
|
60
|
-
}
|
|
61
|
-
// 切换AI配置
|
|
62
|
-
if (regular$3.test(e.msg)) {
|
|
63
|
-
const match = e.msg.match(regular$3);
|
|
64
|
-
if (!match) {
|
|
65
|
-
message.send(format(Text("格式错误,请按照 格式:/切换ai <名称> 进行切换")));
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const [, , , , name] = match;
|
|
69
|
-
const ai = await switchAI(e.guid, name.trim());
|
|
70
|
-
if (!ai) {
|
|
71
|
-
message.send(format(Text(`切换失败,未找到 AI ${name} !`)));
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
message.send(format(Text(`已切换到 AI ${name} !`), Text(`\n模型: ${ai.model}`)));
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
// 添加提示词
|
|
78
|
-
if (regular$4.test(e.msg)) {
|
|
79
|
-
message.send(format(Text("请按照 格式:/添加提示词 <名称> <内容> 进行添加")));
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
// 处理添加提示词
|
|
83
|
-
if (regular$5.test(e.msg)) {
|
|
84
|
-
const match = e.msg.match(regular$5);
|
|
85
|
-
if (!match) {
|
|
86
|
-
message.send(format(Text("格式错误,请按照 格式:/添加提示词 <名称> <内容> 进行添加")));
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const [, , name, content] = match;
|
|
90
|
-
await addPrompt(name, content);
|
|
91
|
-
message.send(format(Text(`提示词 ${name} 添加成功!`)));
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
// 删除提示词
|
|
95
|
-
if (regular$6.test(e.msg)) {
|
|
96
|
-
const match = e.msg.match(regular$6);
|
|
97
|
-
if (!match) {
|
|
98
|
-
message.send(format(Text("格式错误,请按照 格式:/删除提示词 <名称> 进行删除")));
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const [, , , , name] = match;
|
|
102
|
-
await deletePrompt(name);
|
|
103
|
-
message.send(format(Text(`提示词 ${name} 删除成功!`)));
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
// 切换提示词
|
|
107
|
-
if (regular$7.test(e.msg)) {
|
|
108
|
-
const match = e.msg.match(regular$7);
|
|
109
|
-
if (!match) {
|
|
110
|
-
message.send(format(Text("格式错误,请按照 格式:/切换提示词 <名称> 进行切换")));
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const [, , , name] = match;
|
|
114
|
-
const prompt = await switchPrompt(e.guid, name);
|
|
115
|
-
message.send(format(Text(`已切换到提示词 ${name} !\n`), Text(prompt || "")));
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
// 清空提示词
|
|
119
|
-
if (regular$8.test(e.msg)) {
|
|
120
|
-
await switchPrompt(e.guid, "");
|
|
121
|
-
message.send(format(Text("已清空提示词 !")));
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
// 删除AI配置
|
|
125
|
-
if (regular$10.test(e.msg)) {
|
|
126
|
-
const match = e.msg.match(regular$10);
|
|
127
|
-
if (!match) {
|
|
128
|
-
message.send(format(Text("格式错误,请按照 格式:/删除ai <名称> 进行删除")));
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const [, , name] = match;
|
|
132
|
-
const success = await deleteAI(name.trim());
|
|
133
|
-
if (!success) {
|
|
134
|
-
message.send(format(Text(`删除失败,未找到 AI ${name} !`)));
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
message.send(format(Text(`AI ${name} 删除成功 !`)));
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
// 设置好感度开关
|
|
141
|
-
if (regular$11.test(e.msg)) {
|
|
142
|
-
const match = e.msg.match(regular$11);
|
|
143
|
-
if (!match) {
|
|
144
|
-
message.send(format(Text("格式错误,请按照 格式:/开启好感度 或 /关闭好感度 进行设置")));
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
const [, , action] = match;
|
|
148
|
-
const enable = action === "开启" || action === "启用";
|
|
149
|
-
await affectionSwitch(e.guid, enable);
|
|
150
|
-
message.send(format(Text(`已${enable ? "开启" : "关闭"}好感度功能 !`)));
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
// 设置聊天开关 ,发送开启聊天时, 获取ai列表的第一个ai配置, 并切换到该配置
|
|
154
|
-
if (regular$13.test(e.msg)) {
|
|
155
|
-
const match = e.msg.match(regular$13);
|
|
156
|
-
if (!match) {
|
|
157
|
-
message.send(format(Text("格式错误,请按照 格式:/开启聊天 或 /关闭聊天 进行设置")));
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const [, , action] = match;
|
|
161
|
-
const enable = action === "开启";
|
|
162
|
-
if (enable) {
|
|
163
|
-
const aiList = await getAIList();
|
|
164
|
-
if (aiList.length === 0) {
|
|
165
|
-
message.send(format(Text("当前没有可用的AI配置,请先添加AI配置!")));
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const aiInfo = await getAIConfig(e.guid);
|
|
169
|
-
if (aiInfo.model) {
|
|
170
|
-
message.send(format(Text(`聊天功能已开启,当前AI为 ${aiInfo.model} !`)));
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
await switchAI(e.guid, aiList[0]);
|
|
174
|
-
message.send(format(Text(`已开启聊天功能,当前AI为 ${aiList[0]} !`)));
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
await switchAI(e.guid, "");
|
|
178
|
-
message.send(format(Text("已关闭聊天功能 !")));
|
|
179
|
-
}
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
// 设置语音回复开关
|
|
183
|
-
if (regular$14.test(e.msg)) {
|
|
184
|
-
const match = e.msg.match(regular$14);
|
|
185
|
-
if (!match) {
|
|
186
|
-
message.send(format(Text("格式错误,请按照 格式:/开启语音回复 或 /关闭语音回复 进行设置")));
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
const [, , action] = match;
|
|
190
|
-
const enable = action === "开启";
|
|
191
|
-
await redis.set(`chat:tts:response:${e.guid}`, enable ? "1" : "0");
|
|
192
|
-
message.send(format(Text(`已${enable ? "开启" : "关闭"}语音回复功能 !`)));
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
// 设置工具开关
|
|
196
|
-
if (regular$15.test(e.msg)) {
|
|
197
|
-
const match = e.msg.match(regular$15);
|
|
198
|
-
if (!match) {
|
|
199
|
-
message.send(format(Text("格式错误,请按照 格式:/开启工具 或 /关闭工具 进行设置")));
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const [, , action] = match;
|
|
203
|
-
const enable = action === "开启";
|
|
204
|
-
await redis.set(`chat:tools:response:${e.guid}`, enable ? "1" : "0");
|
|
205
|
-
message.send(format(Text(`已${enable ? "开启" : "关闭"}工具功能 !\n请注意当前模型是否支持工具调用。`)));
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
// 无匹配则继续下一个响应器
|
|
209
|
-
next();
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
export { res as default, regular };
|