wechaty-web-panel 1.6.111 → 1.6.113
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/dist/bot/chatgpt/index.js +235 -0
- package/dist/bot/coze/sdk/index.js +110 -0
- package/dist/bot/dify/sdk/index.js +461 -0
- package/dist/bot/dify/sdk/office.js +319 -0
- package/dist/bot/fastgpt/index.js +98 -0
- package/dist/bot/qanything/index.js +136 -0
- package/dist/botInstance/coze.js +167 -0
- package/dist/botInstance/cozev3.js +157 -0
- package/dist/botInstance/dify.js +160 -0
- package/dist/botInstance/fastgpt.js +130 -0
- package/dist/botInstance/gpt4v.js +95 -0
- package/dist/botInstance/officialOpenAi.js +186 -0
- package/dist/botInstance/qany.js +144 -0
- package/dist/botInstance/sdk/chatGPT4V.js +89 -0
- package/dist/botInstance/sdk/coze.js +200 -0
- package/dist/botInstance/sdk/difyClient.js +354 -0
- package/dist/botInstance/sdk/pTimeout.js +97 -0
- package/dist/botInstance/sdk/qanything.js +137 -0
- package/dist/botInstance/sdk/quick-lru.js +237 -0
- package/dist/common/hook.js +66 -0
- package/dist/common/index.js +513 -0
- package/dist/common/multiReply.js +158 -0
- package/dist/common/reply.js +23 -0
- package/dist/const/puppet-type.js +71 -0
- package/dist/db/aiDb.js +27 -0
- package/dist/db/aichatDb.js +84 -0
- package/dist/db/chatHistory.js +137 -0
- package/dist/db/configDb.js +97 -0
- package/dist/db/global.js +62 -0
- package/dist/db/gptConfig.js +85 -0
- package/dist/db/nedb.js +88 -0
- package/dist/db/puppetDb.js +58 -0
- package/dist/db/roomDb.js +83 -0
- package/dist/db/rssConfig.js +82 -0
- package/dist/db/rssHistory.js +88 -0
- package/dist/db/userDb.js +27 -0
- package/dist/handlers/on-callback-message.js +183 -0
- package/dist/handlers/on-error.js +5 -0
- package/dist/handlers/on-friend.js +62 -0
- package/dist/handlers/on-heartbeat.js +20 -0
- package/dist/handlers/on-login.js +58 -0
- package/dist/handlers/on-logout.js +17 -0
- package/dist/handlers/on-message.js +644 -0
- package/dist/handlers/on-ready.js +36 -0
- package/dist/handlers/on-record-message.js +56 -0
- package/dist/handlers/on-roomjoin.js +42 -0
- package/dist/handlers/on-roomleave.js +12 -0
- package/dist/handlers/on-roomtopic.js +16 -0
- package/dist/handlers/on-scan.js +64 -0
- package/dist/handlers/on-verifycode.js +42 -0
- package/dist/index.js +81 -69306
- package/dist/lib/contentCensor.js +23 -0
- package/dist/lib/index.js +562 -0
- package/dist/lib/oss.js +43 -0
- package/dist/lib/s3oss.js +33 -0
- package/dist/mcp/mcp-server.js +26 -0
- package/dist/mcp/src/config/database.js +51 -0
- package/dist/mcp/src/index.js +238 -0
- package/dist/mcp/src/mcp/schemas.js +178 -0
- package/dist/mcp/src/mcp/server.js +421 -0
- package/dist/mcp/src/mcp/streamable-server.js +690 -0
- package/dist/mcp/src/models/ChatMessage.js +151 -0
- package/dist/mcp/src/models/Friend.js +64 -0
- package/dist/mcp/src/models/Group.js +55 -0
- package/dist/mcp/src/models/GroupMember.js +67 -0
- package/dist/mcp/src/models/index.js +27 -0
- package/dist/mcp/src/scripts/migrate.js +21 -0
- package/dist/mcp/src/services/ChatDataService.js +284 -0
- package/dist/mcp/src/services/McpService.js +521 -0
- package/dist/mcp/src/services/McpTools.js +504 -0
- package/dist/mcp/streamable-examples.js +283 -0
- package/dist/mcp/streamable-server.js +79 -0
- package/dist/mcp/test-mcp.js +64 -0
- package/dist/mcp/test-streamable-server.js +86 -0
- package/dist/package-json.js +89 -0
- package/dist/proxy/aibotk.js +829 -0
- package/dist/proxy/api.js +431 -0
- package/dist/proxy/apib.js +587 -0
- package/dist/proxy/bot/chatgpt.js +38 -0
- package/dist/proxy/bot/coze.js +38 -0
- package/dist/proxy/bot/cozev3.js +38 -0
- package/dist/proxy/bot/dify.js +38 -0
- package/dist/proxy/bot/dispatch.js +81 -0
- package/dist/proxy/bot/fastgpt.js +27 -0
- package/dist/proxy/bot/qany.js +27 -0
- package/dist/proxy/config.js +14 -0
- package/dist/proxy/cozeAi.js +60 -0
- package/dist/proxy/cozeV3Ai.js +60 -0
- package/dist/proxy/difyAi.js +58 -0
- package/dist/proxy/fastgpt.js +55 -0
- package/dist/proxy/mqtt.js +275 -0
- package/dist/proxy/multimodal.js +122 -0
- package/dist/proxy/openAi.js +63 -0
- package/dist/proxy/outapi.js +62 -0
- package/dist/proxy/qAnyAi.js +57 -0
- package/dist/proxy/superagent.js +200 -0
- package/dist/proxy/tencent-open.js +255 -0
- package/dist/service/event-dispatch-service.js +309 -0
- package/dist/service/gpt4vService.js +45 -0
- package/dist/service/msg-filter-service.js +121 -0
- package/dist/service/msg-filters.js +645 -0
- package/dist/service/room-async-service.js +455 -0
- package/dist/task/index.js +535 -0
- package/dist/task/rss.js +174 -0
- package/package.json +3 -3
- package/src/package-json.js +3 -3
- package/tsconfig.json +3 -12
- package/dist/index.d.ts +0 -9
- package/tsconfig.cjs.json +0 -12
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { getCname, getEmo, getGoldReply, getLunar, getMingYan, getNews, getResByTX, getRkl, getRubbishType, getSkl, getStar, getSweetWord, getXhy, getXing } from '../proxy/api.js';
|
|
2
|
+
import { getConfig, getCustomEvents, getMeiNv, getWordCloudConfig } from '../proxy/aibotk.js';
|
|
3
|
+
import { getConstellation, getNewsType, msgArr } from '../lib/index.js';
|
|
4
|
+
import { initMultiTask, initTaskLocalSchedule, initTimeSchedule } from '../task/index.js';
|
|
5
|
+
import { roomSay, updateContactAndRoom, updateContactOnly, updateRoomOnly } from '../common/index.js';
|
|
6
|
+
import { getTencentOpenReply } from '../proxy/tencent-open.js';
|
|
7
|
+
import { removeRecord } from '../db/roomDb.js';
|
|
8
|
+
import { getGptOfficialReply, getSimpleGptReply, reset as officialReset } from '../proxy/openAi.js';
|
|
9
|
+
import { getFastGPTReply, getSimpleFastGptReply, reset as fastGptReset } from '../proxy/fastgpt.js';
|
|
10
|
+
import { getDifyReply, getDifySimpleReply, reset as difyReset } from '../proxy/difyAi.js';
|
|
11
|
+
import { getCozeV3Reply, getCozeV3SimpleReply, reset as cozeV3Reset } from '../proxy/cozeV3Ai.js';
|
|
12
|
+
import { getCozeReply, getCozeSimpleReply, reset as cozeReset } from '../proxy/cozeAi.js';
|
|
13
|
+
import { getQAnyReply, reset as qanyReset } from '../proxy/qAnyAi.js';
|
|
14
|
+
import { outApi } from '../proxy/outapi.js';
|
|
15
|
+
import { getUser } from '../db/userDb.js';
|
|
16
|
+
/**
|
|
17
|
+
* 根据事件名称分配不同的api处理,并获取返回内容
|
|
18
|
+
* @param {string} eName 事件名称
|
|
19
|
+
* @param {string} msg 消息内容
|
|
20
|
+
* @param name
|
|
21
|
+
* @param id
|
|
22
|
+
* @param avatar
|
|
23
|
+
* @returns {string} 内容
|
|
24
|
+
*/
|
|
25
|
+
async function dispatchEventContent(that, eName, msg, name, id, avatar, room, roomName, sourceMsg, contact, eventInfo) {
|
|
26
|
+
try {
|
|
27
|
+
let content = '', type = 1, url = '';
|
|
28
|
+
if (eName.includes('event-')) {
|
|
29
|
+
const res = await getCustomEvents({ msg: msg || '', sourceMsg: sourceMsg || '', wxid: id, name, eventId: eName, roomName: roomName || '' });
|
|
30
|
+
return res;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 扩展 api
|
|
34
|
+
*/
|
|
35
|
+
if (eName.includes('outapi-')) {
|
|
36
|
+
const res = await outApi({ msg: msg || '', sourceMsg: sourceMsg || '', wxid: id, name, eventId: eName, roomName: roomName || '' });
|
|
37
|
+
return res;
|
|
38
|
+
}
|
|
39
|
+
switch (eName) {
|
|
40
|
+
case 'rubbish':
|
|
41
|
+
content = await getRubbishType(msg);
|
|
42
|
+
break;
|
|
43
|
+
case 'mingyan':
|
|
44
|
+
content = await getMingYan();
|
|
45
|
+
break;
|
|
46
|
+
case 'sweetword':
|
|
47
|
+
content = await getSweetWord();
|
|
48
|
+
break;
|
|
49
|
+
case 'star':
|
|
50
|
+
let xing = getConstellation(msg);
|
|
51
|
+
content = await getStar(xing);
|
|
52
|
+
break;
|
|
53
|
+
case 'news':
|
|
54
|
+
let newsId = getNewsType(msg);
|
|
55
|
+
content = await getNews(newsId);
|
|
56
|
+
break;
|
|
57
|
+
case 'xing':
|
|
58
|
+
content = await getXing(msg);
|
|
59
|
+
break;
|
|
60
|
+
case 'skl':
|
|
61
|
+
content = await getSkl(msg);
|
|
62
|
+
break;
|
|
63
|
+
case 'lunar':
|
|
64
|
+
content = await getLunar(msg);
|
|
65
|
+
break;
|
|
66
|
+
case 'goldreply':
|
|
67
|
+
content = await getGoldReply(msg);
|
|
68
|
+
break;
|
|
69
|
+
case 'xhy':
|
|
70
|
+
content = await getXhy(msg);
|
|
71
|
+
break;
|
|
72
|
+
case 'rkl':
|
|
73
|
+
content = await getRkl(msg);
|
|
74
|
+
break;
|
|
75
|
+
case 'emo':
|
|
76
|
+
url = await getEmo(msg);
|
|
77
|
+
type = 2;
|
|
78
|
+
break;
|
|
79
|
+
case 'meinv':
|
|
80
|
+
url = await getMeiNv();
|
|
81
|
+
type = 2;
|
|
82
|
+
break;
|
|
83
|
+
case 'cname':
|
|
84
|
+
content = await getCname();
|
|
85
|
+
break;
|
|
86
|
+
case 'removeRecord': {
|
|
87
|
+
const roomName = await room.topic(); // 获取群名
|
|
88
|
+
const config = await getWordCloudConfig(roomName);
|
|
89
|
+
if (config.authList) {
|
|
90
|
+
if (config.authList.length) {
|
|
91
|
+
if (config.authList.includes(name)) {
|
|
92
|
+
await removeRecord(roomName);
|
|
93
|
+
content = '清除成功';
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
content = '很抱歉,你没有权限清楚记录';
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
await removeRecord(roomName);
|
|
101
|
+
content = '清除成功';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
content = '本群暂未开通群词云功能,无需清楚记录';
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 'reloadFriendOnly':
|
|
110
|
+
await updateContactOnly(that);
|
|
111
|
+
content = '更新好友列表成功,请稍等两分钟后生效';
|
|
112
|
+
break;
|
|
113
|
+
case 'reloadRoomOnly':
|
|
114
|
+
await updateRoomOnly(that);
|
|
115
|
+
content = '更新群列表成功,请稍等两分钟后生效';
|
|
116
|
+
break;
|
|
117
|
+
case 'reloadFriend':
|
|
118
|
+
await updateContactAndRoom(that);
|
|
119
|
+
content = '更新好友群消息成功,请稍等两分钟后生效';
|
|
120
|
+
break;
|
|
121
|
+
case 'updateConfig':
|
|
122
|
+
await getConfig();
|
|
123
|
+
await initTaskLocalSchedule(that);
|
|
124
|
+
await initTimeSchedule(that);
|
|
125
|
+
await initMultiTask(that);
|
|
126
|
+
officialReset();
|
|
127
|
+
difyReset();
|
|
128
|
+
cozeReset();
|
|
129
|
+
qanyReset();
|
|
130
|
+
cozeV3Reset();
|
|
131
|
+
fastGptReset();
|
|
132
|
+
content = '更新配置成功,请稍等一分钟后生效';
|
|
133
|
+
break;
|
|
134
|
+
case 'autoRoomCreate':
|
|
135
|
+
console.log('触发创建群聊指令,拉取用户并创建群聊');
|
|
136
|
+
const roomMembers = [contact];
|
|
137
|
+
const creatInfo = eventInfo?.otherInfo || { members: [], name: '', welcomes: [], tips: '' };
|
|
138
|
+
for (let member of creatInfo.members) {
|
|
139
|
+
console.log('member', member);
|
|
140
|
+
const target = (member.id && (await that.Contact.find({ id: member.id }))) || (member.name && (await that.Contact.find({ name: member.name }))); // 获取你要发送的联系人
|
|
141
|
+
if (target) {
|
|
142
|
+
roomMembers.push(target);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
console.log(`没有查找到你预设进群的用户:${member.name},请确保是机器人的好友`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
that.Room.create(roomMembers, creatInfo.name || '')
|
|
149
|
+
.then((room) => {
|
|
150
|
+
if (room) {
|
|
151
|
+
console.log('创建群聊成功');
|
|
152
|
+
if (creatInfo.welcomes && creatInfo.welcomes.length) {
|
|
153
|
+
for (let welcome of creatInfo.welcomes) {
|
|
154
|
+
void roomSay.call(that, room, contact, welcome);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
.catch((e) => {
|
|
160
|
+
console.log('创建群聊失败', e);
|
|
161
|
+
});
|
|
162
|
+
content = creatInfo.tips || '正在拉您进群,请稍后...';
|
|
163
|
+
break;
|
|
164
|
+
default:
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
return msgArr(type, content, url);
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
console.log('事件处理异常', e);
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* 派发不同的机器人处理回复内容
|
|
176
|
+
* @param {*} bot 机器人类别 0 天行机器人 1 天行的图灵机器人 2 图灵机器人 3 腾讯闲聊机器人
|
|
177
|
+
* @param {*} msg 消息内容
|
|
178
|
+
* @param {*} name 发消息人
|
|
179
|
+
* @param {*} id 发消息人id
|
|
180
|
+
*/
|
|
181
|
+
async function dispatchAiBot({ bot, msg, name, id, isMention, uid, uname, roomId, userAlias, userWeixin, roomName, file }) {
|
|
182
|
+
try {
|
|
183
|
+
let res, replys;
|
|
184
|
+
const contactSelf = await getUser();
|
|
185
|
+
let userId = '';
|
|
186
|
+
if (process.env['CUSTOM_USER_ID']) {
|
|
187
|
+
userId = process.env['CUSTOM_USER_ID'];
|
|
188
|
+
}
|
|
189
|
+
switch (bot) {
|
|
190
|
+
case 0:
|
|
191
|
+
if (file) {
|
|
192
|
+
replys = [{ type: 1, content: '' }];
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
res = await getResByTX(msg, id);
|
|
196
|
+
replys = [{ type: 1, content: res }];
|
|
197
|
+
}
|
|
198
|
+
break;
|
|
199
|
+
case 5:
|
|
200
|
+
if (file) {
|
|
201
|
+
replys = [{ type: 1, content: '' }];
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
res = await getTencentOpenReply({ msg, id, userInfo: { name } });
|
|
205
|
+
replys = res;
|
|
206
|
+
}
|
|
207
|
+
// 微信开放对话平台
|
|
208
|
+
break;
|
|
209
|
+
case 6:
|
|
210
|
+
// ChatGPT-api
|
|
211
|
+
res = await getGptOfficialReply({ content: msg, uid: id, file });
|
|
212
|
+
replys = res;
|
|
213
|
+
break;
|
|
214
|
+
case 8:
|
|
215
|
+
// dify ai
|
|
216
|
+
res = await getDifyReply({ content: msg, file, id, inputs: { useid: userId, isMention: isMention ? 1 : 0, fileUrl: file?.fileUrl, fileExtname: file?.fileExtname, uid, ualias: userAlias, uweixin: userWeixin, uname, roomId, roomName, robotId: contactSelf.robotId, robotName: contactSelf.name } });
|
|
217
|
+
replys = res;
|
|
218
|
+
break;
|
|
219
|
+
case 9:
|
|
220
|
+
// fast gpt
|
|
221
|
+
res = await getFastGPTReply({ content: msg, file }, id, { useid: userId, isMention: isMention ? 1 : 0, fileUrl: file?.fileUrl, fileExtname: file?.fileExtname, uid, uname, ualias: userAlias, uweixin: userWeixin, roomId, roomName, robotId: contactSelf.robotId, robotName: contactSelf.name });
|
|
222
|
+
replys = res;
|
|
223
|
+
break;
|
|
224
|
+
case 11:
|
|
225
|
+
// coze
|
|
226
|
+
if (file) {
|
|
227
|
+
replys = [{ type: 1, content: '' }];
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
res = await getCozeReply(msg, id);
|
|
231
|
+
replys = res;
|
|
232
|
+
}
|
|
233
|
+
break;
|
|
234
|
+
case 12:
|
|
235
|
+
// coze v3
|
|
236
|
+
res = await getCozeV3Reply({ content: msg, file, id, inputs: { useid: userId, isMention: isMention ? '1' : '0', fileUrl: file?.fileUrl, fileExtname: file?.fileExtname, uid, ualias: userAlias, uweixin: userWeixin, uname, roomId, roomName, robotId: contactSelf.robotId, robotName: contactSelf.name } });
|
|
237
|
+
replys = res;
|
|
238
|
+
break;
|
|
239
|
+
case 13:
|
|
240
|
+
// QAnything
|
|
241
|
+
if (file) {
|
|
242
|
+
replys = [{ type: 1, content: '' }];
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
res = await getQAnyReply(msg, id);
|
|
246
|
+
replys = res;
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
default:
|
|
250
|
+
replys = [{ type: 1, content: '' }];
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
return replys;
|
|
254
|
+
}
|
|
255
|
+
catch (e) {
|
|
256
|
+
console.log('机器人接口信息获取失败', e);
|
|
257
|
+
return '';
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
async function dispatchSummerBot({ content, id, uid, uname, roomId, roomName, userAlias, userWeixin, config }) {
|
|
261
|
+
try {
|
|
262
|
+
let res, replys;
|
|
263
|
+
const contactSelf = await getUser();
|
|
264
|
+
switch (config.botType) {
|
|
265
|
+
case 6:
|
|
266
|
+
// ChatGPT-api
|
|
267
|
+
res = await getSimpleGptReply({ content, uid: id, config });
|
|
268
|
+
replys = res;
|
|
269
|
+
break;
|
|
270
|
+
case 8:
|
|
271
|
+
// dify ai
|
|
272
|
+
res = await getDifySimpleReply({ content, id, inputs: { uid, uname, ualias: userAlias, uweixin: userWeixin, roomId, roomName, robotId: contactSelf.robotId, robotName: contactSelf.name }, config });
|
|
273
|
+
replys = res;
|
|
274
|
+
break;
|
|
275
|
+
case 9:
|
|
276
|
+
// fast gpt
|
|
277
|
+
res = await getSimpleFastGptReply({ content, uid: id, config, variables: { uid, ualias: userAlias, uweixin: userWeixin, uname, roomId, roomName, robotId: contactSelf.robotId, robotName: contactSelf.name } });
|
|
278
|
+
replys = res;
|
|
279
|
+
break;
|
|
280
|
+
case 11:
|
|
281
|
+
// coze
|
|
282
|
+
res = await getCozeSimpleReply({ content, uid: id, config });
|
|
283
|
+
replys = res;
|
|
284
|
+
break;
|
|
285
|
+
case 12:
|
|
286
|
+
// coze v3
|
|
287
|
+
res = await getCozeV3SimpleReply({ content, id, inputs: { uid, uname, ualias: userAlias, uweixin: userWeixin, roomId, roomName, robotId: contactSelf.robotId, robotName: contactSelf.name }, config });
|
|
288
|
+
replys = res;
|
|
289
|
+
break;
|
|
290
|
+
default:
|
|
291
|
+
replys = [{ type: 1, content: '' }];
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
return replys;
|
|
295
|
+
}
|
|
296
|
+
catch (e) {
|
|
297
|
+
console.log('群聊总结信息获取失败', e);
|
|
298
|
+
return '';
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
export { dispatchEventContent };
|
|
302
|
+
export { dispatchAiBot };
|
|
303
|
+
export { dispatchSummerBot };
|
|
304
|
+
export default {
|
|
305
|
+
dispatchSummerBot,
|
|
306
|
+
dispatchEventContent,
|
|
307
|
+
dispatchAiBot,
|
|
308
|
+
};
|
|
309
|
+
//# sourceMappingURL=event-dispatch-service.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BotManage } from '../common/multiReply.js';
|
|
2
|
+
import { getCustomConfig } from './msg-filters.js';
|
|
3
|
+
import { updateChatRecord } from '../proxy/aibotk.js';
|
|
4
|
+
import globalConfig from '../db/global.js';
|
|
5
|
+
let gpt4vRes = '';
|
|
6
|
+
export async function getGpt4vChat({ room, roomId, roomName, isMention, userAlias, msgContent, name, id, uniqueId, that }) {
|
|
7
|
+
if (!gpt4vRes) {
|
|
8
|
+
gpt4vRes = new BotManage(100, that);
|
|
9
|
+
}
|
|
10
|
+
let finalConfig = await getCustomConfig({ name, id, roomName, roomId, room, type: 'open4v' });
|
|
11
|
+
if (finalConfig) {
|
|
12
|
+
const isRoom = finalConfig.type === 'room';
|
|
13
|
+
if (msgContent.type === 1) {
|
|
14
|
+
let msg = msgContent.content;
|
|
15
|
+
if ((isRoom && finalConfig.needAt === 1 && isMention) || isRoom && !finalConfig.needAt || !isRoom) {
|
|
16
|
+
const keyword = finalConfig?.keywords?.find((item) => msg.includes(item)) || '';
|
|
17
|
+
if (keyword || !finalConfig?.keywords?.length) {
|
|
18
|
+
msg = keyword ? msg.replace(keyword, '') : msg;
|
|
19
|
+
if (finalConfig.limitNum > 0 && finalConfig.limitNum <= finalConfig.usedNum) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
const config = {
|
|
23
|
+
...finalConfig.botConfig,
|
|
24
|
+
robotType: finalConfig.botConfig?.open4vConfig?.type || finalConfig.robotType,
|
|
25
|
+
proxyPass: finalConfig.botConfig?.open4vConfig?.baseUrl || finalConfig.botConfig?.proxyPass,
|
|
26
|
+
apiKey: finalConfig.botConfig?.open4vConfig?.token || finalConfig.botConfig?.token
|
|
27
|
+
};
|
|
28
|
+
const res = await gpt4vRes.run(uniqueId, { type: 1, content: msg }, config);
|
|
29
|
+
if (res.length) {
|
|
30
|
+
const gptConfig = globalConfig.getGptConfigById(finalConfig.id);
|
|
31
|
+
void updateChatRecord(finalConfig.id, gptConfig.usedNum + 1);
|
|
32
|
+
globalConfig.updateOneGptConfig(finalConfig.id, { ...gptConfig, usedNum: gptConfig.usedNum + 1 });
|
|
33
|
+
}
|
|
34
|
+
return res;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (msgContent.type === 3) {
|
|
39
|
+
const res = await gpt4vRes.run(uniqueId, { type: 3, id: msgContent.id });
|
|
40
|
+
return res;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=gpt4vService.js.map
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { allConfig } from '../db/configDb.js';
|
|
2
|
+
import globalConfig from '../db/global.js';
|
|
3
|
+
import msgFilter from './msg-filters.js';
|
|
4
|
+
const WEIXINOFFICIAL = ['朋友推荐消息', '微信支付', '微信运动', '微信团队', 'recommendation message']; // 微信官方账户,针对此账户不做任何回复
|
|
5
|
+
const DELETEFRIEND = '开启了朋友验证'; // 被人删除后,防止重复回复
|
|
6
|
+
const REMINDKEY = '提醒';
|
|
7
|
+
const NEWADDFRIEND = '你已添加';
|
|
8
|
+
async function getMsgReply(resArray, { that, msg, name, contact, config, avatar, userAlias, userWeixin, id, room, isMention, roomName, roomId, isFriend, file }) {
|
|
9
|
+
try {
|
|
10
|
+
let msgArr = [];
|
|
11
|
+
for (let i = 0; i < resArray.length; i++) {
|
|
12
|
+
const item = resArray[i];
|
|
13
|
+
if (item.bool) {
|
|
14
|
+
msgArr = (await msgFilter[item.method]({ that, msg, name, contact, config, avatar, id, room, userAlias, userWeixin, isMention, roomName, roomId, isFriend, file })) || [];
|
|
15
|
+
}
|
|
16
|
+
if (msgArr.length > 0) {
|
|
17
|
+
return msgArr;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
console.log('getMsgReply error', e);
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 微信好友文本消息事件过滤
|
|
29
|
+
*
|
|
30
|
+
* @param that wechaty实例
|
|
31
|
+
* @param {Object} contact 发消息者信息
|
|
32
|
+
* @param {string} msg 消息内容
|
|
33
|
+
* @returns {number} 返回回复内容
|
|
34
|
+
*/
|
|
35
|
+
async function filterFriendMsg(that, contact, msg) {
|
|
36
|
+
try {
|
|
37
|
+
const config = await allConfig(); // 获取配置信息
|
|
38
|
+
const gptConfig = globalConfig.getAllGptConfig(); // 获取gpt配置信息
|
|
39
|
+
const name = contact.name();
|
|
40
|
+
const userAlias = await contact.alias() || '';
|
|
41
|
+
const userWeixin = contact.weixin() || '';
|
|
42
|
+
const id = contact.id;
|
|
43
|
+
const avatar = await contact.avatar();
|
|
44
|
+
const resArray = [
|
|
45
|
+
{ bool: msg === '', method: 'emptyMsg' },
|
|
46
|
+
{ bool: msg.includes(DELETEFRIEND) || WEIXINOFFICIAL.includes(name), method: 'officialMsg' },
|
|
47
|
+
{ bool: config.preventLength && msg.length > config.preventLength, method: 'maxLengthMsg' },
|
|
48
|
+
{ bool: msg.includes(NEWADDFRIEND), method: 'newFriendMsg' },
|
|
49
|
+
{ bool: config.roomJoinKeywords && config.roomJoinKeywords.length > 0, method: 'roomInviteMsg' },
|
|
50
|
+
{ bool: msg.startsWith(REMINDKEY) && !config.no_remind, method: 'scheduleJobMsg' },
|
|
51
|
+
{ bool: config.forwards && config.forwards.length > 0, method: 'keywordForward' },
|
|
52
|
+
{ bool: config.callBackEvents && config.callBackEvents.length > 0, method: 'callbackEvent' },
|
|
53
|
+
{ bool: config.preventWords, method: 'preventWordCheck' },
|
|
54
|
+
{ bool: !!config?.summerConfig, method: 'summerChat' },
|
|
55
|
+
{ bool: config.eventKeywords && config.eventKeywords.length > 0, method: 'eventMsg' },
|
|
56
|
+
{ bool: true, method: 'keywordsMsg' },
|
|
57
|
+
{ bool: gptConfig && gptConfig.length > 0, method: 'customChat' },
|
|
58
|
+
{ bool: config.customBot && config.customBot.open, method: 'customBot' },
|
|
59
|
+
{ bool: config.autoReply && config.botScope !== 'room', method: 'robotMsg' },
|
|
60
|
+
];
|
|
61
|
+
const msgArr = await getMsgReply(resArray, { that, msg, userAlias, userWeixin, contact, name, config, avatar, id });
|
|
62
|
+
return msgArr.length > 0 ? msgArr : [{ type: 1, content: '', url: '' }];
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.log('filterFriendMsg error', e);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 微信群文本消息事件监听
|
|
70
|
+
* @param {*} msg 群消息内容
|
|
71
|
+
* @param {*} name 发消息人昵称
|
|
72
|
+
* @param {*} id 发消息人
|
|
73
|
+
* @param avatar
|
|
74
|
+
* @returns {number} 返回事件类型
|
|
75
|
+
* 事件说明
|
|
76
|
+
* 0 机器人回复
|
|
77
|
+
* 1 开启了好友验证 || 朋友推荐消息 || 发送的文字消息过长,大于40个字符
|
|
78
|
+
* 2 初次添加好友
|
|
79
|
+
*/
|
|
80
|
+
async function filterRoomMsg({ that, msg, name, id, avatar, userAlias, userWeixin, room, isMention, roomName, roomId, isFriend }) {
|
|
81
|
+
try {
|
|
82
|
+
const config = await allConfig(); // 获取配置信息
|
|
83
|
+
const gptConfig = globalConfig.getAllGptConfig(); // 获取gpt配置信息
|
|
84
|
+
const resArray = [
|
|
85
|
+
{ bool: msg === '', method: 'emptyMsg' },
|
|
86
|
+
{ bool: config.forwards && config.forwards.length > 0, method: 'keywordForward' },
|
|
87
|
+
{ bool: config.callBackEvents && config.callBackEvents.length > 0, method: 'callbackEvent' },
|
|
88
|
+
{ bool: !!config.preventWords, method: 'preventWordCheck' },
|
|
89
|
+
{ bool: !!config?.summerConfig, method: 'summerChat' },
|
|
90
|
+
{ bool: config.eventKeywords && config.eventKeywords.length > 0, method: 'eventMsg' },
|
|
91
|
+
{ bool: true, method: 'keywordsMsg' },
|
|
92
|
+
{ bool: gptConfig && gptConfig.length > 0, method: 'customChat' },
|
|
93
|
+
{ bool: config.customBot && config.customBot.open, method: 'customBot' },
|
|
94
|
+
{ bool: config.autoReply && config.botScope !== 'friend', method: 'robotMsg' },
|
|
95
|
+
];
|
|
96
|
+
const msgArr = await getMsgReply(resArray, { that, msg, name, config, avatar, id, room, userAlias, userWeixin, roomName, roomId, isMention, isFriend });
|
|
97
|
+
return msgArr.length > 0 ? msgArr : [{ type: 1, content: '', url: '' }];
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
console.log('filterRoomMsg error', e);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function filterFile({ that, msg, name, id, avatar, userAlias, userWeixin, room, isMention, roomName, roomId, isFriend, file }) {
|
|
104
|
+
const config = await allConfig(); // 获取配置信息
|
|
105
|
+
const gptConfig = globalConfig.getAllGptConfig(); // 获取gpt配置信息
|
|
106
|
+
const resArray = [
|
|
107
|
+
{ bool: gptConfig && gptConfig.length > 0, method: 'customChat' },
|
|
108
|
+
{ bool: (config.autoReply && config.botScope !== 'room' && !room) || (config.autoReply && config.botScope !== 'friend' && room), method: 'robotMsg' },
|
|
109
|
+
];
|
|
110
|
+
const msgArr = await getMsgReply(resArray, { that, msg, name, config, avatar, id, room, userAlias, userWeixin, roomName, roomId, isMention, isFriend, file });
|
|
111
|
+
return msgArr.length > 0 ? msgArr : [{ type: 1, content: '', url: '' }];
|
|
112
|
+
}
|
|
113
|
+
export { filterFriendMsg };
|
|
114
|
+
export { filterRoomMsg };
|
|
115
|
+
export { filterFile };
|
|
116
|
+
export default {
|
|
117
|
+
filterFriendMsg,
|
|
118
|
+
filterRoomMsg,
|
|
119
|
+
filterFile
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=msg-filter-service.js.map
|