wechaty-web-panel 1.6.33 → 1.6.34
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 +7 -0
- package/dist/cjs/src/botInstance/dify.js +9 -3
- package/dist/cjs/src/botInstance/officialOpenAi.d.ts +1 -4
- package/dist/cjs/src/botInstance/officialOpenAi.js +23 -7
- package/dist/cjs/src/common/index.d.ts +8 -0
- package/dist/cjs/src/common/index.js +10 -1
- package/dist/cjs/src/handlers/on-scan.d.ts +1 -0
- package/dist/cjs/src/handlers/on-scan.js +5 -0
- package/dist/cjs/src/lib/index.d.ts +7 -0
- package/dist/cjs/src/lib/index.js +33 -1
- package/dist/cjs/src/package-json.js +1 -1
- package/dist/cjs/src/proxy/aibotk.d.ts +18 -0
- package/dist/cjs/src/proxy/aibotk.js +48 -2
- package/dist/cjs/src/proxy/mqtt.js +5 -0
- package/dist/cjs/src/service/event-dispatch-service.d.ts +1 -1
- package/dist/cjs/src/service/event-dispatch-service.js +6 -1
- package/dist/cjs/src/service/msg-filters.d.ts +5 -4
- package/dist/cjs/src/service/msg-filters.js +9 -7
- package/dist/cjs/src/task/index.js +56 -0
- package/dist/esm/src/botInstance/dify.js +9 -3
- package/dist/esm/src/botInstance/officialOpenAi.d.ts +1 -4
- package/dist/esm/src/botInstance/officialOpenAi.js +23 -7
- package/dist/esm/src/common/index.d.ts +8 -0
- package/dist/esm/src/common/index.js +9 -1
- package/dist/esm/src/handlers/on-scan.d.ts +1 -0
- package/dist/esm/src/handlers/on-scan.js +3 -0
- package/dist/esm/src/lib/index.d.ts +7 -0
- package/dist/esm/src/lib/index.js +30 -0
- package/dist/esm/src/package-json.js +1 -1
- package/dist/esm/src/proxy/aibotk.d.ts +18 -0
- package/dist/esm/src/proxy/aibotk.js +45 -1
- package/dist/esm/src/proxy/mqtt.js +5 -0
- package/dist/esm/src/service/event-dispatch-service.d.ts +1 -1
- package/dist/esm/src/service/event-dispatch-service.js +8 -3
- package/dist/esm/src/service/msg-filters.d.ts +5 -4
- package/dist/esm/src/service/msg-filters.js +10 -8
- package/dist/esm/src/task/index.js +57 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,7 @@ const aibotk_js_1 = require("../proxy/aibotk.js");
|
|
|
9
9
|
const contentCensor_js_1 = require("../lib/contentCensor.js");
|
|
10
10
|
const puppet_type_js_1 = require("../const/puppet-type.js");
|
|
11
11
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
12
|
+
const index_js_1 = require("../lib/index.js");
|
|
12
13
|
class DifyAi {
|
|
13
14
|
constructor(config = {
|
|
14
15
|
token: '',
|
|
@@ -100,9 +101,10 @@ class DifyAi {
|
|
|
100
101
|
else {
|
|
101
102
|
message = text.replaceAll('\n', this.eol);
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
message
|
|
104
|
+
const imgs = (0, index_js_1.extractImageLinks)(message);
|
|
105
|
+
while (message.length > 1500) {
|
|
106
|
+
replys.push(message.slice(0, 1500));
|
|
107
|
+
message = message.slice(1500);
|
|
106
108
|
}
|
|
107
109
|
replys.push(message);
|
|
108
110
|
replys = replys.map(item => {
|
|
@@ -111,6 +113,10 @@ class DifyAi {
|
|
|
111
113
|
content: item.trim()
|
|
112
114
|
};
|
|
113
115
|
});
|
|
116
|
+
if (imgs.length) {
|
|
117
|
+
console.log('提取到内容中的图片', imgs);
|
|
118
|
+
replys = replys.concat(imgs);
|
|
119
|
+
}
|
|
114
120
|
return replys;
|
|
115
121
|
}
|
|
116
122
|
catch (e) {
|
|
@@ -12,6 +12,7 @@ const contentCensor_js_1 = require("../lib/contentCensor.js");
|
|
|
12
12
|
const puppet_type_js_1 = require("../const/puppet-type.js");
|
|
13
13
|
const uuid_1 = require("uuid");
|
|
14
14
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
15
|
+
const index_js_1 = require("../lib/index.js");
|
|
15
16
|
let chatGPT = null;
|
|
16
17
|
class OfficialOpenAi {
|
|
17
18
|
constructor(config = {
|
|
@@ -54,15 +55,24 @@ class OfficialOpenAi {
|
|
|
54
55
|
if (this.config.model.toLowerCase().includes('32k')) {
|
|
55
56
|
baseOptions.maxModelTokens = 32768;
|
|
56
57
|
baseOptions.maxResponseTokens = 8192;
|
|
58
|
+
} // if use GPT-4 Turbo
|
|
59
|
+
else if (this.config.model.toLowerCase().includes('1106-preview')) {
|
|
60
|
+
baseOptions.maxModelTokens = 128000;
|
|
61
|
+
baseOptions.maxResponseTokens = 4096;
|
|
57
62
|
}
|
|
58
63
|
else {
|
|
59
64
|
baseOptions.maxModelTokens = 8192;
|
|
60
65
|
baseOptions.maxResponseTokens = 2048;
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
|
-
if (this.config.model.toLowerCase().includes('gpt-3.5
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
if (this.config.model.toLowerCase().includes('gpt-3.5')) {
|
|
69
|
+
if (this.config.model.toLowerCase().includes('16k') || this.config.model.toLowerCase().includes('turbo-1106')) {
|
|
70
|
+
baseOptions.maxModelTokens = 16385;
|
|
71
|
+
baseOptions.maxResponseTokens = 4096;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
baseOptions.maxResponseTokens = 1000;
|
|
75
|
+
}
|
|
66
76
|
}
|
|
67
77
|
if (this.config.proxyUrl) {
|
|
68
78
|
console.log(`启用代理请求:${this.config.proxyUrl}`);
|
|
@@ -116,7 +126,7 @@ class OfficialOpenAi {
|
|
|
116
126
|
async getReply(content, uid, adminId = '', systemMessage = '', isFastGPT) {
|
|
117
127
|
try {
|
|
118
128
|
if (!this.chatGPT) {
|
|
119
|
-
console.log(isFastGPT ? '看到此消息说明启用了
|
|
129
|
+
console.log(isFastGPT ? '看到此消息说明启用了FastGPT' : '看到此消息说明已启用ChatGPT');
|
|
120
130
|
await this.init();
|
|
121
131
|
}
|
|
122
132
|
if (this.config.filter) {
|
|
@@ -173,9 +183,11 @@ class OfficialOpenAi {
|
|
|
173
183
|
else {
|
|
174
184
|
message = text.replaceAll('\n', this.eol);
|
|
175
185
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
186
|
+
const imgs = (0, index_js_1.extractImageLinks)(message);
|
|
187
|
+
console.log('imgs', imgs);
|
|
188
|
+
while (message.length > 1500) {
|
|
189
|
+
replys.push(message.slice(0, 1500));
|
|
190
|
+
message = message.slice(1500);
|
|
179
191
|
}
|
|
180
192
|
replys.push(message);
|
|
181
193
|
replys = replys.map(item => {
|
|
@@ -184,6 +196,10 @@ class OfficialOpenAi {
|
|
|
184
196
|
content: item.trim()
|
|
185
197
|
};
|
|
186
198
|
});
|
|
199
|
+
if (imgs.length) {
|
|
200
|
+
console.log('提取到内容中的图片', imgs);
|
|
201
|
+
replys = replys.concat(imgs);
|
|
202
|
+
}
|
|
187
203
|
return replys;
|
|
188
204
|
}
|
|
189
205
|
catch (e) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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 = void 0;
|
|
3
|
+
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
4
|
const api_js_1 = require("../proxy/api.js");
|
|
5
5
|
const aibotk_js_1 = require("../proxy/aibotk.js");
|
|
6
6
|
const userDb_js_1 = require("../db/userDb.js");
|
|
@@ -28,6 +28,15 @@ async function getNewsContent(sortId, endWord = '', num = 10) {
|
|
|
28
28
|
return content;
|
|
29
29
|
}
|
|
30
30
|
exports.getNewsContent = getNewsContent;
|
|
31
|
+
/**
|
|
32
|
+
* 获取自定义定制内容
|
|
33
|
+
* @param {*} sortId 定制Id
|
|
34
|
+
*/
|
|
35
|
+
async function getCustomContent(sortId) {
|
|
36
|
+
let news = await (0, aibotk_js_1.getCustomNews)(sortId);
|
|
37
|
+
return news;
|
|
38
|
+
}
|
|
39
|
+
exports.getCustomContent = getCustomContent;
|
|
31
40
|
/**
|
|
32
41
|
* 获取每日说内容
|
|
33
42
|
* @param {*} date 与朋友的纪念日
|
|
@@ -3,6 +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.resetScanTime = void 0;
|
|
6
7
|
const qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
|
|
7
8
|
const index_js_1 = require("../lib/index.js");
|
|
8
9
|
const aibotk_js_1 = require("../proxy/aibotk.js");
|
|
@@ -11,6 +12,10 @@ const puppetDb_js_1 = require("../db/puppetDb.js");
|
|
|
11
12
|
const global_js_1 = __importDefault(require("../db/global.js"));
|
|
12
13
|
// 限制推送二维码的次数,防止掉线后,无限推送二维码到服务器
|
|
13
14
|
let scanTime = 0;
|
|
15
|
+
function resetScanTime() {
|
|
16
|
+
scanTime = 0;
|
|
17
|
+
}
|
|
18
|
+
exports.resetScanTime = resetScanTime;
|
|
14
19
|
function getQrcodeKey(qrcode) {
|
|
15
20
|
if (!qrcode || !qrcode.startsWith('http'))
|
|
16
21
|
return;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export function delHtmlTag(str: any): any;
|
|
2
|
+
/**
|
|
3
|
+
* 提取文字中的图片链接
|
|
4
|
+
* @param text
|
|
5
|
+
* @returns {*[]}
|
|
6
|
+
*/
|
|
7
|
+
export function extractImageLinks(text: any): any[];
|
|
8
|
+
export function convertMdToText(mdContent: any): any;
|
|
2
9
|
declare namespace _default {
|
|
3
10
|
export { Base64Encode };
|
|
4
11
|
export { Base64Decode };
|
|
@@ -26,11 +26,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getNewsType = exports.groupArray = exports.cancelAllSchedule = exports.throttle = exports.msgArr = exports.contentDistinguish = exports.getFormatQuery = exports.MD5 = exports.writeFile = exports.randomRange = exports.getConstellation = exports.isRealDate = exports.formatDate = exports.getDay = exports.convertTime = exports.getToday = exports.delay = exports.parseBody = exports.setLocalSchedule = exports.Base64Decode = exports.Base64Encode = exports.delHtmlTag = void 0;
|
|
29
|
+
exports.getNewsType = exports.groupArray = exports.cancelAllSchedule = exports.throttle = exports.msgArr = exports.contentDistinguish = exports.getFormatQuery = exports.MD5 = exports.writeFile = exports.randomRange = exports.getConstellation = exports.isRealDate = exports.formatDate = exports.getDay = exports.convertTime = exports.getToday = exports.delay = exports.parseBody = exports.setLocalSchedule = exports.Base64Decode = exports.Base64Encode = exports.convertMdToText = exports.extractImageLinks = exports.delHtmlTag = void 0;
|
|
30
30
|
const crypto_1 = __importDefault(require("crypto"));
|
|
31
31
|
const schedule = __importStar(require("node-schedule"));
|
|
32
32
|
const fs_1 = __importDefault(require("fs"));
|
|
33
33
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
34
|
+
const marked_1 = require("marked");
|
|
34
35
|
/**
|
|
35
36
|
* 设置定时器
|
|
36
37
|
* @param {*} date 日期
|
|
@@ -496,6 +497,37 @@ function delHtmlTag(str) {
|
|
|
496
497
|
return str.replace(/<[^>]+>/g, ""); //去掉所有的html标记
|
|
497
498
|
}
|
|
498
499
|
exports.delHtmlTag = delHtmlTag;
|
|
500
|
+
/**
|
|
501
|
+
* 提取文字中的图片链接
|
|
502
|
+
* @param text
|
|
503
|
+
* @returns {*[]}
|
|
504
|
+
*/
|
|
505
|
+
function extractImageLinks(text) {
|
|
506
|
+
const httpRegex = /(http:\/\/\S+\.(?:jpg|png|gif|webp|jpeg))/g;
|
|
507
|
+
const httpsRegex = /(https:\/\/\S+\.(?:jpg|png|gif|webp|jpeg))/g;
|
|
508
|
+
const mdRegexHttps = /!\[[^\]]*\]\((https?:\/\/\S+)\)/g;
|
|
509
|
+
const mdRegexHttp = /!\[[^\]]*\]\((http?:\/\/\S+)\)/g;
|
|
510
|
+
let imageLinks = [];
|
|
511
|
+
let match;
|
|
512
|
+
while ((match = httpRegex.exec(text)) !== null) {
|
|
513
|
+
imageLinks.push(match[0]);
|
|
514
|
+
}
|
|
515
|
+
while ((match = httpsRegex.exec(text)) !== null) {
|
|
516
|
+
imageLinks.push(match[0]);
|
|
517
|
+
}
|
|
518
|
+
while ((match = mdRegexHttp.exec(text)) !== null || (match = mdRegexHttps.exec(text)) !== null) {
|
|
519
|
+
imageLinks.push(match[1]);
|
|
520
|
+
}
|
|
521
|
+
return imageLinks.map(item => ({ type: 2, url: item }));
|
|
522
|
+
}
|
|
523
|
+
exports.extractImageLinks = extractImageLinks;
|
|
524
|
+
function convertMdToText(mdContent) {
|
|
525
|
+
// 使用 marked 库将 md 格式的内容转换成文本格式
|
|
526
|
+
const textContent = (0, marked_1.marked)(mdContent, { gfm: true });
|
|
527
|
+
return textContent;
|
|
528
|
+
}
|
|
529
|
+
exports.convertMdToText = convertMdToText;
|
|
530
|
+
;
|
|
499
531
|
exports.default = {
|
|
500
532
|
Base64Encode,
|
|
501
533
|
Base64Decode,
|
|
@@ -10,6 +10,24 @@ export function getWordCloudConfig(roomName: any): Promise<any>;
|
|
|
10
10
|
* 获取词云图片
|
|
11
11
|
*/
|
|
12
12
|
export function getWordCloud(wordcontent: any, background: any, border: any): Promise<string | undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* 获取自定义内容
|
|
15
|
+
* @param id
|
|
16
|
+
* @returns {Promise<[{type: number, content: string}]|*[]>}
|
|
17
|
+
*/
|
|
18
|
+
export function getCustomNews(id: any): Promise<[{
|
|
19
|
+
type: number;
|
|
20
|
+
content: string;
|
|
21
|
+
}] | any[]>;
|
|
22
|
+
/**
|
|
23
|
+
* 获取自定义技能
|
|
24
|
+
* @param params
|
|
25
|
+
* @returns {Promise<[{type: number, content: string}]|*[]>}
|
|
26
|
+
*/
|
|
27
|
+
export function getCustomEvents(params: any): Promise<[{
|
|
28
|
+
type: number;
|
|
29
|
+
content: string;
|
|
30
|
+
}] | any[]>;
|
|
13
31
|
/**
|
|
14
32
|
* 获取gpt配置
|
|
15
33
|
* @return {Promise<*>}
|
|
@@ -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.getPromotInfo = exports.updateChatRecord = exports.getFireNews = exports.getMaterial = exports.getOne = exports.getMeiNv = exports.getMqttConfig = exports.updatePanelVersion = exports.asyncData = exports.sendRoom = exports.sendFriend = exports.putqn = exports.sendRobotInfo = exports.sendHeartBeat = exports.setQrCode = exports.updateSchedule = exports.setSchedule = exports.getScheduleList = exports.getConfig = exports.clearVerifyCode = exports.getVerifyCode = exports.getPanelVersion = exports.getRssConfig = exports.getTasks = exports.getGptConfig = exports.getWordCloud = exports.getWordCloudConfig = exports.getWordCloudRoom = void 0;
|
|
6
|
+
exports.getPromotInfo = exports.updateChatRecord = exports.getFireNews = exports.getMaterial = exports.getOne = exports.getMeiNv = exports.getMqttConfig = exports.updatePanelVersion = exports.asyncData = exports.sendRoom = exports.sendFriend = exports.putqn = exports.sendRobotInfo = exports.sendHeartBeat = exports.setQrCode = exports.updateSchedule = exports.setSchedule = exports.getScheduleList = exports.getConfig = exports.clearVerifyCode = exports.getVerifyCode = exports.getPanelVersion = exports.getRssConfig = exports.getTasks = exports.getGptConfig = exports.getCustomEvents = exports.getCustomNews = exports.getWordCloud = exports.getWordCloudConfig = exports.getWordCloudRoom = void 0;
|
|
7
7
|
const superagent_js_1 = require("./superagent.js");
|
|
8
8
|
const configDb_js_1 = require("../db/configDb.js");
|
|
9
9
|
const package_json_js_1 = require("../package-json.js");
|
|
@@ -140,7 +140,7 @@ async function getFireNews(id, num) {
|
|
|
140
140
|
1001: '您可以 @消防小助手+新闻标题,通过ChatGPT为您分析时事新闻!',
|
|
141
141
|
1002: '您可以 @消防小助手+新闻标题,通过ChatGPT为您分析今日消防行业招标信息!',
|
|
142
142
|
};
|
|
143
|
-
return `${news}…………………………${eol}${eol}${endMap[id]}`;
|
|
143
|
+
return `${news}…………………………${eol}${eol}${endMap[id] || ''}`;
|
|
144
144
|
}
|
|
145
145
|
catch (e) {
|
|
146
146
|
console.log('获取每日一句失败', e);
|
|
@@ -148,6 +148,52 @@ async function getFireNews(id, num) {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
exports.getFireNews = getFireNews;
|
|
151
|
+
/**
|
|
152
|
+
* 获取自定义内容
|
|
153
|
+
* @param id
|
|
154
|
+
* @returns {Promise<[{type: number, content: string}]|*[]>}
|
|
155
|
+
*/
|
|
156
|
+
async function getCustomNews(id) {
|
|
157
|
+
try {
|
|
158
|
+
let option = {
|
|
159
|
+
method: 'GET',
|
|
160
|
+
url: '/customnews',
|
|
161
|
+
params: {
|
|
162
|
+
id
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
let content = await (0, superagent_js_1.aiBotReq)(option);
|
|
166
|
+
let newContent = content.data || [];
|
|
167
|
+
return newContent;
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
console.log('定制内容获取失败', e);
|
|
171
|
+
return [{ type: 1, content: '定制内容获取失败' }];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.getCustomNews = getCustomNews;
|
|
175
|
+
/**
|
|
176
|
+
* 获取自定义技能
|
|
177
|
+
* @param params
|
|
178
|
+
* @returns {Promise<[{type: number, content: string}]|*[]>}
|
|
179
|
+
*/
|
|
180
|
+
async function getCustomEvents(params) {
|
|
181
|
+
try {
|
|
182
|
+
let option = {
|
|
183
|
+
method: 'POST',
|
|
184
|
+
url: '/customevent',
|
|
185
|
+
params,
|
|
186
|
+
};
|
|
187
|
+
let content = await (0, superagent_js_1.aiBotReq)(option);
|
|
188
|
+
let newContent = content.data || [];
|
|
189
|
+
return newContent;
|
|
190
|
+
}
|
|
191
|
+
catch (e) {
|
|
192
|
+
console.log('自定义技能获取失败', e);
|
|
193
|
+
return [{ type: 1, content: '自定义技能获取失败' }];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
exports.getCustomEvents = getCustomEvents;
|
|
151
197
|
/**
|
|
152
198
|
* 获取配置文件
|
|
153
199
|
* @returns {Promise<*>}
|
|
@@ -39,6 +39,7 @@ const chatgpt_web_js_1 = require("./bot/chatgpt-web.js");
|
|
|
39
39
|
const dify_js_1 = require("./bot/dify.js");
|
|
40
40
|
const rss_js_1 = require("../task/rss.js");
|
|
41
41
|
const global_js_1 = __importDefault(require("../db/global.js"));
|
|
42
|
+
const on_scan_js_1 = require("../handlers/on-scan.js");
|
|
42
43
|
let mqttclient = null;
|
|
43
44
|
async function sendRoomSay(that, room, messages) {
|
|
44
45
|
console.log(`收到群:${room.name}批量发送消息请求, 消息数量【${messages.length}】`);
|
|
@@ -191,6 +192,10 @@ async function initMqtt(that) {
|
|
|
191
192
|
console.log('强制更新二维码');
|
|
192
193
|
await this.refreshQrCode();
|
|
193
194
|
}
|
|
195
|
+
else if (content.target === 'getNewQrCode') {
|
|
196
|
+
console.log('获取最新二维码');
|
|
197
|
+
(0, on_scan_js_1.resetScanTime)();
|
|
198
|
+
}
|
|
194
199
|
else if (content.target === 'verifyCode') {
|
|
195
200
|
console.log('触发了输入验证码事件');
|
|
196
201
|
if (global_js_1.default.getVerifyId() === global_js_1.default.getQrKey()) {
|
|
@@ -12,7 +12,7 @@ export default _default;
|
|
|
12
12
|
* @param avatar
|
|
13
13
|
* @returns {string} 内容
|
|
14
14
|
*/
|
|
15
|
-
export function dispatchEventContent(that: any, eName: string, msg: string, name: any, id: any, avatar: any, room: any): string;
|
|
15
|
+
export function dispatchEventContent(that: any, eName: string, msg: string, name: any, id: any, avatar: any, room: any, roomName: any, sourceMsg: any): string;
|
|
16
16
|
/**
|
|
17
17
|
* 派发不同的机器人处理回复内容
|
|
18
18
|
* @param {*} bot 机器人类别 0 天行机器人 1 天行的图灵机器人 2 图灵机器人 3 腾讯闲聊机器人
|
|
@@ -23,9 +23,13 @@ const difyAi_js_1 = require("../proxy/difyAi.js");
|
|
|
23
23
|
* @param avatar
|
|
24
24
|
* @returns {string} 内容
|
|
25
25
|
*/
|
|
26
|
-
async function dispatchEventContent(that, eName, msg, name, id, avatar, room) {
|
|
26
|
+
async function dispatchEventContent(that, eName, msg, name, id, avatar, room, roomName, sourceMsg) {
|
|
27
27
|
try {
|
|
28
28
|
let content = '', type = 1, url = '';
|
|
29
|
+
if (eName.includes('event-')) {
|
|
30
|
+
const res = await (0, aibotk_js_1.getCustomEvents)({ msg: msg || '', sourceMsg: sourceMsg || '', wxid: id, name, eventId: eName, roomName: roomName || '' });
|
|
31
|
+
return res;
|
|
32
|
+
}
|
|
29
33
|
switch (eName) {
|
|
30
34
|
case 'rubbish':
|
|
31
35
|
content = await api_js_1.default.getRubbishType(msg);
|
|
@@ -112,6 +116,7 @@ async function dispatchEventContent(that, eName, msg, name, id, avatar, room) {
|
|
|
112
116
|
await (0, aibotk_js_1.getConfig)();
|
|
113
117
|
await (0, index_js_2.initTaskLocalSchedule)(that);
|
|
114
118
|
await (0, index_js_2.initTimeSchedule)(that);
|
|
119
|
+
await (0, index_js_2.initMultiTask)(that);
|
|
115
120
|
(0, openAiHook_js_1.reset)();
|
|
116
121
|
(0, openAi_js_1.reset)();
|
|
117
122
|
(0, difyAi_js_1.reset)();
|
|
@@ -45,11 +45,11 @@ export function callbackEvent({ that, msg, name, id, config, room, isMention }:
|
|
|
45
45
|
export function emptyMsg({ room, isMention }: {
|
|
46
46
|
room: any;
|
|
47
47
|
isMention: any;
|
|
48
|
-
}): {
|
|
48
|
+
}): Promise<{
|
|
49
49
|
type: number;
|
|
50
|
-
content:
|
|
50
|
+
content: any;
|
|
51
51
|
url: string;
|
|
52
|
-
}[]
|
|
52
|
+
}[]>;
|
|
53
53
|
export function officialMsg(): {
|
|
54
54
|
type: number;
|
|
55
55
|
content: string;
|
|
@@ -74,7 +74,7 @@ export function scheduleJobMsg({ that, msg, name }: {
|
|
|
74
74
|
msg: any;
|
|
75
75
|
name: any;
|
|
76
76
|
}): Promise<any>;
|
|
77
|
-
export function eventMsg({ that, msg, name, id, avatar, config, room, isMention }: {
|
|
77
|
+
export function eventMsg({ that, msg, name, id, avatar, config, room, isMention, roomName }: {
|
|
78
78
|
that: any;
|
|
79
79
|
msg: any;
|
|
80
80
|
name: any;
|
|
@@ -83,6 +83,7 @@ export function eventMsg({ that, msg, name, id, avatar, config, room, isMention
|
|
|
83
83
|
config: any;
|
|
84
84
|
room: any;
|
|
85
85
|
isMention: any;
|
|
86
|
+
roomName: any;
|
|
86
87
|
}): Promise<string | never[]>;
|
|
87
88
|
/**
|
|
88
89
|
* 关键词回复
|
|
@@ -12,11 +12,13 @@ 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
14
|
const userDb_js_1 = require("../db/userDb.js");
|
|
15
|
-
|
|
15
|
+
const configDb_js_1 = require("../db/configDb.js");
|
|
16
|
+
async function emptyMsg({ room, isMention }) {
|
|
17
|
+
const config = await (0, configDb_js_1.allConfig)();
|
|
16
18
|
if (room && !isMention)
|
|
17
19
|
return [];
|
|
18
20
|
let msgArr = []; // 返回的消息列表
|
|
19
|
-
let obj = { type: 1, content:
|
|
21
|
+
let obj = { type: 1, content: config.defaultReply, url: "" }; // 消息主体
|
|
20
22
|
msgArr.push(obj);
|
|
21
23
|
return msgArr;
|
|
22
24
|
}
|
|
@@ -136,9 +138,9 @@ exports.scheduleJobMsg = scheduleJobMsg;
|
|
|
136
138
|
* @param avatar 用户头像
|
|
137
139
|
* @returns {String}
|
|
138
140
|
*/
|
|
139
|
-
async function getEventReply(that, event, msg, name, id, avatar, room) {
|
|
141
|
+
async function getEventReply(that, event, msg, name, id, avatar, room, roomName, sourceMsg) {
|
|
140
142
|
try {
|
|
141
|
-
let reply = await event_dispatch_service_js_1.default.dispatchEventContent(that, event, msg, name, id, avatar, room);
|
|
143
|
+
let reply = await event_dispatch_service_js_1.default.dispatchEventContent(that, event, msg, name, id, avatar, room, roomName, sourceMsg);
|
|
142
144
|
return reply;
|
|
143
145
|
}
|
|
144
146
|
catch (e) {
|
|
@@ -201,7 +203,7 @@ async function callbackEvent({ that, msg, name, id, config, room, isMention }) {
|
|
|
201
203
|
}
|
|
202
204
|
}
|
|
203
205
|
exports.callbackEvent = callbackEvent;
|
|
204
|
-
async function eventMsg({ that, msg, name, id, avatar, config, room, isMention }) {
|
|
206
|
+
async function eventMsg({ that, msg, name, id, avatar, config, room, isMention, roomName }) {
|
|
205
207
|
try {
|
|
206
208
|
for (let item of config.eventKeywords) {
|
|
207
209
|
for (let key of item.keywords) {
|
|
@@ -210,8 +212,8 @@ async function eventMsg({ that, msg, name, id, avatar, config, room, isMention }
|
|
|
210
212
|
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope === "friend") || (!room && item.scope === "room")) {
|
|
211
213
|
return [];
|
|
212
214
|
}
|
|
213
|
-
|
|
214
|
-
let res = await getEventReply(that, item.event,
|
|
215
|
+
const replaceMsg = msg.replace(key, "");
|
|
216
|
+
let res = await getEventReply(that, item.event, replaceMsg, name, id, avatar, room, roomName, msg);
|
|
215
217
|
return res;
|
|
216
218
|
}
|
|
217
219
|
}
|
|
@@ -146,6 +146,45 @@ const sendNews = async ({ that, target, item, isMulti, targets }) => {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* 发送自定义定制内容
|
|
151
|
+
* @param that
|
|
152
|
+
* @param target
|
|
153
|
+
* @param type 类型 room contact
|
|
154
|
+
* @param item
|
|
155
|
+
* @param isMulti 是否多个目标
|
|
156
|
+
* @param targets 发送的多个目标
|
|
157
|
+
* @return {Promise<void>}
|
|
158
|
+
*/
|
|
159
|
+
const sendCustomContent = async ({ that, target, type, item, isMulti, targets }) => {
|
|
160
|
+
let contents = await (0, index_js_2.getCustomContent)(item.sortId);
|
|
161
|
+
console.log("定制内容发送", contents);
|
|
162
|
+
if (!isMulti) {
|
|
163
|
+
for (const reply of contents) {
|
|
164
|
+
await (0, index_js_2.contactSay)(target, reply);
|
|
165
|
+
await (0, index_js_1.delay)(200);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
for (let single of targets) {
|
|
170
|
+
try {
|
|
171
|
+
for (const reply of contents) {
|
|
172
|
+
type === 'room' ? await (0, index_js_2.roomSay)(single, '', reply) : await (0, index_js_2.contactSay)(single, reply);
|
|
173
|
+
await (0, index_js_1.delay)(200);
|
|
174
|
+
}
|
|
175
|
+
if (item.delay) {
|
|
176
|
+
await (0, index_js_1.delay)(item.delay);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
await (0, index_js_1.delay)(800);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
console.log(`定时任务失败,可能群已经解散或者好友不存在: ${e}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
149
188
|
/**
|
|
150
189
|
* 发送每日说
|
|
151
190
|
* @param that
|
|
@@ -379,6 +418,9 @@ async function sendMultiTaskMessage(that, task) {
|
|
|
379
418
|
else if (task.taskType === "countdown") {
|
|
380
419
|
await sendCountDown({ that, isMulti: true, targets, item: task.taskInfo });
|
|
381
420
|
}
|
|
421
|
+
else if (task.taskType === "customContent") {
|
|
422
|
+
await sendCustomContent({ that, isMulti: true, targets, type: task.type, item: task.taskInfo });
|
|
423
|
+
}
|
|
382
424
|
}
|
|
383
425
|
catch (error) {
|
|
384
426
|
console.log("立即发送定时任务失败:", error);
|
|
@@ -414,6 +456,14 @@ async function startSendMultiTask({ that, task }) {
|
|
|
414
456
|
item: task.taskInfo
|
|
415
457
|
});
|
|
416
458
|
}
|
|
459
|
+
else if (task.taskType === "customContent") {
|
|
460
|
+
await sendCustomContent({
|
|
461
|
+
that,
|
|
462
|
+
isMulti: true,
|
|
463
|
+
targets,
|
|
464
|
+
item: task.taskInfo
|
|
465
|
+
});
|
|
466
|
+
}
|
|
417
467
|
}
|
|
418
468
|
async function setMultiTask(that, task) {
|
|
419
469
|
try {
|
|
@@ -435,6 +485,12 @@ async function setMultiTask(that, task) {
|
|
|
435
485
|
task
|
|
436
486
|
}), `schedule_countdown_${task.id}`);
|
|
437
487
|
}
|
|
488
|
+
else if (task.taskType === "customContent") {
|
|
489
|
+
(0, index_js_1.setLocalSchedule)(task.cron, startSendMultiTask.bind(null, {
|
|
490
|
+
that,
|
|
491
|
+
task
|
|
492
|
+
}), `schedule_customcontent_${task.id}`);
|
|
493
|
+
}
|
|
438
494
|
}
|
|
439
495
|
catch (e) {
|
|
440
496
|
console.log("catch error:" + e);
|
|
@@ -4,6 +4,7 @@ import { getPromotInfo } from "../proxy/aibotk.js";
|
|
|
4
4
|
import { ContentCensor } from "../lib/contentCensor.js";
|
|
5
5
|
import { getPuppetEol } from "../const/puppet-type.js";
|
|
6
6
|
import dayjs from "dayjs";
|
|
7
|
+
import { extractImageLinks } from '../lib/index.js';
|
|
7
8
|
class DifyAi {
|
|
8
9
|
constructor(config = {
|
|
9
10
|
token: '',
|
|
@@ -95,9 +96,10 @@ class DifyAi {
|
|
|
95
96
|
else {
|
|
96
97
|
message = text.replaceAll('\n', this.eol);
|
|
97
98
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
message
|
|
99
|
+
const imgs = extractImageLinks(message);
|
|
100
|
+
while (message.length > 1500) {
|
|
101
|
+
replys.push(message.slice(0, 1500));
|
|
102
|
+
message = message.slice(1500);
|
|
101
103
|
}
|
|
102
104
|
replys.push(message);
|
|
103
105
|
replys = replys.map(item => {
|
|
@@ -106,6 +108,10 @@ class DifyAi {
|
|
|
106
108
|
content: item.trim()
|
|
107
109
|
};
|
|
108
110
|
});
|
|
111
|
+
if (imgs.length) {
|
|
112
|
+
console.log('提取到内容中的图片', imgs);
|
|
113
|
+
replys = replys.concat(imgs);
|
|
114
|
+
}
|
|
109
115
|
return replys;
|
|
110
116
|
}
|
|
111
117
|
catch (e) {
|
|
@@ -7,6 +7,7 @@ import { ContentCensor } from "../lib/contentCensor.js";
|
|
|
7
7
|
import { getPuppetEol } from "../const/puppet-type.js";
|
|
8
8
|
import { v4 as uuidv4 } from "uuid";
|
|
9
9
|
import dayjs from "dayjs";
|
|
10
|
+
import { extractImageLinks } from '../lib/index.js';
|
|
10
11
|
let chatGPT = null;
|
|
11
12
|
class OfficialOpenAi {
|
|
12
13
|
constructor(config = {
|
|
@@ -49,15 +50,24 @@ class OfficialOpenAi {
|
|
|
49
50
|
if (this.config.model.toLowerCase().includes('32k')) {
|
|
50
51
|
baseOptions.maxModelTokens = 32768;
|
|
51
52
|
baseOptions.maxResponseTokens = 8192;
|
|
53
|
+
} // if use GPT-4 Turbo
|
|
54
|
+
else if (this.config.model.toLowerCase().includes('1106-preview')) {
|
|
55
|
+
baseOptions.maxModelTokens = 128000;
|
|
56
|
+
baseOptions.maxResponseTokens = 4096;
|
|
52
57
|
}
|
|
53
58
|
else {
|
|
54
59
|
baseOptions.maxModelTokens = 8192;
|
|
55
60
|
baseOptions.maxResponseTokens = 2048;
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
|
-
if (this.config.model.toLowerCase().includes('gpt-3.5
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
if (this.config.model.toLowerCase().includes('gpt-3.5')) {
|
|
64
|
+
if (this.config.model.toLowerCase().includes('16k') || this.config.model.toLowerCase().includes('turbo-1106')) {
|
|
65
|
+
baseOptions.maxModelTokens = 16385;
|
|
66
|
+
baseOptions.maxResponseTokens = 4096;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
baseOptions.maxResponseTokens = 1000;
|
|
70
|
+
}
|
|
61
71
|
}
|
|
62
72
|
if (this.config.proxyUrl) {
|
|
63
73
|
console.log(`启用代理请求:${this.config.proxyUrl}`);
|
|
@@ -111,7 +121,7 @@ class OfficialOpenAi {
|
|
|
111
121
|
async getReply(content, uid, adminId = '', systemMessage = '', isFastGPT) {
|
|
112
122
|
try {
|
|
113
123
|
if (!this.chatGPT) {
|
|
114
|
-
console.log(isFastGPT ? '看到此消息说明启用了
|
|
124
|
+
console.log(isFastGPT ? '看到此消息说明启用了FastGPT' : '看到此消息说明已启用ChatGPT');
|
|
115
125
|
await this.init();
|
|
116
126
|
}
|
|
117
127
|
if (this.config.filter) {
|
|
@@ -168,9 +178,11 @@ class OfficialOpenAi {
|
|
|
168
178
|
else {
|
|
169
179
|
message = text.replaceAll('\n', this.eol);
|
|
170
180
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
181
|
+
const imgs = extractImageLinks(message);
|
|
182
|
+
console.log('imgs', imgs);
|
|
183
|
+
while (message.length > 1500) {
|
|
184
|
+
replys.push(message.slice(0, 1500));
|
|
185
|
+
message = message.slice(1500);
|
|
174
186
|
}
|
|
175
187
|
replys.push(message);
|
|
176
188
|
replys = replys.map(item => {
|
|
@@ -179,6 +191,10 @@ class OfficialOpenAi {
|
|
|
179
191
|
content: item.trim()
|
|
180
192
|
};
|
|
181
193
|
});
|
|
194
|
+
if (imgs.length) {
|
|
195
|
+
console.log('提取到内容中的图片', imgs);
|
|
196
|
+
replys = replys.concat(imgs);
|
|
197
|
+
}
|
|
182
198
|
return replys;
|
|
183
199
|
}
|
|
184
200
|
catch (e) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getNews, getTXweather, getSweetWord } from '../proxy/api.js';
|
|
2
|
-
import { sendFriend, sendRoom, asyncData, getOne, getMaterial } from '../proxy/aibotk.js';
|
|
2
|
+
import { sendFriend, sendRoom, asyncData, getOne, getMaterial, getCustomNews } from '../proxy/aibotk.js';
|
|
3
3
|
import { getUser } from '../db/userDb.js';
|
|
4
4
|
import { formatDate, getDay, groupArray, delay } from '../lib/index.js';
|
|
5
5
|
import { FileBox } from 'file-box';
|
|
@@ -24,6 +24,14 @@ async function getNewsContent(sortId, endWord = '', num = 10) {
|
|
|
24
24
|
let content = `${today}${eol}${news}${eol}${endWord ? '————————' : ''}${endWord}`;
|
|
25
25
|
return content;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* 获取自定义定制内容
|
|
29
|
+
* @param {*} sortId 定制Id
|
|
30
|
+
*/
|
|
31
|
+
export async function getCustomContent(sortId) {
|
|
32
|
+
let news = await getCustomNews(sortId);
|
|
33
|
+
return news;
|
|
34
|
+
}
|
|
27
35
|
/**
|
|
28
36
|
* 获取每日说内容
|
|
29
37
|
* @param {*} date 与朋友的纪念日
|
|
@@ -6,6 +6,9 @@ import { updatePuppetConfig } from "../db/puppetDb.js";
|
|
|
6
6
|
import globalConfig from '../db/global.js';
|
|
7
7
|
// 限制推送二维码的次数,防止掉线后,无限推送二维码到服务器
|
|
8
8
|
let scanTime = 0;
|
|
9
|
+
export function resetScanTime() {
|
|
10
|
+
scanTime = 0;
|
|
11
|
+
}
|
|
9
12
|
function getQrcodeKey(qrcode) {
|
|
10
13
|
if (!qrcode || !qrcode.startsWith('http'))
|
|
11
14
|
return;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export function delHtmlTag(str: any): any;
|
|
2
|
+
/**
|
|
3
|
+
* 提取文字中的图片链接
|
|
4
|
+
* @param text
|
|
5
|
+
* @returns {*[]}
|
|
6
|
+
*/
|
|
7
|
+
export function extractImageLinks(text: any): any[];
|
|
8
|
+
export function convertMdToText(mdContent: any): any;
|
|
2
9
|
declare namespace _default {
|
|
3
10
|
export { Base64Encode };
|
|
4
11
|
export { Base64Decode };
|
|
@@ -2,6 +2,7 @@ import Crypto from 'crypto';
|
|
|
2
2
|
import * as schedule from 'node-schedule';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import dayjs from "dayjs";
|
|
5
|
+
import { marked } from 'marked';
|
|
5
6
|
/**
|
|
6
7
|
* 设置定时器
|
|
7
8
|
* @param {*} date 日期
|
|
@@ -445,6 +446,35 @@ function groupArray(array, subGroupLength) {
|
|
|
445
446
|
export function delHtmlTag(str) {
|
|
446
447
|
return str.replace(/<[^>]+>/g, ""); //去掉所有的html标记
|
|
447
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* 提取文字中的图片链接
|
|
451
|
+
* @param text
|
|
452
|
+
* @returns {*[]}
|
|
453
|
+
*/
|
|
454
|
+
export function extractImageLinks(text) {
|
|
455
|
+
const httpRegex = /(http:\/\/\S+\.(?:jpg|png|gif|webp|jpeg))/g;
|
|
456
|
+
const httpsRegex = /(https:\/\/\S+\.(?:jpg|png|gif|webp|jpeg))/g;
|
|
457
|
+
const mdRegexHttps = /!\[[^\]]*\]\((https?:\/\/\S+)\)/g;
|
|
458
|
+
const mdRegexHttp = /!\[[^\]]*\]\((http?:\/\/\S+)\)/g;
|
|
459
|
+
let imageLinks = [];
|
|
460
|
+
let match;
|
|
461
|
+
while ((match = httpRegex.exec(text)) !== null) {
|
|
462
|
+
imageLinks.push(match[0]);
|
|
463
|
+
}
|
|
464
|
+
while ((match = httpsRegex.exec(text)) !== null) {
|
|
465
|
+
imageLinks.push(match[0]);
|
|
466
|
+
}
|
|
467
|
+
while ((match = mdRegexHttp.exec(text)) !== null || (match = mdRegexHttps.exec(text)) !== null) {
|
|
468
|
+
imageLinks.push(match[1]);
|
|
469
|
+
}
|
|
470
|
+
return imageLinks.map(item => ({ type: 2, url: item }));
|
|
471
|
+
}
|
|
472
|
+
export function convertMdToText(mdContent) {
|
|
473
|
+
// 使用 marked 库将 md 格式的内容转换成文本格式
|
|
474
|
+
const textContent = marked(mdContent, { gfm: true });
|
|
475
|
+
return textContent;
|
|
476
|
+
}
|
|
477
|
+
;
|
|
448
478
|
export { Base64Encode };
|
|
449
479
|
export { Base64Decode };
|
|
450
480
|
export { setLocalSchedule };
|
|
@@ -10,6 +10,24 @@ export function getWordCloudConfig(roomName: any): Promise<any>;
|
|
|
10
10
|
* 获取词云图片
|
|
11
11
|
*/
|
|
12
12
|
export function getWordCloud(wordcontent: any, background: any, border: any): Promise<string | undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* 获取自定义内容
|
|
15
|
+
* @param id
|
|
16
|
+
* @returns {Promise<[{type: number, content: string}]|*[]>}
|
|
17
|
+
*/
|
|
18
|
+
export function getCustomNews(id: any): Promise<[{
|
|
19
|
+
type: number;
|
|
20
|
+
content: string;
|
|
21
|
+
}] | any[]>;
|
|
22
|
+
/**
|
|
23
|
+
* 获取自定义技能
|
|
24
|
+
* @param params
|
|
25
|
+
* @returns {Promise<[{type: number, content: string}]|*[]>}
|
|
26
|
+
*/
|
|
27
|
+
export function getCustomEvents(params: any): Promise<[{
|
|
28
|
+
type: number;
|
|
29
|
+
content: string;
|
|
30
|
+
}] | any[]>;
|
|
13
31
|
/**
|
|
14
32
|
* 获取gpt配置
|
|
15
33
|
* @return {Promise<*>}
|
|
@@ -129,13 +129,57 @@ async function getFireNews(id, num) {
|
|
|
129
129
|
1001: '您可以 @消防小助手+新闻标题,通过ChatGPT为您分析时事新闻!',
|
|
130
130
|
1002: '您可以 @消防小助手+新闻标题,通过ChatGPT为您分析今日消防行业招标信息!',
|
|
131
131
|
};
|
|
132
|
-
return `${news}…………………………${eol}${eol}${endMap[id]}`;
|
|
132
|
+
return `${news}…………………………${eol}${eol}${endMap[id] || ''}`;
|
|
133
133
|
}
|
|
134
134
|
catch (e) {
|
|
135
135
|
console.log('获取每日一句失败', e);
|
|
136
136
|
return '今日一句似乎已经消失';
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* 获取自定义内容
|
|
141
|
+
* @param id
|
|
142
|
+
* @returns {Promise<[{type: number, content: string}]|*[]>}
|
|
143
|
+
*/
|
|
144
|
+
export async function getCustomNews(id) {
|
|
145
|
+
try {
|
|
146
|
+
let option = {
|
|
147
|
+
method: 'GET',
|
|
148
|
+
url: '/customnews',
|
|
149
|
+
params: {
|
|
150
|
+
id
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
let content = await aiBotReq(option);
|
|
154
|
+
let newContent = content.data || [];
|
|
155
|
+
return newContent;
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
console.log('定制内容获取失败', e);
|
|
159
|
+
return [{ type: 1, content: '定制内容获取失败' }];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 获取自定义技能
|
|
164
|
+
* @param params
|
|
165
|
+
* @returns {Promise<[{type: number, content: string}]|*[]>}
|
|
166
|
+
*/
|
|
167
|
+
export async function getCustomEvents(params) {
|
|
168
|
+
try {
|
|
169
|
+
let option = {
|
|
170
|
+
method: 'POST',
|
|
171
|
+
url: '/customevent',
|
|
172
|
+
params,
|
|
173
|
+
};
|
|
174
|
+
let content = await aiBotReq(option);
|
|
175
|
+
let newContent = content.data || [];
|
|
176
|
+
return newContent;
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
console.log('自定义技能获取失败', e);
|
|
180
|
+
return [{ type: 1, content: '自定义技能获取失败' }];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
139
183
|
/**
|
|
140
184
|
* 获取配置文件
|
|
141
185
|
* @returns {Promise<*>}
|
|
@@ -10,6 +10,7 @@ import { reset as webReset } from './bot/chatgpt-web.js';
|
|
|
10
10
|
import { reset as difyReset } from './bot/dify.js';
|
|
11
11
|
import { initRssTask, sendRssTaskMessage } from "../task/rss.js";
|
|
12
12
|
import globalConfig from "../db/global.js";
|
|
13
|
+
import { resetScanTime } from '../handlers/on-scan.js';
|
|
13
14
|
let mqttclient = null;
|
|
14
15
|
async function sendRoomSay(that, room, messages) {
|
|
15
16
|
console.log(`收到群:${room.name}批量发送消息请求, 消息数量【${messages.length}】`);
|
|
@@ -162,6 +163,10 @@ async function initMqtt(that) {
|
|
|
162
163
|
console.log('强制更新二维码');
|
|
163
164
|
await this.refreshQrCode();
|
|
164
165
|
}
|
|
166
|
+
else if (content.target === 'getNewQrCode') {
|
|
167
|
+
console.log('获取最新二维码');
|
|
168
|
+
resetScanTime();
|
|
169
|
+
}
|
|
165
170
|
else if (content.target === 'verifyCode') {
|
|
166
171
|
console.log('触发了输入验证码事件');
|
|
167
172
|
if (globalConfig.getVerifyId() === globalConfig.getQrKey()) {
|
|
@@ -12,7 +12,7 @@ export default _default;
|
|
|
12
12
|
* @param avatar
|
|
13
13
|
* @returns {string} 内容
|
|
14
14
|
*/
|
|
15
|
-
export function dispatchEventContent(that: any, eName: string, msg: string, name: any, id: any, avatar: any, room: any): string;
|
|
15
|
+
export function dispatchEventContent(that: any, eName: string, msg: string, name: any, id: any, avatar: any, room: any, roomName: any, sourceMsg: any): string;
|
|
16
16
|
/**
|
|
17
17
|
* 派发不同的机器人处理回复内容
|
|
18
18
|
* @param {*} bot 机器人类别 0 天行机器人 1 天行的图灵机器人 2 图灵机器人 3 腾讯闲聊机器人
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import api from '../proxy/api.js';
|
|
2
|
-
import { getConfig, getMeiNv, getWordCloudConfig } from '../proxy/aibotk.js';
|
|
2
|
+
import { getConfig, getMeiNv, getWordCloudConfig, getCustomEvents } from '../proxy/aibotk.js';
|
|
3
3
|
import { getConstellation, msgArr, getNewsType } from '../lib/index.js';
|
|
4
|
-
import { initTaskLocalSchedule, initTimeSchedule } from "../task/index.js";
|
|
4
|
+
import { initTaskLocalSchedule, initTimeSchedule, initMultiTask } from "../task/index.js";
|
|
5
5
|
import { updateContactAndRoom, updateContactOnly, updateRoomOnly } from '../common/index.js';
|
|
6
6
|
import { getTencentOpenReply } from '../proxy/tencent-open.js';
|
|
7
7
|
import { removeRecord } from "../db/roomDb.js";
|
|
@@ -17,9 +17,13 @@ import { getDifyReply, reset as difyReset } from "../proxy/difyAi.js";
|
|
|
17
17
|
* @param avatar
|
|
18
18
|
* @returns {string} 内容
|
|
19
19
|
*/
|
|
20
|
-
async function dispatchEventContent(that, eName, msg, name, id, avatar, room) {
|
|
20
|
+
async function dispatchEventContent(that, eName, msg, name, id, avatar, room, roomName, sourceMsg) {
|
|
21
21
|
try {
|
|
22
22
|
let content = '', type = 1, url = '';
|
|
23
|
+
if (eName.includes('event-')) {
|
|
24
|
+
const res = await getCustomEvents({ msg: msg || '', sourceMsg: sourceMsg || '', wxid: id, name, eventId: eName, roomName: roomName || '' });
|
|
25
|
+
return res;
|
|
26
|
+
}
|
|
23
27
|
switch (eName) {
|
|
24
28
|
case 'rubbish':
|
|
25
29
|
content = await api.getRubbishType(msg);
|
|
@@ -106,6 +110,7 @@ async function dispatchEventContent(that, eName, msg, name, id, avatar, room) {
|
|
|
106
110
|
await getConfig();
|
|
107
111
|
await initTaskLocalSchedule(that);
|
|
108
112
|
await initTimeSchedule(that);
|
|
113
|
+
await initMultiTask(that);
|
|
109
114
|
reset();
|
|
110
115
|
officialReset();
|
|
111
116
|
difyReset();
|
|
@@ -45,11 +45,11 @@ export function callbackEvent({ that, msg, name, id, config, room, isMention }:
|
|
|
45
45
|
export function emptyMsg({ room, isMention }: {
|
|
46
46
|
room: any;
|
|
47
47
|
isMention: any;
|
|
48
|
-
}): {
|
|
48
|
+
}): Promise<{
|
|
49
49
|
type: number;
|
|
50
|
-
content:
|
|
50
|
+
content: any;
|
|
51
51
|
url: string;
|
|
52
|
-
}[]
|
|
52
|
+
}[]>;
|
|
53
53
|
export function officialMsg(): {
|
|
54
54
|
type: number;
|
|
55
55
|
content: string;
|
|
@@ -74,7 +74,7 @@ export function scheduleJobMsg({ that, msg, name }: {
|
|
|
74
74
|
msg: any;
|
|
75
75
|
name: any;
|
|
76
76
|
}): Promise<any>;
|
|
77
|
-
export function eventMsg({ that, msg, name, id, avatar, config, room, isMention }: {
|
|
77
|
+
export function eventMsg({ that, msg, name, id, avatar, config, room, isMention, roomName }: {
|
|
78
78
|
that: any;
|
|
79
79
|
msg: any;
|
|
80
80
|
name: any;
|
|
@@ -83,6 +83,7 @@ export function eventMsg({ that, msg, name, id, avatar, config, room, isMention
|
|
|
83
83
|
config: any;
|
|
84
84
|
room: any;
|
|
85
85
|
isMention: any;
|
|
86
|
+
roomName: any;
|
|
86
87
|
}): Promise<string | never[]>;
|
|
87
88
|
/**
|
|
88
89
|
* 关键词回复
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import dispatch from "./event-dispatch-service.js";
|
|
2
|
-
import { setSchedule, updateSchedule } from
|
|
2
|
+
import { getConfig, setSchedule, updateSchedule } from '../proxy/aibotk.js';
|
|
3
3
|
import { contentDistinguish, setLocalSchedule, isRealDate } from "../lib/index.js";
|
|
4
4
|
import { addRoom } from "../common/index.js";
|
|
5
5
|
import { service, callbackAibotApi } from "../proxy/superagent.js";
|
|
6
6
|
import { dispatchBot } from "../proxy/bot/dispatch.js";
|
|
7
7
|
import globalConfig from "../db/global.js";
|
|
8
8
|
import { getUser } from "../db/userDb.js";
|
|
9
|
-
|
|
9
|
+
import { allConfig } from '../db/configDb.js';
|
|
10
|
+
async function emptyMsg({ room, isMention }) {
|
|
11
|
+
const config = await allConfig();
|
|
10
12
|
if (room && !isMention)
|
|
11
13
|
return [];
|
|
12
14
|
let msgArr = []; // 返回的消息列表
|
|
13
|
-
let obj = { type: 1, content:
|
|
15
|
+
let obj = { type: 1, content: config.defaultReply, url: "" }; // 消息主体
|
|
14
16
|
msgArr.push(obj);
|
|
15
17
|
return msgArr;
|
|
16
18
|
}
|
|
@@ -124,9 +126,9 @@ async function scheduleJobMsg({ that, msg, name }) {
|
|
|
124
126
|
* @param avatar 用户头像
|
|
125
127
|
* @returns {String}
|
|
126
128
|
*/
|
|
127
|
-
async function getEventReply(that, event, msg, name, id, avatar, room) {
|
|
129
|
+
async function getEventReply(that, event, msg, name, id, avatar, room, roomName, sourceMsg) {
|
|
128
130
|
try {
|
|
129
|
-
let reply = await dispatch.dispatchEventContent(that, event, msg, name, id, avatar, room);
|
|
131
|
+
let reply = await dispatch.dispatchEventContent(that, event, msg, name, id, avatar, room, roomName, sourceMsg);
|
|
130
132
|
return reply;
|
|
131
133
|
}
|
|
132
134
|
catch (e) {
|
|
@@ -188,7 +190,7 @@ async function callbackEvent({ that, msg, name, id, config, room, isMention }) {
|
|
|
188
190
|
return [];
|
|
189
191
|
}
|
|
190
192
|
}
|
|
191
|
-
async function eventMsg({ that, msg, name, id, avatar, config, room, isMention }) {
|
|
193
|
+
async function eventMsg({ that, msg, name, id, avatar, config, room, isMention, roomName }) {
|
|
192
194
|
try {
|
|
193
195
|
for (let item of config.eventKeywords) {
|
|
194
196
|
for (let key of item.keywords) {
|
|
@@ -197,8 +199,8 @@ async function eventMsg({ that, msg, name, id, avatar, config, room, isMention }
|
|
|
197
199
|
if ((room && item.needAt === 1 && !isMention) || (room && item.needAt === undefined && !isMention) || (room && item.scope === "friend") || (!room && item.scope === "room")) {
|
|
198
200
|
return [];
|
|
199
201
|
}
|
|
200
|
-
|
|
201
|
-
let res = await getEventReply(that, item.event,
|
|
202
|
+
const replaceMsg = msg.replace(key, "");
|
|
203
|
+
let res = await getEventReply(that, item.event, replaceMsg, name, id, avatar, room, roomName, msg);
|
|
202
204
|
return res;
|
|
203
205
|
}
|
|
204
206
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setLocalSchedule, delay, cancelAllSchedule } from "../lib/index.js";
|
|
2
2
|
import { allConfig } from "../db/configDb.js";
|
|
3
3
|
import { getScheduleList, updateSchedule } from "../proxy/aibotk.js";
|
|
4
|
-
import { getNewsContent, getEveryDayContent, roomSay, getRoomEveryDayContent, contactSay, getCountDownContent } from "../common/index.js";
|
|
4
|
+
import { getNewsContent, getEveryDayContent, roomSay, getRoomEveryDayContent, contactSay, getCountDownContent, getCustomContent } from "../common/index.js";
|
|
5
5
|
import globalConfig from "../db/global.js";
|
|
6
6
|
const typeMap = {
|
|
7
7
|
contact: "用户名", room: "群名"
|
|
@@ -140,6 +140,45 @@ const sendNews = async ({ that, target, item, isMulti, targets }) => {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
+
/**
|
|
144
|
+
* 发送自定义定制内容
|
|
145
|
+
* @param that
|
|
146
|
+
* @param target
|
|
147
|
+
* @param type 类型 room contact
|
|
148
|
+
* @param item
|
|
149
|
+
* @param isMulti 是否多个目标
|
|
150
|
+
* @param targets 发送的多个目标
|
|
151
|
+
* @return {Promise<void>}
|
|
152
|
+
*/
|
|
153
|
+
const sendCustomContent = async ({ that, target, type, item, isMulti, targets }) => {
|
|
154
|
+
let contents = await getCustomContent(item.sortId);
|
|
155
|
+
console.log("定制内容发送", contents);
|
|
156
|
+
if (!isMulti) {
|
|
157
|
+
for (const reply of contents) {
|
|
158
|
+
await contactSay(target, reply);
|
|
159
|
+
await delay(200);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
for (let single of targets) {
|
|
164
|
+
try {
|
|
165
|
+
for (const reply of contents) {
|
|
166
|
+
type === 'room' ? await roomSay(single, '', reply) : await contactSay(single, reply);
|
|
167
|
+
await delay(200);
|
|
168
|
+
}
|
|
169
|
+
if (item.delay) {
|
|
170
|
+
await delay(item.delay);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
await delay(800);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
console.log(`定时任务失败,可能群已经解散或者好友不存在: ${e}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
143
182
|
/**
|
|
144
183
|
* 发送每日说
|
|
145
184
|
* @param that
|
|
@@ -370,6 +409,9 @@ async function sendMultiTaskMessage(that, task) {
|
|
|
370
409
|
else if (task.taskType === "countdown") {
|
|
371
410
|
await sendCountDown({ that, isMulti: true, targets, item: task.taskInfo });
|
|
372
411
|
}
|
|
412
|
+
else if (task.taskType === "customContent") {
|
|
413
|
+
await sendCustomContent({ that, isMulti: true, targets, type: task.type, item: task.taskInfo });
|
|
414
|
+
}
|
|
373
415
|
}
|
|
374
416
|
catch (error) {
|
|
375
417
|
console.log("立即发送定时任务失败:", error);
|
|
@@ -404,6 +446,14 @@ async function startSendMultiTask({ that, task }) {
|
|
|
404
446
|
item: task.taskInfo
|
|
405
447
|
});
|
|
406
448
|
}
|
|
449
|
+
else if (task.taskType === "customContent") {
|
|
450
|
+
await sendCustomContent({
|
|
451
|
+
that,
|
|
452
|
+
isMulti: true,
|
|
453
|
+
targets,
|
|
454
|
+
item: task.taskInfo
|
|
455
|
+
});
|
|
456
|
+
}
|
|
407
457
|
}
|
|
408
458
|
async function setMultiTask(that, task) {
|
|
409
459
|
try {
|
|
@@ -425,6 +475,12 @@ async function setMultiTask(that, task) {
|
|
|
425
475
|
task
|
|
426
476
|
}), `schedule_countdown_${task.id}`);
|
|
427
477
|
}
|
|
478
|
+
else if (task.taskType === "customContent") {
|
|
479
|
+
setLocalSchedule(task.cron, startSendMultiTask.bind(null, {
|
|
480
|
+
that,
|
|
481
|
+
task
|
|
482
|
+
}), `schedule_customcontent_${task.id}`);
|
|
483
|
+
}
|
|
428
484
|
}
|
|
429
485
|
catch (e) {
|
|
430
486
|
console.log("catch error:" + e);
|