wechaty-web-panel 1.6.19 → 1.6.21
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/CHANGELOG.md +3 -0
- package/dist/cjs/src/common/index.js +2 -2
- package/dist/cjs/src/package-json.js +1 -1
- package/dist/cjs/src/proxy/aibotk.js +1 -0
- package/dist/cjs/src/service/msg-filter-service.js +1 -0
- package/dist/cjs/src/service/msg-filters.d.ts +10 -0
- package/dist/cjs/src/service/msg-filters.js +90 -50
- package/dist/cjs/src/task/rss.js +1 -1
- package/dist/esm/src/common/index.js +2 -2
- package/dist/esm/src/package-json.js +1 -1
- package/dist/esm/src/proxy/aibotk.js +1 -0
- package/dist/esm/src/service/msg-filter-service.js +1 -0
- package/dist/esm/src/service/msg-filters.d.ts +10 -0
- package/dist/esm/src/service/msg-filters.js +95 -55
- package/dist/esm/src/task/rss.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -232,8 +232,8 @@ async function roomSay(room, contact, msg) {
|
|
|
232
232
|
const title = await formatContent(msg.title);
|
|
233
233
|
let url = new this.UrlLink({
|
|
234
234
|
description: description,
|
|
235
|
-
thumbnailUrl:
|
|
236
|
-
title:
|
|
235
|
+
thumbnailUrl: msg.thumbUrl,
|
|
236
|
+
title: title,
|
|
237
237
|
url: msg.url,
|
|
238
238
|
});
|
|
239
239
|
await room.say(url);
|
|
@@ -90,6 +90,7 @@ async function filterRoomMsg({ that, msg, name, id, avatar, room, isMention, roo
|
|
|
90
90
|
{ bool: config.eventKeywords && config.eventKeywords.length > 0, method: 'eventMsg' },
|
|
91
91
|
{ bool: true, method: 'keywordsMsg' },
|
|
92
92
|
{ bool: gptConfig && gptConfig.length > 0, method: 'customChat' },
|
|
93
|
+
{ bool: config.customBot && config.customBot.open, method: 'customBot' },
|
|
93
94
|
{ bool: config.autoReply && config.botScope !== 'friend', method: 'robotMsg' },
|
|
94
95
|
];
|
|
95
96
|
const msgArr = await getMsgReply(resArray, { that, msg, name, config, avatar, id, room, roomName, roomId, isMention });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
declare namespace _default {
|
|
2
|
+
export { customBot };
|
|
2
3
|
export { callbackEvent };
|
|
3
4
|
export { emptyMsg };
|
|
4
5
|
export { officialMsg };
|
|
@@ -13,6 +14,15 @@ declare namespace _default {
|
|
|
13
14
|
export { preventWordCheck };
|
|
14
15
|
}
|
|
15
16
|
export default _default;
|
|
17
|
+
export function customBot({ that, msg, name, id, config, room, isMention }: {
|
|
18
|
+
that: any;
|
|
19
|
+
msg: any;
|
|
20
|
+
name: any;
|
|
21
|
+
id: any;
|
|
22
|
+
config: any;
|
|
23
|
+
room: any;
|
|
24
|
+
isMention: any;
|
|
25
|
+
}): Promise<never[] | import("axios").AxiosResponse<any, any>>;
|
|
16
26
|
/**
|
|
17
27
|
* 回调函数事件
|
|
18
28
|
* @param that
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.preventWordCheck = exports.customChat = exports.maxLengthMsg = exports.robotMsg = exports.keywordsMsg = exports.eventMsg = exports.scheduleJobMsg = exports.roomInviteMsg = exports.newFriendMsg = exports.officialMsg = exports.emptyMsg = exports.callbackEvent = void 0;
|
|
6
|
+
exports.preventWordCheck = exports.customChat = exports.maxLengthMsg = exports.robotMsg = exports.keywordsMsg = exports.eventMsg = exports.scheduleJobMsg = exports.roomInviteMsg = exports.newFriendMsg = exports.officialMsg = exports.emptyMsg = exports.callbackEvent = exports.customBot = void 0;
|
|
7
7
|
const event_dispatch_service_js_1 = __importDefault(require("./event-dispatch-service.js"));
|
|
8
8
|
const aibotk_js_1 = require("../proxy/aibotk.js");
|
|
9
9
|
const index_js_1 = require("../lib/index.js");
|
|
@@ -11,28 +11,29 @@ const index_js_2 = require("../common/index.js");
|
|
|
11
11
|
const superagent_js_1 = require("../proxy/superagent.js");
|
|
12
12
|
const dispatch_js_1 = require("../proxy/bot/dispatch.js");
|
|
13
13
|
const global_js_1 = __importDefault(require("../db/global.js"));
|
|
14
|
+
const userDb_js_1 = require("../db/userDb.js");
|
|
14
15
|
function emptyMsg({ room, isMention }) {
|
|
15
16
|
if (room && !isMention)
|
|
16
17
|
return [];
|
|
17
18
|
let msgArr = []; // 返回的消息列表
|
|
18
|
-
let obj = { type: 1, content:
|
|
19
|
+
let obj = { type: 1, content: "我在呢", url: "" }; // 消息主体
|
|
19
20
|
msgArr.push(obj);
|
|
20
21
|
return msgArr;
|
|
21
22
|
}
|
|
22
23
|
exports.emptyMsg = emptyMsg;
|
|
23
24
|
function officialMsg() {
|
|
24
|
-
console.log(
|
|
25
|
-
return [{ type: 1, content:
|
|
25
|
+
console.log("官方消息,不做回复");
|
|
26
|
+
return [{ type: 1, content: "", url: "" }];
|
|
26
27
|
}
|
|
27
28
|
exports.officialMsg = officialMsg;
|
|
28
29
|
function maxLengthMsg() {
|
|
29
|
-
console.log(
|
|
30
|
-
return [{ type: 1, content:
|
|
30
|
+
console.log("字符超过设定值,不做回复");
|
|
31
|
+
return [{ type: 1, content: "", url: "" }];
|
|
31
32
|
}
|
|
32
33
|
exports.maxLengthMsg = maxLengthMsg;
|
|
33
34
|
function newFriendMsg({ config, name }) {
|
|
34
35
|
console.log(`新添加好友:${name},默认回复`);
|
|
35
|
-
return config.newFriendReplys || [{ type: 1, content:
|
|
36
|
+
return config.newFriendReplys || [{ type: 1, content: "", url: "" }];
|
|
36
37
|
}
|
|
37
38
|
exports.newFriendMsg = newFriendMsg;
|
|
38
39
|
async function roomInviteMsg({ that, msg, contact, config }) {
|
|
@@ -41,14 +42,14 @@ async function roomInviteMsg({ that, msg, contact, config }) {
|
|
|
41
42
|
if (item.reg === 2 && item.keywords.includes(msg)) {
|
|
42
43
|
console.log(`精确匹配到加群关键词${msg},正在邀请用户进群`);
|
|
43
44
|
await (0, index_js_2.addRoom)(that, contact, item.roomName, item.replys);
|
|
44
|
-
return [{ type: 1, content:
|
|
45
|
+
return [{ type: 1, content: "", url: "" }];
|
|
45
46
|
}
|
|
46
47
|
else {
|
|
47
48
|
for (let key of item.keywords) {
|
|
48
49
|
if (msg.includes(key)) {
|
|
49
50
|
console.log(`模糊匹配到加群关键词${msg},正在邀请用户进群`);
|
|
50
51
|
await (0, index_js_2.addRoom)(that, contact, item.roomName, item.replys);
|
|
51
|
-
return [{ type: 1, content:
|
|
52
|
+
return [{ type: 1, content: "", url: "" }];
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
}
|
|
@@ -56,7 +57,7 @@ async function roomInviteMsg({ that, msg, contact, config }) {
|
|
|
56
57
|
return [];
|
|
57
58
|
}
|
|
58
59
|
catch (e) {
|
|
59
|
-
console.log(
|
|
60
|
+
console.log("roomInviteMsg error", e);
|
|
60
61
|
return [];
|
|
61
62
|
}
|
|
62
63
|
}
|
|
@@ -77,7 +78,7 @@ async function addSchedule(that, obj) {
|
|
|
77
78
|
let contact = await that.Contact.find({ name: nickName });
|
|
78
79
|
let id = scheduleObj.id;
|
|
79
80
|
(0, index_js_1.setLocalSchedule)(Rule1, async () => {
|
|
80
|
-
console.log(
|
|
81
|
+
console.log("你的专属提醒开启啦!");
|
|
81
82
|
await contact.say(content);
|
|
82
83
|
if (!scheduleObj.isLoop) {
|
|
83
84
|
(0, aibotk_js_1.updateSchedule)(id);
|
|
@@ -86,42 +87,42 @@ async function addSchedule(that, obj) {
|
|
|
86
87
|
return true;
|
|
87
88
|
}
|
|
88
89
|
catch (error) {
|
|
89
|
-
console.log(
|
|
90
|
+
console.log("设置定时任务失败", error);
|
|
90
91
|
return false;
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
async function scheduleJobMsg({ that, msg, name }) {
|
|
94
95
|
try {
|
|
95
|
-
let obj = { type: 1, content:
|
|
96
|
-
let msgArr = msg.replace(/\s+/g,
|
|
96
|
+
let obj = { type: 1, content: "", url: "" }; // 消息主体
|
|
97
|
+
let msgArr = msg.replace(/\s+/g, " ").split(" ");
|
|
97
98
|
if (msgArr.length > 3) {
|
|
98
99
|
let schedule = (0, index_js_1.contentDistinguish)(msgArr, name);
|
|
99
100
|
let time = schedule.isLoop ? schedule.time : (0, index_js_1.isRealDate)(schedule.time);
|
|
100
101
|
if (time) {
|
|
101
102
|
let res = await addSchedule(that, schedule);
|
|
102
103
|
if (res) {
|
|
103
|
-
obj.content =
|
|
104
|
+
obj.content = "小助手已经把你的提醒牢记在小本本上了";
|
|
104
105
|
}
|
|
105
106
|
else {
|
|
106
|
-
obj.content =
|
|
107
|
+
obj.content = "添加提醒失败,请稍后重试";
|
|
107
108
|
}
|
|
108
109
|
msgArr.push(obj);
|
|
109
110
|
return msgArr;
|
|
110
111
|
}
|
|
111
112
|
else {
|
|
112
|
-
obj.content =
|
|
113
|
+
obj.content = "提醒设置失败,请保证每个关键词之间使用空格分割开,并保证日期格式正确。正确格式为:“提醒(空格)我(空格)每天(空格)18:30(空格)下班回家";
|
|
113
114
|
msgArr.push(obj);
|
|
114
115
|
return msgArr;
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
else {
|
|
118
|
-
obj.content =
|
|
119
|
+
obj.content = "提醒设置失败,请保证每个关键词之间使用空格分割开,并保证日期格式正确。正确格式为:“提醒(空格)我(空格)18:30(空格)下班回家”";
|
|
119
120
|
msgArr.push(obj);
|
|
120
121
|
return msgArr;
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
catch (e) {
|
|
124
|
-
console.log(
|
|
125
|
+
console.log("scheduleJobMsg error:", e);
|
|
125
126
|
return [];
|
|
126
127
|
}
|
|
127
128
|
}
|
|
@@ -141,7 +142,7 @@ async function getEventReply(that, event, msg, name, id, avatar, room) {
|
|
|
141
142
|
return reply;
|
|
142
143
|
}
|
|
143
144
|
catch (e) {
|
|
144
|
-
console.log(
|
|
145
|
+
console.log("getEventReply error", e);
|
|
145
146
|
return [];
|
|
146
147
|
}
|
|
147
148
|
}
|
|
@@ -161,22 +162,22 @@ async function callbackEvent({ that, msg, name, id, config, room, isMention }) {
|
|
|
161
162
|
for (let key of item.keywords) {
|
|
162
163
|
if ((item.reg === 1 && msg.includes(key)) || (item.reg === 2 && msg === key)) {
|
|
163
164
|
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
164
|
-
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope ===
|
|
165
|
+
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope === "friend") || (!room && item.scope === "room")) {
|
|
165
166
|
return [];
|
|
166
167
|
}
|
|
167
168
|
msg = msg.trim();
|
|
168
|
-
const topic = room ? await room.topic() :
|
|
169
|
+
const topic = room ? await room.topic() : "";
|
|
169
170
|
const data = {
|
|
170
171
|
uid: id,
|
|
171
172
|
uname: name,
|
|
172
|
-
roomId: (room && room.id) ||
|
|
173
|
-
roomName: (room && topic) ||
|
|
174
|
-
word: msg
|
|
173
|
+
roomId: (room && room.id) || "",
|
|
174
|
+
roomName: (room && topic) || "",
|
|
175
|
+
word: msg
|
|
175
176
|
};
|
|
176
177
|
item.moreData &&
|
|
177
178
|
item.moreData.length &&
|
|
178
179
|
item.moreData.forEach((mItem) => {
|
|
179
|
-
if (mItem.key !==
|
|
180
|
+
if (mItem.key !== "uid" && mItem.key !== "uname" && mItem.key !== "word" && mItem.key !== "roomId" && mItem.key !== "roomName") {
|
|
180
181
|
data[mItem.key] = mItem.value;
|
|
181
182
|
}
|
|
182
183
|
});
|
|
@@ -195,7 +196,7 @@ async function callbackEvent({ that, msg, name, id, config, room, isMention }) {
|
|
|
195
196
|
return [];
|
|
196
197
|
}
|
|
197
198
|
catch (e) {
|
|
198
|
-
console.log(
|
|
199
|
+
console.log("error", e);
|
|
199
200
|
return [];
|
|
200
201
|
}
|
|
201
202
|
}
|
|
@@ -206,10 +207,10 @@ async function eventMsg({ that, msg, name, id, avatar, config, room, isMention }
|
|
|
206
207
|
for (let key of item.keywords) {
|
|
207
208
|
if ((item.reg === 1 && msg.includes(key)) || (item.reg === 2 && msg === key)) {
|
|
208
209
|
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
209
|
-
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope ===
|
|
210
|
+
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope === "friend") || (!room && item.scope === "room")) {
|
|
210
211
|
return [];
|
|
211
212
|
}
|
|
212
|
-
msg = msg.replace(key,
|
|
213
|
+
msg = msg.replace(key, "");
|
|
213
214
|
let res = await getEventReply(that, item.event, msg, name, id, avatar, room);
|
|
214
215
|
return res;
|
|
215
216
|
}
|
|
@@ -218,7 +219,7 @@ async function eventMsg({ that, msg, name, id, avatar, config, room, isMention }
|
|
|
218
219
|
return [];
|
|
219
220
|
}
|
|
220
221
|
catch (e) {
|
|
221
|
-
console.log(
|
|
222
|
+
console.log("eventMsg error:", e);
|
|
222
223
|
return [];
|
|
223
224
|
}
|
|
224
225
|
}
|
|
@@ -233,7 +234,7 @@ async function keywordsMsg({ msg, config, room, isMention }) {
|
|
|
233
234
|
for (let item of config.replyKeywords) {
|
|
234
235
|
if (item.reg === 2 && item.keywords.includes(msg)) {
|
|
235
236
|
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
236
|
-
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope ===
|
|
237
|
+
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope === "friend") || (!room && item.scope === "room")) {
|
|
237
238
|
return [];
|
|
238
239
|
}
|
|
239
240
|
console.log(`精确匹配到关键词${msg},正在回复用户`);
|
|
@@ -243,7 +244,7 @@ async function keywordsMsg({ msg, config, room, isMention }) {
|
|
|
243
244
|
for (let key of item.keywords) {
|
|
244
245
|
if (msg.includes(key)) {
|
|
245
246
|
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
246
|
-
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope ===
|
|
247
|
+
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope === "friend") || (!room && item.scope === "room")) {
|
|
247
248
|
return [];
|
|
248
249
|
}
|
|
249
250
|
console.log(`模糊匹配到关键词${msg},正在回复用户`);
|
|
@@ -258,7 +259,7 @@ async function keywordsMsg({ msg, config, room, isMention }) {
|
|
|
258
259
|
}
|
|
259
260
|
}
|
|
260
261
|
catch (e) {
|
|
261
|
-
console.log(
|
|
262
|
+
console.log("keywordsMsg error:", e);
|
|
262
263
|
return [];
|
|
263
264
|
}
|
|
264
265
|
}
|
|
@@ -272,17 +273,17 @@ async function robotMsg({ msg, name, id, config, isMention, room }) {
|
|
|
272
273
|
try {
|
|
273
274
|
let msgArr = []; // 返回的消息列表
|
|
274
275
|
if (config.autoReply) {
|
|
275
|
-
console.log(
|
|
276
|
+
console.log("开启了机器人自动回复功能");
|
|
276
277
|
msgArr = await event_dispatch_service_js_1.default.dispatchAiBot(config.defaultBot, msg, name, id);
|
|
277
278
|
}
|
|
278
279
|
else {
|
|
279
|
-
console.log(
|
|
280
|
-
msgArr = [{ type: 1, content:
|
|
280
|
+
console.log("没有开启机器人自动回复功能");
|
|
281
|
+
msgArr = [{ type: 1, content: "", url: "" }];
|
|
281
282
|
}
|
|
282
283
|
return msgArr;
|
|
283
284
|
}
|
|
284
285
|
catch (e) {
|
|
285
|
-
console.log(
|
|
286
|
+
console.log("robotMsg error:", e);
|
|
286
287
|
return [];
|
|
287
288
|
}
|
|
288
289
|
}
|
|
@@ -292,7 +293,7 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
|
|
|
292
293
|
try {
|
|
293
294
|
const gptConfigs = global_js_1.default.getAllGptConfig();
|
|
294
295
|
if (gptConfigs && gptConfigs.length) {
|
|
295
|
-
let finalConfig =
|
|
296
|
+
let finalConfig = "";
|
|
296
297
|
if (room) {
|
|
297
298
|
finalConfig = room && gptConfigs.find((item) => {
|
|
298
299
|
const targetNames = [];
|
|
@@ -301,7 +302,7 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
|
|
|
301
302
|
targetNames.push(tItem.name);
|
|
302
303
|
targetIds.push(tItem.id);
|
|
303
304
|
});
|
|
304
|
-
return item.type ===
|
|
305
|
+
return item.type === "room" && (targetNames.includes(roomName) || targetIds.includes(roomId));
|
|
305
306
|
});
|
|
306
307
|
}
|
|
307
308
|
else {
|
|
@@ -312,23 +313,29 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
|
|
|
312
313
|
targetNames.push(tItem.name);
|
|
313
314
|
targetIds.push(tItem.id);
|
|
314
315
|
});
|
|
315
|
-
return item.type ===
|
|
316
|
+
return item.type === "contact" && (targetNames.includes(name) || targetIds.includes(id));
|
|
316
317
|
});
|
|
317
318
|
}
|
|
318
319
|
if (finalConfig) {
|
|
319
|
-
const isRoom = finalConfig.type ===
|
|
320
|
+
const isRoom = finalConfig.type === "room";
|
|
320
321
|
if (finalConfig.openChat) {
|
|
321
322
|
if ((isRoom && finalConfig.needAt === 1 && isMention) || isRoom & !finalConfig.needAt || !isRoom) {
|
|
322
323
|
const keyword = finalConfig?.keywords.find((item) => msg.includes(item));
|
|
323
324
|
if (keyword || !finalConfig?.keywords.length) {
|
|
324
|
-
msg = keyword ? msg.replace(keyword,
|
|
325
|
+
msg = keyword ? msg.replace(keyword, "") : msg;
|
|
325
326
|
if (finalConfig.limitNum > 0 && finalConfig.limitNum <= finalConfig.usedNum) {
|
|
326
|
-
return [{ type: 1, content: finalConfig.rechargeTip ||
|
|
327
|
+
return [{ type: 1, content: finalConfig.rechargeTip || "聊天次数已用完,请联系管理员充值" }];
|
|
327
328
|
}
|
|
328
|
-
const msgArr = await (0, dispatch_js_1.dispatchBot)({
|
|
329
|
+
const msgArr = await (0, dispatch_js_1.dispatchBot)({
|
|
330
|
+
botType: finalConfig.robotType,
|
|
331
|
+
content: msg,
|
|
332
|
+
uid: id,
|
|
333
|
+
adminId: finalConfig.id,
|
|
334
|
+
config: finalConfig.botConfig
|
|
335
|
+
});
|
|
329
336
|
if (msgArr.length)
|
|
330
337
|
return msgArr;
|
|
331
|
-
console.log(
|
|
338
|
+
console.log("自定义回复获取内容失败,启用全局配置");
|
|
332
339
|
return [];
|
|
333
340
|
}
|
|
334
341
|
}
|
|
@@ -337,7 +344,10 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
|
|
|
337
344
|
else {
|
|
338
345
|
// 如果没有开启对话 也要检测一下是不是需要@ 才返回默认回复
|
|
339
346
|
if ((isRoom && finalConfig.needAt === 1 && isMention) || isRoom & !finalConfig.needAt || !isRoom) {
|
|
340
|
-
return finalConfig.defaultReply ? [{ type: 1, content: finalConfig.defaultReply }] : [{
|
|
347
|
+
return finalConfig.defaultReply ? [{ type: 1, content: finalConfig.defaultReply }] : [{
|
|
348
|
+
type: 1,
|
|
349
|
+
content: ""
|
|
350
|
+
}];
|
|
341
351
|
}
|
|
342
352
|
return [];
|
|
343
353
|
}
|
|
@@ -347,7 +357,7 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
|
|
|
347
357
|
return [];
|
|
348
358
|
}
|
|
349
359
|
catch (e) {
|
|
350
|
-
console.log(
|
|
360
|
+
console.log("catch error:" + e);
|
|
351
361
|
return [];
|
|
352
362
|
}
|
|
353
363
|
}
|
|
@@ -360,23 +370,53 @@ exports.customChat = customChat;
|
|
|
360
370
|
* @return {*[]}
|
|
361
371
|
*/
|
|
362
372
|
function preventWordCheck({ msg, config, isMention, room }) {
|
|
363
|
-
const preventWords = config.preventWords.replaceAll(
|
|
373
|
+
const preventWords = config.preventWords.replaceAll(",", ",").split(",");
|
|
364
374
|
// 如果是群消息,但是没有提及机器人,则不需要返回任何消息 因为可能是正常交流而已
|
|
365
375
|
if (room && !isMention) {
|
|
366
376
|
return [];
|
|
367
377
|
}
|
|
368
378
|
if (preventWords && preventWords.length) {
|
|
369
379
|
for (let item of preventWords) {
|
|
370
|
-
if (item && item !==
|
|
380
|
+
if (item && item !== "" && msg.includes(item)) {
|
|
371
381
|
console.log(`触发禁止词【${item}】,不回复用户`);
|
|
372
|
-
return [{ type: 1, content:
|
|
382
|
+
return [{ type: 1, content: "这个话题不适合讨论,换个话题吧。" }];
|
|
373
383
|
}
|
|
374
384
|
}
|
|
375
385
|
}
|
|
376
386
|
return [];
|
|
377
387
|
}
|
|
378
388
|
exports.preventWordCheck = preventWordCheck;
|
|
389
|
+
async function customBot({ that, msg, name, id, config, room, isMention }) {
|
|
390
|
+
const item = config.customBot;
|
|
391
|
+
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
392
|
+
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope === "friend") || (!room && item.scope === "room")) {
|
|
393
|
+
return [];
|
|
394
|
+
}
|
|
395
|
+
const contactSelf = await (0, userDb_js_1.getUser)();
|
|
396
|
+
msg = msg.trim();
|
|
397
|
+
const topic = room ? await room.topic() : "";
|
|
398
|
+
const data = {
|
|
399
|
+
robotId: contactSelf.robotId,
|
|
400
|
+
uid: id,
|
|
401
|
+
uname: name,
|
|
402
|
+
roomId: (room && room.id) || "",
|
|
403
|
+
roomName: (room && topic) || "",
|
|
404
|
+
word: msg
|
|
405
|
+
};
|
|
406
|
+
item.moreData &&
|
|
407
|
+
item.moreData.length &&
|
|
408
|
+
item.moreData.forEach((mItem) => {
|
|
409
|
+
if (mItem.key !== "uid" && mItem.key !== "uname" && mItem.key !== "word" && mItem.key !== "roomId" && mItem.key !== "roomName" && mItem.key !== "robotId") {
|
|
410
|
+
data[mItem.key] = mItem.value;
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
const timeout = item.timeout || 60;
|
|
414
|
+
let res = await superagent_js_1.service.post(item.customUrl, data, { timeout: timeout * 1000 });
|
|
415
|
+
return res;
|
|
416
|
+
}
|
|
417
|
+
exports.customBot = customBot;
|
|
379
418
|
exports.default = {
|
|
419
|
+
customBot,
|
|
380
420
|
callbackEvent,
|
|
381
421
|
emptyMsg,
|
|
382
422
|
officialMsg,
|
package/dist/cjs/src/task/rss.js
CHANGED
|
@@ -21,7 +21,7 @@ async function getRssContent(info) {
|
|
|
21
21
|
if (feed.items && feed.items.length) {
|
|
22
22
|
// 当存在历史推送记录 需要判读是否推送过
|
|
23
23
|
const last = feed.items[0];
|
|
24
|
-
const lastContent = last.
|
|
24
|
+
const lastContent = last.link;
|
|
25
25
|
if (lastItem) {
|
|
26
26
|
if (lastContent !== lastItem.lastContent) {
|
|
27
27
|
const content = await setContent(last, info);
|
|
@@ -222,8 +222,8 @@ async function roomSay(room, contact, msg) {
|
|
|
222
222
|
const title = await formatContent(msg.title);
|
|
223
223
|
let url = new this.UrlLink({
|
|
224
224
|
description: description,
|
|
225
|
-
thumbnailUrl:
|
|
226
|
-
title:
|
|
225
|
+
thumbnailUrl: msg.thumbUrl,
|
|
226
|
+
title: title,
|
|
227
227
|
url: msg.url,
|
|
228
228
|
});
|
|
229
229
|
await room.say(url);
|
|
@@ -83,6 +83,7 @@ async function filterRoomMsg({ that, msg, name, id, avatar, room, isMention, roo
|
|
|
83
83
|
{ bool: config.eventKeywords && config.eventKeywords.length > 0, method: 'eventMsg' },
|
|
84
84
|
{ bool: true, method: 'keywordsMsg' },
|
|
85
85
|
{ bool: gptConfig && gptConfig.length > 0, method: 'customChat' },
|
|
86
|
+
{ bool: config.customBot && config.customBot.open, method: 'customBot' },
|
|
86
87
|
{ bool: config.autoReply && config.botScope !== 'friend', method: 'robotMsg' },
|
|
87
88
|
];
|
|
88
89
|
const msgArr = await getMsgReply(resArray, { that, msg, name, config, avatar, id, room, roomName, roomId, isMention });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
declare namespace _default {
|
|
2
|
+
export { customBot };
|
|
2
3
|
export { callbackEvent };
|
|
3
4
|
export { emptyMsg };
|
|
4
5
|
export { officialMsg };
|
|
@@ -13,6 +14,15 @@ declare namespace _default {
|
|
|
13
14
|
export { preventWordCheck };
|
|
14
15
|
}
|
|
15
16
|
export default _default;
|
|
17
|
+
export function customBot({ that, msg, name, id, config, room, isMention }: {
|
|
18
|
+
that: any;
|
|
19
|
+
msg: any;
|
|
20
|
+
name: any;
|
|
21
|
+
id: any;
|
|
22
|
+
config: any;
|
|
23
|
+
room: any;
|
|
24
|
+
isMention: any;
|
|
25
|
+
}): Promise<never[] | import("axios").AxiosResponse<any, any>>;
|
|
16
26
|
/**
|
|
17
27
|
* 回调函数事件
|
|
18
28
|
* @param that
|
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
import dispatch from
|
|
2
|
-
import { setSchedule, updateSchedule } from
|
|
3
|
-
import { contentDistinguish, setLocalSchedule, isRealDate } from
|
|
4
|
-
import { addRoom } from
|
|
5
|
-
import { service, callbackAibotApi } from
|
|
6
|
-
import { dispatchBot } from
|
|
1
|
+
import dispatch from "./event-dispatch-service.js";
|
|
2
|
+
import { setSchedule, updateSchedule } from "../proxy/aibotk.js";
|
|
3
|
+
import { contentDistinguish, setLocalSchedule, isRealDate } from "../lib/index.js";
|
|
4
|
+
import { addRoom } from "../common/index.js";
|
|
5
|
+
import { service, callbackAibotApi } from "../proxy/superagent.js";
|
|
6
|
+
import { dispatchBot } from "../proxy/bot/dispatch.js";
|
|
7
7
|
import globalConfig from "../db/global.js";
|
|
8
|
+
import { getUser } from "../db/userDb.js";
|
|
8
9
|
function emptyMsg({ room, isMention }) {
|
|
9
10
|
if (room && !isMention)
|
|
10
11
|
return [];
|
|
11
12
|
let msgArr = []; // 返回的消息列表
|
|
12
|
-
let obj = { type: 1, content:
|
|
13
|
+
let obj = { type: 1, content: "我在呢", url: "" }; // 消息主体
|
|
13
14
|
msgArr.push(obj);
|
|
14
15
|
return msgArr;
|
|
15
16
|
}
|
|
16
17
|
function officialMsg() {
|
|
17
|
-
console.log(
|
|
18
|
-
return [{ type: 1, content:
|
|
18
|
+
console.log("官方消息,不做回复");
|
|
19
|
+
return [{ type: 1, content: "", url: "" }];
|
|
19
20
|
}
|
|
20
21
|
function maxLengthMsg() {
|
|
21
|
-
console.log(
|
|
22
|
-
return [{ type: 1, content:
|
|
22
|
+
console.log("字符超过设定值,不做回复");
|
|
23
|
+
return [{ type: 1, content: "", url: "" }];
|
|
23
24
|
}
|
|
24
25
|
function newFriendMsg({ config, name }) {
|
|
25
26
|
console.log(`新添加好友:${name},默认回复`);
|
|
26
|
-
return config.newFriendReplys || [{ type: 1, content:
|
|
27
|
+
return config.newFriendReplys || [{ type: 1, content: "", url: "" }];
|
|
27
28
|
}
|
|
28
29
|
async function roomInviteMsg({ that, msg, contact, config }) {
|
|
29
30
|
try {
|
|
@@ -31,14 +32,14 @@ async function roomInviteMsg({ that, msg, contact, config }) {
|
|
|
31
32
|
if (item.reg === 2 && item.keywords.includes(msg)) {
|
|
32
33
|
console.log(`精确匹配到加群关键词${msg},正在邀请用户进群`);
|
|
33
34
|
await addRoom(that, contact, item.roomName, item.replys);
|
|
34
|
-
return [{ type: 1, content:
|
|
35
|
+
return [{ type: 1, content: "", url: "" }];
|
|
35
36
|
}
|
|
36
37
|
else {
|
|
37
38
|
for (let key of item.keywords) {
|
|
38
39
|
if (msg.includes(key)) {
|
|
39
40
|
console.log(`模糊匹配到加群关键词${msg},正在邀请用户进群`);
|
|
40
41
|
await addRoom(that, contact, item.roomName, item.replys);
|
|
41
|
-
return [{ type: 1, content:
|
|
42
|
+
return [{ type: 1, content: "", url: "" }];
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
}
|
|
@@ -46,7 +47,7 @@ async function roomInviteMsg({ that, msg, contact, config }) {
|
|
|
46
47
|
return [];
|
|
47
48
|
}
|
|
48
49
|
catch (e) {
|
|
49
|
-
console.log(
|
|
50
|
+
console.log("roomInviteMsg error", e);
|
|
50
51
|
return [];
|
|
51
52
|
}
|
|
52
53
|
}
|
|
@@ -66,7 +67,7 @@ async function addSchedule(that, obj) {
|
|
|
66
67
|
let contact = await that.Contact.find({ name: nickName });
|
|
67
68
|
let id = scheduleObj.id;
|
|
68
69
|
setLocalSchedule(Rule1, async () => {
|
|
69
|
-
console.log(
|
|
70
|
+
console.log("你的专属提醒开启啦!");
|
|
70
71
|
await contact.say(content);
|
|
71
72
|
if (!scheduleObj.isLoop) {
|
|
72
73
|
updateSchedule(id);
|
|
@@ -75,42 +76,42 @@ async function addSchedule(that, obj) {
|
|
|
75
76
|
return true;
|
|
76
77
|
}
|
|
77
78
|
catch (error) {
|
|
78
|
-
console.log(
|
|
79
|
+
console.log("设置定时任务失败", error);
|
|
79
80
|
return false;
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
async function scheduleJobMsg({ that, msg, name }) {
|
|
83
84
|
try {
|
|
84
|
-
let obj = { type: 1, content:
|
|
85
|
-
let msgArr = msg.replace(/\s+/g,
|
|
85
|
+
let obj = { type: 1, content: "", url: "" }; // 消息主体
|
|
86
|
+
let msgArr = msg.replace(/\s+/g, " ").split(" ");
|
|
86
87
|
if (msgArr.length > 3) {
|
|
87
88
|
let schedule = contentDistinguish(msgArr, name);
|
|
88
89
|
let time = schedule.isLoop ? schedule.time : isRealDate(schedule.time);
|
|
89
90
|
if (time) {
|
|
90
91
|
let res = await addSchedule(that, schedule);
|
|
91
92
|
if (res) {
|
|
92
|
-
obj.content =
|
|
93
|
+
obj.content = "小助手已经把你的提醒牢记在小本本上了";
|
|
93
94
|
}
|
|
94
95
|
else {
|
|
95
|
-
obj.content =
|
|
96
|
+
obj.content = "添加提醒失败,请稍后重试";
|
|
96
97
|
}
|
|
97
98
|
msgArr.push(obj);
|
|
98
99
|
return msgArr;
|
|
99
100
|
}
|
|
100
101
|
else {
|
|
101
|
-
obj.content =
|
|
102
|
+
obj.content = "提醒设置失败,请保证每个关键词之间使用空格分割开,并保证日期格式正确。正确格式为:“提醒(空格)我(空格)每天(空格)18:30(空格)下班回家";
|
|
102
103
|
msgArr.push(obj);
|
|
103
104
|
return msgArr;
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
else {
|
|
107
|
-
obj.content =
|
|
108
|
+
obj.content = "提醒设置失败,请保证每个关键词之间使用空格分割开,并保证日期格式正确。正确格式为:“提醒(空格)我(空格)18:30(空格)下班回家”";
|
|
108
109
|
msgArr.push(obj);
|
|
109
110
|
return msgArr;
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
catch (e) {
|
|
113
|
-
console.log(
|
|
114
|
+
console.log("scheduleJobMsg error:", e);
|
|
114
115
|
return [];
|
|
115
116
|
}
|
|
116
117
|
}
|
|
@@ -129,7 +130,7 @@ async function getEventReply(that, event, msg, name, id, avatar, room) {
|
|
|
129
130
|
return reply;
|
|
130
131
|
}
|
|
131
132
|
catch (e) {
|
|
132
|
-
console.log(
|
|
133
|
+
console.log("getEventReply error", e);
|
|
133
134
|
return [];
|
|
134
135
|
}
|
|
135
136
|
}
|
|
@@ -149,22 +150,22 @@ async function callbackEvent({ that, msg, name, id, config, room, isMention }) {
|
|
|
149
150
|
for (let key of item.keywords) {
|
|
150
151
|
if ((item.reg === 1 && msg.includes(key)) || (item.reg === 2 && msg === key)) {
|
|
151
152
|
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
152
|
-
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope ===
|
|
153
|
+
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope === "friend") || (!room && item.scope === "room")) {
|
|
153
154
|
return [];
|
|
154
155
|
}
|
|
155
156
|
msg = msg.trim();
|
|
156
|
-
const topic = room ? await room.topic() :
|
|
157
|
+
const topic = room ? await room.topic() : "";
|
|
157
158
|
const data = {
|
|
158
159
|
uid: id,
|
|
159
160
|
uname: name,
|
|
160
|
-
roomId: (room && room.id) ||
|
|
161
|
-
roomName: (room && topic) ||
|
|
162
|
-
word: msg
|
|
161
|
+
roomId: (room && room.id) || "",
|
|
162
|
+
roomName: (room && topic) || "",
|
|
163
|
+
word: msg
|
|
163
164
|
};
|
|
164
165
|
item.moreData &&
|
|
165
166
|
item.moreData.length &&
|
|
166
167
|
item.moreData.forEach((mItem) => {
|
|
167
|
-
if (mItem.key !==
|
|
168
|
+
if (mItem.key !== "uid" && mItem.key !== "uname" && mItem.key !== "word" && mItem.key !== "roomId" && mItem.key !== "roomName") {
|
|
168
169
|
data[mItem.key] = mItem.value;
|
|
169
170
|
}
|
|
170
171
|
});
|
|
@@ -183,7 +184,7 @@ async function callbackEvent({ that, msg, name, id, config, room, isMention }) {
|
|
|
183
184
|
return [];
|
|
184
185
|
}
|
|
185
186
|
catch (e) {
|
|
186
|
-
console.log(
|
|
187
|
+
console.log("error", e);
|
|
187
188
|
return [];
|
|
188
189
|
}
|
|
189
190
|
}
|
|
@@ -193,10 +194,10 @@ async function eventMsg({ that, msg, name, id, avatar, config, room, isMention }
|
|
|
193
194
|
for (let key of item.keywords) {
|
|
194
195
|
if ((item.reg === 1 && msg.includes(key)) || (item.reg === 2 && msg === key)) {
|
|
195
196
|
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
196
|
-
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope ===
|
|
197
|
+
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope === "friend") || (!room && item.scope === "room")) {
|
|
197
198
|
return [];
|
|
198
199
|
}
|
|
199
|
-
msg = msg.replace(key,
|
|
200
|
+
msg = msg.replace(key, "");
|
|
200
201
|
let res = await getEventReply(that, item.event, msg, name, id, avatar, room);
|
|
201
202
|
return res;
|
|
202
203
|
}
|
|
@@ -205,7 +206,7 @@ async function eventMsg({ that, msg, name, id, avatar, config, room, isMention }
|
|
|
205
206
|
return [];
|
|
206
207
|
}
|
|
207
208
|
catch (e) {
|
|
208
|
-
console.log(
|
|
209
|
+
console.log("eventMsg error:", e);
|
|
209
210
|
return [];
|
|
210
211
|
}
|
|
211
212
|
}
|
|
@@ -219,7 +220,7 @@ async function keywordsMsg({ msg, config, room, isMention }) {
|
|
|
219
220
|
for (let item of config.replyKeywords) {
|
|
220
221
|
if (item.reg === 2 && item.keywords.includes(msg)) {
|
|
221
222
|
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
222
|
-
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope ===
|
|
223
|
+
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope === "friend") || (!room && item.scope === "room")) {
|
|
223
224
|
return [];
|
|
224
225
|
}
|
|
225
226
|
console.log(`精确匹配到关键词${msg},正在回复用户`);
|
|
@@ -229,7 +230,7 @@ async function keywordsMsg({ msg, config, room, isMention }) {
|
|
|
229
230
|
for (let key of item.keywords) {
|
|
230
231
|
if (msg.includes(key)) {
|
|
231
232
|
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
232
|
-
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope ===
|
|
233
|
+
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope === "friend") || (!room && item.scope === "room")) {
|
|
233
234
|
return [];
|
|
234
235
|
}
|
|
235
236
|
console.log(`模糊匹配到关键词${msg},正在回复用户`);
|
|
@@ -244,7 +245,7 @@ async function keywordsMsg({ msg, config, room, isMention }) {
|
|
|
244
245
|
}
|
|
245
246
|
}
|
|
246
247
|
catch (e) {
|
|
247
|
-
console.log(
|
|
248
|
+
console.log("keywordsMsg error:", e);
|
|
248
249
|
return [];
|
|
249
250
|
}
|
|
250
251
|
}
|
|
@@ -257,17 +258,17 @@ async function robotMsg({ msg, name, id, config, isMention, room }) {
|
|
|
257
258
|
try {
|
|
258
259
|
let msgArr = []; // 返回的消息列表
|
|
259
260
|
if (config.autoReply) {
|
|
260
|
-
console.log(
|
|
261
|
+
console.log("开启了机器人自动回复功能");
|
|
261
262
|
msgArr = await dispatch.dispatchAiBot(config.defaultBot, msg, name, id);
|
|
262
263
|
}
|
|
263
264
|
else {
|
|
264
|
-
console.log(
|
|
265
|
-
msgArr = [{ type: 1, content:
|
|
265
|
+
console.log("没有开启机器人自动回复功能");
|
|
266
|
+
msgArr = [{ type: 1, content: "", url: "" }];
|
|
266
267
|
}
|
|
267
268
|
return msgArr;
|
|
268
269
|
}
|
|
269
270
|
catch (e) {
|
|
270
|
-
console.log(
|
|
271
|
+
console.log("robotMsg error:", e);
|
|
271
272
|
return [];
|
|
272
273
|
}
|
|
273
274
|
}
|
|
@@ -276,7 +277,7 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
|
|
|
276
277
|
try {
|
|
277
278
|
const gptConfigs = globalConfig.getAllGptConfig();
|
|
278
279
|
if (gptConfigs && gptConfigs.length) {
|
|
279
|
-
let finalConfig =
|
|
280
|
+
let finalConfig = "";
|
|
280
281
|
if (room) {
|
|
281
282
|
finalConfig = room && gptConfigs.find((item) => {
|
|
282
283
|
const targetNames = [];
|
|
@@ -285,7 +286,7 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
|
|
|
285
286
|
targetNames.push(tItem.name);
|
|
286
287
|
targetIds.push(tItem.id);
|
|
287
288
|
});
|
|
288
|
-
return item.type ===
|
|
289
|
+
return item.type === "room" && (targetNames.includes(roomName) || targetIds.includes(roomId));
|
|
289
290
|
});
|
|
290
291
|
}
|
|
291
292
|
else {
|
|
@@ -296,23 +297,29 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
|
|
|
296
297
|
targetNames.push(tItem.name);
|
|
297
298
|
targetIds.push(tItem.id);
|
|
298
299
|
});
|
|
299
|
-
return item.type ===
|
|
300
|
+
return item.type === "contact" && (targetNames.includes(name) || targetIds.includes(id));
|
|
300
301
|
});
|
|
301
302
|
}
|
|
302
303
|
if (finalConfig) {
|
|
303
|
-
const isRoom = finalConfig.type ===
|
|
304
|
+
const isRoom = finalConfig.type === "room";
|
|
304
305
|
if (finalConfig.openChat) {
|
|
305
306
|
if ((isRoom && finalConfig.needAt === 1 && isMention) || isRoom & !finalConfig.needAt || !isRoom) {
|
|
306
307
|
const keyword = finalConfig?.keywords.find((item) => msg.includes(item));
|
|
307
308
|
if (keyword || !finalConfig?.keywords.length) {
|
|
308
|
-
msg = keyword ? msg.replace(keyword,
|
|
309
|
+
msg = keyword ? msg.replace(keyword, "") : msg;
|
|
309
310
|
if (finalConfig.limitNum > 0 && finalConfig.limitNum <= finalConfig.usedNum) {
|
|
310
|
-
return [{ type: 1, content: finalConfig.rechargeTip ||
|
|
311
|
+
return [{ type: 1, content: finalConfig.rechargeTip || "聊天次数已用完,请联系管理员充值" }];
|
|
311
312
|
}
|
|
312
|
-
const msgArr = await dispatchBot({
|
|
313
|
+
const msgArr = await dispatchBot({
|
|
314
|
+
botType: finalConfig.robotType,
|
|
315
|
+
content: msg,
|
|
316
|
+
uid: id,
|
|
317
|
+
adminId: finalConfig.id,
|
|
318
|
+
config: finalConfig.botConfig
|
|
319
|
+
});
|
|
313
320
|
if (msgArr.length)
|
|
314
321
|
return msgArr;
|
|
315
|
-
console.log(
|
|
322
|
+
console.log("自定义回复获取内容失败,启用全局配置");
|
|
316
323
|
return [];
|
|
317
324
|
}
|
|
318
325
|
}
|
|
@@ -321,7 +328,10 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
|
|
|
321
328
|
else {
|
|
322
329
|
// 如果没有开启对话 也要检测一下是不是需要@ 才返回默认回复
|
|
323
330
|
if ((isRoom && finalConfig.needAt === 1 && isMention) || isRoom & !finalConfig.needAt || !isRoom) {
|
|
324
|
-
return finalConfig.defaultReply ? [{ type: 1, content: finalConfig.defaultReply }] : [{
|
|
331
|
+
return finalConfig.defaultReply ? [{ type: 1, content: finalConfig.defaultReply }] : [{
|
|
332
|
+
type: 1,
|
|
333
|
+
content: ""
|
|
334
|
+
}];
|
|
325
335
|
}
|
|
326
336
|
return [];
|
|
327
337
|
}
|
|
@@ -331,7 +341,7 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
|
|
|
331
341
|
return [];
|
|
332
342
|
}
|
|
333
343
|
catch (e) {
|
|
334
|
-
console.log(
|
|
344
|
+
console.log("catch error:" + e);
|
|
335
345
|
return [];
|
|
336
346
|
}
|
|
337
347
|
}
|
|
@@ -343,21 +353,50 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
|
|
|
343
353
|
* @return {*[]}
|
|
344
354
|
*/
|
|
345
355
|
function preventWordCheck({ msg, config, isMention, room }) {
|
|
346
|
-
const preventWords = config.preventWords.replaceAll(
|
|
356
|
+
const preventWords = config.preventWords.replaceAll(",", ",").split(",");
|
|
347
357
|
// 如果是群消息,但是没有提及机器人,则不需要返回任何消息 因为可能是正常交流而已
|
|
348
358
|
if (room && !isMention) {
|
|
349
359
|
return [];
|
|
350
360
|
}
|
|
351
361
|
if (preventWords && preventWords.length) {
|
|
352
362
|
for (let item of preventWords) {
|
|
353
|
-
if (item && item !==
|
|
363
|
+
if (item && item !== "" && msg.includes(item)) {
|
|
354
364
|
console.log(`触发禁止词【${item}】,不回复用户`);
|
|
355
|
-
return [{ type: 1, content:
|
|
365
|
+
return [{ type: 1, content: "这个话题不适合讨论,换个话题吧。" }];
|
|
356
366
|
}
|
|
357
367
|
}
|
|
358
368
|
}
|
|
359
369
|
return [];
|
|
360
370
|
}
|
|
371
|
+
async function customBot({ that, msg, name, id, config, room, isMention }) {
|
|
372
|
+
const item = config.customBot;
|
|
373
|
+
// 如果匹配到关键词 群消息要求是必须@,但是没@ 就不需要回复 || 当为群消息关键词只在好友私聊时触发 || 非群消息只在群中触发
|
|
374
|
+
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope === "friend") || (!room && item.scope === "room")) {
|
|
375
|
+
return [];
|
|
376
|
+
}
|
|
377
|
+
const contactSelf = await getUser();
|
|
378
|
+
msg = msg.trim();
|
|
379
|
+
const topic = room ? await room.topic() : "";
|
|
380
|
+
const data = {
|
|
381
|
+
robotId: contactSelf.robotId,
|
|
382
|
+
uid: id,
|
|
383
|
+
uname: name,
|
|
384
|
+
roomId: (room && room.id) || "",
|
|
385
|
+
roomName: (room && topic) || "",
|
|
386
|
+
word: msg
|
|
387
|
+
};
|
|
388
|
+
item.moreData &&
|
|
389
|
+
item.moreData.length &&
|
|
390
|
+
item.moreData.forEach((mItem) => {
|
|
391
|
+
if (mItem.key !== "uid" && mItem.key !== "uname" && mItem.key !== "word" && mItem.key !== "roomId" && mItem.key !== "roomName" && mItem.key !== "robotId") {
|
|
392
|
+
data[mItem.key] = mItem.value;
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
const timeout = item.timeout || 60;
|
|
396
|
+
let res = await service.post(item.customUrl, data, { timeout: timeout * 1000 });
|
|
397
|
+
return res;
|
|
398
|
+
}
|
|
399
|
+
export { customBot };
|
|
361
400
|
export { callbackEvent };
|
|
362
401
|
export { emptyMsg };
|
|
363
402
|
export { officialMsg };
|
|
@@ -371,6 +410,7 @@ export { maxLengthMsg };
|
|
|
371
410
|
export { customChat };
|
|
372
411
|
export { preventWordCheck };
|
|
373
412
|
export default {
|
|
413
|
+
customBot,
|
|
374
414
|
callbackEvent,
|
|
375
415
|
emptyMsg,
|
|
376
416
|
officialMsg,
|
package/dist/esm/src/task/rss.js
CHANGED
|
@@ -15,7 +15,7 @@ async function getRssContent(info) {
|
|
|
15
15
|
if (feed.items && feed.items.length) {
|
|
16
16
|
// 当存在历史推送记录 需要判读是否推送过
|
|
17
17
|
const last = feed.items[0];
|
|
18
|
-
const lastContent = last.
|
|
18
|
+
const lastContent = last.link;
|
|
19
19
|
if (lastItem) {
|
|
20
20
|
if (lastContent !== lastItem.lastContent) {
|
|
21
21
|
const content = await setContent(last, info);
|