wechaty-web-panel 1.6.54 → 1.6.55
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 +4 -0
- package/dist/cjs/src/common/index.js +34 -2
- package/dist/cjs/src/db/chatHistory.d.ts +42 -0
- package/dist/cjs/src/db/chatHistory.js +150 -0
- package/dist/cjs/src/handlers/on-friend.js +1 -1
- package/dist/cjs/src/handlers/on-message.js +5 -5
- package/dist/cjs/src/handlers/on-record-message.d.ts +3 -0
- package/dist/cjs/src/handlers/on-record-message.js +54 -0
- package/dist/cjs/src/index.d.ts +1 -0
- package/dist/cjs/src/index.js +8 -1
- package/dist/cjs/src/package-json.js +1 -1
- package/dist/cjs/src/proxy/api.d.ts +15 -45
- package/dist/cjs/src/proxy/api.js +192 -357
- package/dist/cjs/src/proxy/apib.d.ts +109 -0
- package/dist/cjs/src/proxy/apib.js +589 -0
- package/dist/cjs/src/proxy/config.d.ts +1 -2
- package/dist/cjs/src/proxy/config.js +2 -3
- package/dist/cjs/src/proxy/cozeAi.d.ts +8 -0
- package/dist/cjs/src/proxy/cozeAi.js +19 -1
- package/dist/cjs/src/proxy/difyAi.d.ts +8 -0
- package/dist/cjs/src/proxy/difyAi.js +18 -1
- package/dist/cjs/src/proxy/mqtt.js +7 -0
- package/dist/cjs/src/proxy/openAi.d.ts +9 -0
- package/dist/cjs/src/proxy/openAi.js +19 -1
- package/dist/cjs/src/service/event-dispatch-service.d.ts +9 -0
- package/dist/cjs/src/service/event-dispatch-service.js +53 -33
- package/dist/cjs/src/service/gpt4vService.js +1 -1
- package/dist/cjs/src/service/msg-filter-service.js +2 -0
- package/dist/cjs/src/service/msg-filters.d.ts +15 -0
- package/dist/cjs/src/service/msg-filters.js +33 -1
- package/dist/esm/src/common/index.js +31 -2
- package/dist/esm/src/db/chatHistory.d.ts +42 -0
- package/dist/esm/src/db/chatHistory.js +137 -0
- package/dist/esm/src/handlers/on-friend.js +1 -1
- package/dist/esm/src/handlers/on-message.js +5 -5
- package/dist/esm/src/handlers/on-record-message.d.ts +3 -0
- package/dist/esm/src/handlers/on-record-message.js +49 -0
- package/dist/esm/src/index.d.ts +1 -0
- package/dist/esm/src/index.js +7 -1
- package/dist/esm/src/package-json.js +1 -1
- package/dist/esm/src/proxy/api.d.ts +15 -45
- package/dist/esm/src/proxy/api.js +190 -376
- package/dist/esm/src/proxy/apib.d.ts +109 -0
- package/dist/esm/src/proxy/apib.js +587 -0
- package/dist/esm/src/proxy/config.d.ts +1 -2
- package/dist/esm/src/proxy/config.js +1 -2
- package/dist/esm/src/proxy/cozeAi.d.ts +8 -0
- package/dist/esm/src/proxy/cozeAi.js +17 -0
- package/dist/esm/src/proxy/difyAi.d.ts +8 -0
- package/dist/esm/src/proxy/difyAi.js +16 -0
- package/dist/esm/src/proxy/mqtt.js +7 -0
- package/dist/esm/src/proxy/openAi.d.ts +9 -0
- package/dist/esm/src/proxy/openAi.js +17 -0
- package/dist/esm/src/service/event-dispatch-service.d.ts +9 -0
- package/dist/esm/src/service/event-dispatch-service.js +54 -31
- package/dist/esm/src/service/gpt4vService.js +1 -1
- package/dist/esm/src/service/msg-filter-service.js +2 -0
- package/dist/esm/src/service/msg-filters.d.ts +15 -0
- package/dist/esm/src/service/msg-filters.js +31 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.sendRoomNotice = exports.getCountDownContent = exports.getRoomEveryDayContent = exports.updateContactAndRoom = exports.addRoomWelcomeSay = exports.roomSay = exports.contactSay = exports.addRoom = exports.updateRoomInfo = exports.updateContactInfo = exports.getNewsContent = exports.getEveryDayContent = exports.updateContactOnly = exports.updateRoomOnly = exports.getCustomContent = void 0;
|
|
4
7
|
const api_js_1 = require("../proxy/api.js");
|
|
@@ -9,6 +12,8 @@ const index_js_1 = require("../lib/index.js");
|
|
|
9
12
|
const file_box_1 = require("file-box");
|
|
10
13
|
const configDb_js_1 = require("../db/configDb.js");
|
|
11
14
|
const puppet_type_js_1 = require("../const/puppet-type.js");
|
|
15
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
16
|
+
const chatHistory_js_1 = require("../db/chatHistory.js");
|
|
12
17
|
async function formatContent(text) {
|
|
13
18
|
text = text.replaceAll('\\n', '\n');
|
|
14
19
|
const isWin = await (0, puppet_type_js_1.isWindowsPlatform)();
|
|
@@ -204,6 +209,29 @@ async function addRoomWelcomeSay(room, roomName, contactName, msg) {
|
|
|
204
209
|
}
|
|
205
210
|
}
|
|
206
211
|
exports.addRoomWelcomeSay = addRoomWelcomeSay;
|
|
212
|
+
async function addReplyHistory(that, { content, contact, room }) {
|
|
213
|
+
const config = await (0, configDb_js_1.allConfig)();
|
|
214
|
+
const { role } = config.userInfo;
|
|
215
|
+
if (role !== 'vip')
|
|
216
|
+
return;
|
|
217
|
+
const robotInfo = that.currentUser;
|
|
218
|
+
const userSelfName = robotInfo?.name(); // 机器人名称
|
|
219
|
+
const userSelfId = robotInfo?.id; // 机器人名称
|
|
220
|
+
const contactName = contact?.name(); // 接收消息人昵称
|
|
221
|
+
const contactId = contact?.id; // 接收消息人id
|
|
222
|
+
const roomName = room ? await room.topic() : '';
|
|
223
|
+
const historyItem = {
|
|
224
|
+
conversionId: room ? room.id : contactId,
|
|
225
|
+
conversionName: room ? roomName : contactName,
|
|
226
|
+
isRoom: !!room,
|
|
227
|
+
isRobot: true,
|
|
228
|
+
content: content,
|
|
229
|
+
chatName: userSelfName,
|
|
230
|
+
chatId: userSelfId,
|
|
231
|
+
time: (0, dayjs_1.default)().unix()
|
|
232
|
+
};
|
|
233
|
+
void (0, chatHistory_js_1.addHistory)(historyItem);
|
|
234
|
+
}
|
|
207
235
|
/**
|
|
208
236
|
* 群关键词回复
|
|
209
237
|
* @param {*} contact
|
|
@@ -225,6 +253,7 @@ async function roomSay(room, contact, msg) {
|
|
|
225
253
|
const content = await formatContent(msg.content);
|
|
226
254
|
// 文字
|
|
227
255
|
contact ? await room.say(content, contact) : await room.say(content);
|
|
256
|
+
void addReplyHistory(this, { content, contact: null, room: room });
|
|
228
257
|
}
|
|
229
258
|
else if (msg.type === 2 && msg.url) {
|
|
230
259
|
// url文件
|
|
@@ -235,6 +264,7 @@ async function roomSay(room, contact, msg) {
|
|
|
235
264
|
// contact ? await room.say('', contact) : ''
|
|
236
265
|
await (0, index_js_1.delay)(500);
|
|
237
266
|
await room.say(obj);
|
|
267
|
+
void addReplyHistory(this, { content: `[文件或图片](${msg.url})`, contact: null, room: room });
|
|
238
268
|
}
|
|
239
269
|
else if (msg.type === 3 && msg.url) {
|
|
240
270
|
// bse64文件
|
|
@@ -253,6 +283,7 @@ async function roomSay(room, contact, msg) {
|
|
|
253
283
|
url: msg.url,
|
|
254
284
|
});
|
|
255
285
|
await room.say(url);
|
|
286
|
+
void addReplyHistory(this, { content: `[链接](${msg.url})`, contact: null, room: room });
|
|
256
287
|
}
|
|
257
288
|
else if (msg.type === 5 && msg.appid && msg.title && msg.pagePath && msg.description && msg.thumbUrl) {
|
|
258
289
|
let miniProgram = new this.MiniProgram({
|
|
@@ -269,7 +300,6 @@ async function roomSay(room, contact, msg) {
|
|
|
269
300
|
else if (msg.type === 8 && msg.url && msg.voiceLength) {
|
|
270
301
|
const fileBox = file_box_1.FileBox.fromUrl(msg.url);
|
|
271
302
|
fileBox.mimeType = "audio/silk";
|
|
272
|
-
fileBox.mediaType = "audio/silk";
|
|
273
303
|
fileBox.metadata = {
|
|
274
304
|
voiceLength: msg.voiceLength,
|
|
275
305
|
};
|
|
@@ -303,6 +333,7 @@ async function contactSay(contact, msg, isRoom = false) {
|
|
|
303
333
|
const content = await formatContent(msg.content);
|
|
304
334
|
// 文字
|
|
305
335
|
await contact.say(content);
|
|
336
|
+
void addReplyHistory(this, { content, contact, room: null });
|
|
306
337
|
}
|
|
307
338
|
else if (msg.type === 2 && msg.url) {
|
|
308
339
|
// url文件
|
|
@@ -312,6 +343,7 @@ async function contactSay(contact, msg, isRoom = false) {
|
|
|
312
343
|
obj = file_box_1.FileBox.fromUrl(`${config_js_1.AIBOTK_OUTAPI}/convert?url=${msg.url}`);
|
|
313
344
|
}
|
|
314
345
|
await contact.say(obj);
|
|
346
|
+
void addReplyHistory(this, { content: `[文件或图片](${msg.url})`, contact, room: null });
|
|
315
347
|
}
|
|
316
348
|
else if (msg.type === 3 && msg.url) {
|
|
317
349
|
// bse64文件
|
|
@@ -328,6 +360,7 @@ async function contactSay(contact, msg, isRoom = false) {
|
|
|
328
360
|
url: msg.url,
|
|
329
361
|
});
|
|
330
362
|
await contact.say(url);
|
|
363
|
+
void addReplyHistory(this, { content: `[链接](${msg.url})`, contact, room: null });
|
|
331
364
|
}
|
|
332
365
|
else if (msg.type === 5 && msg.appid && msg.title && msg.pagePath && msg.description && msg.thumbUrl) {
|
|
333
366
|
let miniProgram = new this.MiniProgram({
|
|
@@ -344,7 +377,6 @@ async function contactSay(contact, msg, isRoom = false) {
|
|
|
344
377
|
else if (msg.type === 8 && msg.url && msg.voiceLength) {
|
|
345
378
|
const fileBox = file_box_1.FileBox.fromUrl(msg.url);
|
|
346
379
|
fileBox.mimeType = "audio/silk";
|
|
347
|
-
fileBox.mediaType = "audio/silk";
|
|
348
380
|
fileBox.metadata = {
|
|
349
381
|
voiceLength: msg.voiceLength,
|
|
350
382
|
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 记录聊天记录 记录格式
|
|
3
|
+
* { conversionId: '', conversionName: '', isRoom: false, isRobot: false, content: '内容', chatName: '用户名', chatId: '', time: '时间' }
|
|
4
|
+
* @param info
|
|
5
|
+
* @returns {Promise<unknown>}
|
|
6
|
+
*/
|
|
7
|
+
export function addHistory(info: any): Promise<unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* 获取指定群的聊天记录
|
|
10
|
+
* @param conversionId
|
|
11
|
+
* @returns {Promise<*>}
|
|
12
|
+
*/
|
|
13
|
+
export function getHistoryByConversionId(conversionId: any): Promise<any>;
|
|
14
|
+
export function getHistoryByConversionName(conversionName: any): Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* 清楚指定群的聊天记录
|
|
17
|
+
* @param conversionId
|
|
18
|
+
* @returns {Promise<void>}
|
|
19
|
+
*/
|
|
20
|
+
export function removeHistory(conversionId: any): Promise<void>;
|
|
21
|
+
export function clearHistory(): void;
|
|
22
|
+
/**
|
|
23
|
+
* 按照时间获取指定群聊的所有聊天内容
|
|
24
|
+
* @param rooName
|
|
25
|
+
* @param day 取的天数
|
|
26
|
+
* @returns {Promise<*>}
|
|
27
|
+
*/
|
|
28
|
+
export function getHistoryByTime({ id, name }: {
|
|
29
|
+
id: any;
|
|
30
|
+
name: any;
|
|
31
|
+
}, day: any): Promise<any>;
|
|
32
|
+
/**
|
|
33
|
+
* 按照数量获取指定群聊的所有聊天内容
|
|
34
|
+
* @param rooName
|
|
35
|
+
* @param day 取的天数
|
|
36
|
+
* @returns {Promise<*>}
|
|
37
|
+
*/
|
|
38
|
+
export function getHistoryByNum({ id, name }: {
|
|
39
|
+
id: any;
|
|
40
|
+
name: any;
|
|
41
|
+
}, num: any): Promise<any>;
|
|
42
|
+
//# sourceMappingURL=chatHistory.d.ts.map
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getHistoryByNum = exports.getHistoryByTime = exports.clearHistory = exports.removeHistory = exports.getHistoryByConversionName = exports.getHistoryByConversionId = exports.addHistory = void 0;
|
|
7
|
+
const nedb_js_1 = __importDefault(require("./nedb.js"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const os_1 = __importDefault(require("os"));
|
|
10
|
+
const global_js_1 = __importDefault(require("./global.js"));
|
|
11
|
+
const fs_1 = __importDefault(require("fs"));
|
|
12
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
13
|
+
let rdb = null;
|
|
14
|
+
function initDb() {
|
|
15
|
+
if (!rdb) {
|
|
16
|
+
const baseDir = path_1.default.join(os_1.default.homedir(), path_1.default.sep, ".wechaty", "wechaty-panel-cache", global_js_1.default.getApikey(), path_1.default.sep);
|
|
17
|
+
const dbpath = baseDir + "chatHistory.db";
|
|
18
|
+
if (fs_1.default.existsSync(dbpath)) {
|
|
19
|
+
fs_1.default.unlinkSync(dbpath);
|
|
20
|
+
}
|
|
21
|
+
rdb = (0, nedb_js_1.default)(dbpath);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function delDb() {
|
|
25
|
+
if (rdb) {
|
|
26
|
+
const baseDir = path_1.default.join(os_1.default.homedir(), path_1.default.sep, ".wechaty", "wechaty-panel-cache", global_js_1.default.getApikey(), path_1.default.sep);
|
|
27
|
+
const dbpath = baseDir + "chatHistory.db";
|
|
28
|
+
if (fs_1.default.existsSync(dbpath)) {
|
|
29
|
+
fs_1.default.unlinkSync(dbpath);
|
|
30
|
+
}
|
|
31
|
+
rdb = null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 记录聊天记录 记录格式
|
|
36
|
+
* { conversionId: '', conversionName: '', isRoom: false, isRobot: false, content: '内容', chatName: '用户名', chatId: '', time: '时间' }
|
|
37
|
+
* @param info
|
|
38
|
+
* @returns {Promise<unknown>}
|
|
39
|
+
*/
|
|
40
|
+
async function addHistory(info) {
|
|
41
|
+
try {
|
|
42
|
+
initDb();
|
|
43
|
+
let doc = rdb && await rdb.insert(info);
|
|
44
|
+
return doc;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.log('插入数据错误', error);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.addHistory = addHistory;
|
|
51
|
+
/**
|
|
52
|
+
* 获取指定群的聊天记录
|
|
53
|
+
* @param conversionId
|
|
54
|
+
* @returns {Promise<*>}
|
|
55
|
+
*/
|
|
56
|
+
async function getHistoryByConversionId(conversionId) {
|
|
57
|
+
try {
|
|
58
|
+
let search = rdb && await rdb.find({ conversionId }) || [];
|
|
59
|
+
return search;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.log('查询数据错误', error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.getHistoryByConversionId = getHistoryByConversionId;
|
|
66
|
+
async function getHistoryByConversionName(conversionName) {
|
|
67
|
+
try {
|
|
68
|
+
let search = rdb ? await rdb.find({ conversionName }) : [];
|
|
69
|
+
return search;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.log('查询数据错误', error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.getHistoryByConversionName = getHistoryByConversionName;
|
|
76
|
+
/**
|
|
77
|
+
* 清楚指定群的聊天记录
|
|
78
|
+
* @param conversionId
|
|
79
|
+
* @returns {Promise<void>}
|
|
80
|
+
*/
|
|
81
|
+
async function removeHistory(conversionId) {
|
|
82
|
+
try {
|
|
83
|
+
let search = await rdb.remove({ conversionId }, { multi: true });
|
|
84
|
+
return search;
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
console.log("error", e);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.removeHistory = removeHistory;
|
|
91
|
+
function clearHistory() {
|
|
92
|
+
try {
|
|
93
|
+
delDb();
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
console.log("error", e);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.clearHistory = clearHistory;
|
|
100
|
+
/**
|
|
101
|
+
* 按照时间获取指定群聊的所有聊天内容
|
|
102
|
+
* @param rooName
|
|
103
|
+
* @param day 取的天数
|
|
104
|
+
* @returns {Promise<*>}
|
|
105
|
+
*/
|
|
106
|
+
async function getHistoryByTime({ id, name }, day) {
|
|
107
|
+
try {
|
|
108
|
+
let list = [];
|
|
109
|
+
list = await getHistoryByConversionId(id);
|
|
110
|
+
if (!list.length) {
|
|
111
|
+
list = await getHistoryByConversionName(name);
|
|
112
|
+
}
|
|
113
|
+
list = list.filter(item => {
|
|
114
|
+
if (day === 0) {
|
|
115
|
+
return item.time >= (0, dayjs_1.default)().startOf('day').unix();
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
return item.time >= (0, dayjs_1.default)().unix() - day * 60 * 60;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
list.sort((a, b) => (a.time - b.time));
|
|
122
|
+
return list;
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
console.log("error", e);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.getHistoryByTime = getHistoryByTime;
|
|
129
|
+
/**
|
|
130
|
+
* 按照数量获取指定群聊的所有聊天内容
|
|
131
|
+
* @param rooName
|
|
132
|
+
* @param day 取的天数
|
|
133
|
+
* @returns {Promise<*>}
|
|
134
|
+
*/
|
|
135
|
+
async function getHistoryByNum({ id, name }, num) {
|
|
136
|
+
try {
|
|
137
|
+
let list = [];
|
|
138
|
+
list = await getHistoryByConversionId(id);
|
|
139
|
+
if (!list.length) {
|
|
140
|
+
list = await getHistoryByConversionName(name);
|
|
141
|
+
}
|
|
142
|
+
list.sort((a, b) => (b.time - a.time));
|
|
143
|
+
return list.splice(0, num);
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
console.log("error", e);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.getHistoryByNum = getHistoryByNum;
|
|
150
|
+
//# sourceMappingURL=chatHistory.js.map
|
|
@@ -22,7 +22,7 @@ async function onFriend(friendship) {
|
|
|
22
22
|
await (0, index_js_1.delay)(10000);
|
|
23
23
|
await friendship.accept();
|
|
24
24
|
}
|
|
25
|
-
else if (config.acceptFriendKeyWords.length > 0 && config.acceptFriendKeyWords.find(item =>
|
|
25
|
+
else if (config.acceptFriendKeyWords.length > 0 && config.acceptFriendKeyWords.find(item => hello.includes(item))) {
|
|
26
26
|
console.log(`触发关键词${hello},10秒后自动通过好友请求`);
|
|
27
27
|
await (0, index_js_1.delay)(10000);
|
|
28
28
|
await friendship.accept();
|
|
@@ -93,8 +93,8 @@ async function dispatchFriendFilterByMsgType(that, msg) {
|
|
|
93
93
|
}
|
|
94
94
|
replys = await (0, reply_js_1.getContactTextReply)(that, contact, content.trim());
|
|
95
95
|
for (let reply of replys) {
|
|
96
|
-
await (0, index_js_2.delay)(1000);
|
|
97
96
|
await index_js_1.contactSay.call(that, contact, reply);
|
|
97
|
+
await (0, index_js_2.delay)(200);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -130,8 +130,8 @@ async function dispatchFriendFilterByMsgType(that, msg) {
|
|
|
130
130
|
}
|
|
131
131
|
replys = await (0, reply_js_1.getContactTextReply)(that, contact, text.trim());
|
|
132
132
|
for (let reply of replys) {
|
|
133
|
-
await (0, index_js_2.delay)(1000);
|
|
134
133
|
await index_js_1.contactSay.call(that, contact, reply);
|
|
134
|
+
await (0, index_js_2.delay)(200);
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
@@ -249,8 +249,8 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
|
|
|
249
249
|
});
|
|
250
250
|
if (gpt4vReplys.length) {
|
|
251
251
|
for (let reply of gpt4vReplys) {
|
|
252
|
-
await (0, index_js_2.delay)(1000);
|
|
253
252
|
await index_js_1.roomSay.call(that, room, contact, reply);
|
|
253
|
+
await (0, index_js_2.delay)(200);
|
|
254
254
|
}
|
|
255
255
|
return;
|
|
256
256
|
}
|
|
@@ -267,8 +267,8 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
|
|
|
267
267
|
isMention: mentionSelf
|
|
268
268
|
});
|
|
269
269
|
for (let reply of replys) {
|
|
270
|
-
await (0, index_js_2.delay)(1000);
|
|
271
270
|
await index_js_1.roomSay.call(that, room, contact, reply);
|
|
271
|
+
await (0, index_js_2.delay)(200);
|
|
272
272
|
}
|
|
273
273
|
const cloudRoom = config.cloudRoom;
|
|
274
274
|
if (role === 'vip' && cloudRoom.includes(roomName) && !checkIgnore(content, ignoreRecord)) {
|
|
@@ -351,8 +351,8 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
|
|
|
351
351
|
isMention: true
|
|
352
352
|
});
|
|
353
353
|
for (let reply of replys) {
|
|
354
|
-
await (0, index_js_2.delay)(1000);
|
|
355
354
|
await index_js_1.roomSay.call(that, room, contact, reply);
|
|
355
|
+
await (0, index_js_2.delay)(200);
|
|
356
356
|
}
|
|
357
357
|
}
|
|
358
358
|
else {
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const configDb_js_1 = require("../db/configDb.js");
|
|
7
|
+
const chatHistory_js_1 = require("../db/chatHistory.js");
|
|
8
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
9
|
+
async function onRecordMessage(msg) {
|
|
10
|
+
try {
|
|
11
|
+
const config = await (0, configDb_js_1.allConfig)();
|
|
12
|
+
const { role } = config && config.userInfo || { role: 'default' };
|
|
13
|
+
const contact = msg.talker(); // 发消息人
|
|
14
|
+
const contactName = contact.name(); // 发消息人昵称
|
|
15
|
+
const room = msg.room(); // 是否为群消息
|
|
16
|
+
const roomName = room ? await room.topic() : '';
|
|
17
|
+
const msgSelf = msg.self(); // 是否自己发给自己的消息
|
|
18
|
+
const type = msg.type();
|
|
19
|
+
const isOfficial = contact.type() === this.Contact.Type.Official;
|
|
20
|
+
let content = '';
|
|
21
|
+
if (msgSelf || isOfficial || role !== 'vip')
|
|
22
|
+
return;
|
|
23
|
+
switch (type) {
|
|
24
|
+
case this.Message.Type.Text:
|
|
25
|
+
case this.Message.Type.Url:
|
|
26
|
+
if (type === this.Message.Type.Url) {
|
|
27
|
+
const urlLink = await msg.toUrlLink();
|
|
28
|
+
content = `[链接](${urlLink.url()})`;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
content = msg.text();
|
|
32
|
+
}
|
|
33
|
+
const historyItem = {
|
|
34
|
+
conversionId: room ? room.id : contact.id,
|
|
35
|
+
conversionName: room ? roomName : contactName,
|
|
36
|
+
isRoom: !!room,
|
|
37
|
+
isRobot: false,
|
|
38
|
+
content: content,
|
|
39
|
+
chatName: contactName,
|
|
40
|
+
chatId: contact.id,
|
|
41
|
+
time: (0, dayjs_1.default)().unix()
|
|
42
|
+
};
|
|
43
|
+
void (0, chatHistory_js_1.addHistory)(historyItem);
|
|
44
|
+
return;
|
|
45
|
+
default:
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
console.log('监听消息失败', e);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.default = onRecordMessage;
|
|
54
|
+
//# sourceMappingURL=on-record-message.js.map
|
package/dist/cjs/src/index.d.ts
CHANGED
package/dist/cjs/src/index.js
CHANGED
|
@@ -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.WechatyWebPanelPlugin = void 0;
|
|
6
|
+
exports.WechatyMessageRecordPlugin = exports.WechatyWebPanelPlugin = void 0;
|
|
7
7
|
const global_js_1 = __importDefault(require("./db/global.js"));
|
|
8
8
|
const aiDb_js_1 = require("./db/aiDb.js");
|
|
9
9
|
const on_scan_js_1 = __importDefault(require("./handlers/on-scan.js"));
|
|
@@ -18,6 +18,7 @@ const on_error_js_1 = __importDefault(require("./handlers/on-error.js"));
|
|
|
18
18
|
const on_roomtopic_js_1 = __importDefault(require("./handlers/on-roomtopic.js"));
|
|
19
19
|
const on_roomleave_js_1 = __importDefault(require("./handlers/on-roomleave.js"));
|
|
20
20
|
const on_verifycode_js_1 = __importDefault(require("./handlers/on-verifycode.js"));
|
|
21
|
+
const on_record_message_js_1 = __importDefault(require("./handlers/on-record-message.js"));
|
|
21
22
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
22
23
|
const originalConsoleLog = console.log;
|
|
23
24
|
// 重写 console.log 方法
|
|
@@ -78,4 +79,10 @@ function WechatyWebPanelPlugin(config = { apiKey, apiSecret, scanTimes }) {
|
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
exports.WechatyWebPanelPlugin = WechatyWebPanelPlugin;
|
|
82
|
+
function WechatyMessageRecordPlugin() {
|
|
83
|
+
return function (bot) {
|
|
84
|
+
bot.on('message', on_record_message_js_1.default);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
exports.WechatyMessageRecordPlugin = WechatyMessageRecordPlugin;
|
|
81
88
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,50 +1,9 @@
|
|
|
1
|
-
declare namespace _default {
|
|
2
|
-
export { getResByTXTL };
|
|
3
|
-
export { getResByTX };
|
|
4
|
-
export { getResByTL };
|
|
5
|
-
export { getTXweather };
|
|
6
|
-
export { getRubbishType };
|
|
7
|
-
export { getSweetWord };
|
|
8
|
-
export { getNews };
|
|
9
|
-
export { getMingYan };
|
|
10
|
-
export { getStar };
|
|
11
|
-
export { getXing };
|
|
12
|
-
export { getSkl };
|
|
13
|
-
export { getLunar };
|
|
14
|
-
export { getGoldReply };
|
|
15
|
-
export { getXhy };
|
|
16
|
-
export { getRkl };
|
|
17
|
-
export { getAvatar };
|
|
18
|
-
export { getEmo };
|
|
19
|
-
export { getMeiNv };
|
|
20
|
-
export { getCname };
|
|
21
|
-
}
|
|
22
|
-
export default _default;
|
|
23
|
-
/**
|
|
24
|
-
* 天行图灵聊天机器人
|
|
25
|
-
* @param {*} word 发送内容
|
|
26
|
-
* @param {*} id id
|
|
27
|
-
*/
|
|
28
|
-
export function getResByTXTL(word: any, id: any): Promise<any>;
|
|
29
1
|
/**
|
|
30
2
|
* 天行聊天机器人
|
|
31
3
|
* @param {*} word 内容
|
|
32
4
|
* @param {*} id id
|
|
33
5
|
*/
|
|
34
6
|
export function getResByTX(word: any, id: any): Promise<string | undefined>;
|
|
35
|
-
/**
|
|
36
|
-
* 图灵智能聊天机器人
|
|
37
|
-
* @param {*} word 内容
|
|
38
|
-
* @param {*} id id
|
|
39
|
-
*/
|
|
40
|
-
export function getResByTL(word: any, id: any): Promise<any>;
|
|
41
|
-
/**
|
|
42
|
-
* 获取天行天气
|
|
43
|
-
*/
|
|
44
|
-
export function getTXweather(city: any): Promise<{
|
|
45
|
-
weatherTips: any;
|
|
46
|
-
todayWeather: string;
|
|
47
|
-
} | undefined>;
|
|
48
7
|
/**
|
|
49
8
|
* 获取垃圾分类结果
|
|
50
9
|
* @param {String} word 垃圾名称
|
|
@@ -54,6 +13,13 @@ export function getRubbishType(word: string): Promise<string | undefined>;
|
|
|
54
13
|
* 土味情话获取
|
|
55
14
|
*/
|
|
56
15
|
export function getSweetWord(): Promise<any>;
|
|
16
|
+
/**
|
|
17
|
+
* 获取天行天气
|
|
18
|
+
*/
|
|
19
|
+
export function getTXweather(city: any): Promise<{
|
|
20
|
+
weatherTips: any;
|
|
21
|
+
todayWeather: string;
|
|
22
|
+
} | undefined>;
|
|
57
23
|
/**
|
|
58
24
|
* 获取每日新闻内容
|
|
59
25
|
* @param {*} id 新闻频道对应的ID
|
|
@@ -104,12 +70,16 @@ export function getAvatar(base: any, type: any): Promise<any>;
|
|
|
104
70
|
* @param {*} msg
|
|
105
71
|
*/
|
|
106
72
|
export function getEmo(msg: any): Promise<any>;
|
|
107
|
-
/**
|
|
108
|
-
* 获取美女图片
|
|
109
|
-
*/
|
|
110
|
-
export function getMeiNv(): Promise<any>;
|
|
111
73
|
/**
|
|
112
74
|
* 天行网络取名
|
|
113
75
|
*/
|
|
114
76
|
export function getCname(): Promise<any>;
|
|
77
|
+
/**
|
|
78
|
+
* 天行违章码查询
|
|
79
|
+
*/
|
|
80
|
+
export function getJtwfcode(code: any): Promise<string | undefined>;
|
|
81
|
+
/**
|
|
82
|
+
* 天行健康小妙招
|
|
83
|
+
*/
|
|
84
|
+
export function getHealthskill(word: any): Promise<string | undefined>;
|
|
115
85
|
//# sourceMappingURL=api.d.ts.map
|