wechaty-web-panel 1.6.27 → 1.6.29
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 +6 -0
- package/dist/cjs/src/db/global.js +7 -0
- package/dist/cjs/src/handlers/on-message.js +1 -1
- package/dist/cjs/src/handlers/on-ready.js +1 -0
- package/dist/cjs/src/package-json.js +1 -1
- package/dist/cjs/src/proxy/aibotk.d.ts +5 -0
- package/dist/cjs/src/proxy/aibotk.js +24 -1
- package/dist/cjs/src/proxy/mqtt.js +9 -0
- package/dist/cjs/src/task/index.d.ts +11 -0
- package/dist/cjs/src/task/index.js +202 -22
- package/dist/esm/src/db/global.js +7 -0
- package/dist/esm/src/handlers/on-message.js +1 -1
- package/dist/esm/src/handlers/on-ready.js +2 -1
- package/dist/esm/src/package-json.js +1 -1
- package/dist/esm/src/proxy/aibotk.d.ts +5 -0
- package/dist/esm/src/proxy/aibotk.js +22 -0
- package/dist/esm/src/proxy/mqtt.js +11 -2
- package/dist/esm/src/task/index.d.ts +11 -0
- package/dist/esm/src/task/index.js +198 -21
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,13 @@ class Config {
|
|
|
12
12
|
this.verifyCode = ''; // 企微验证码
|
|
13
13
|
this.verifyId = ''; // 企微验证码id
|
|
14
14
|
this.gptconfig = [];
|
|
15
|
+
this.allTasks = [];
|
|
16
|
+
}
|
|
17
|
+
getAllTasks() {
|
|
18
|
+
return this.allTasks;
|
|
19
|
+
}
|
|
20
|
+
updateAllTasks(list) {
|
|
21
|
+
this.allTasks = list;
|
|
15
22
|
}
|
|
16
23
|
getVerifyId() {
|
|
17
24
|
return this.verifyId;
|
|
@@ -120,7 +120,7 @@ async function dispatchFriendFilterByMsgType(that, msg) {
|
|
|
120
120
|
async function dispatchRoomFilterByMsgType(that, room, msg) {
|
|
121
121
|
const aibotConfig = await (0, aiDb_js_1.getAibotConfig)();
|
|
122
122
|
const config = await (0, configDb_js_1.allConfig)();
|
|
123
|
-
const { role } = config.userInfo;
|
|
123
|
+
const { role } = config && config.userInfo || { role: 'default' };
|
|
124
124
|
try {
|
|
125
125
|
const eol = await (0, puppet_type_js_1.getPuppetEol)();
|
|
126
126
|
const contact = msg.talker(); // 发消息人
|
|
@@ -19,6 +19,7 @@ async function onReady() {
|
|
|
19
19
|
await (0, puppetDb_js_1.updatePuppetConfig)({ puppetType: this.puppet.constructor.name });
|
|
20
20
|
await (0, aibotk_js_1.getConfig)(); // 获取配置文件
|
|
21
21
|
(0, index_js_3.initAllSchedule)(this); // 初始化任务
|
|
22
|
+
(0, index_js_3.initMultiTask)(this); // 初始化批量定时任务
|
|
22
23
|
const config = await (0, configDb_js_1.allConfig)();
|
|
23
24
|
const { role } = config.userInfo;
|
|
24
25
|
if (role === 'vip') {
|
|
@@ -15,6 +15,11 @@ export function getWordCloud(wordcontent: any, background: any, border: any): Pr
|
|
|
15
15
|
* @return {Promise<*>}
|
|
16
16
|
*/
|
|
17
17
|
export function getGptConfig(): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* 获取批量任务
|
|
20
|
+
* @return {Promise<*>}
|
|
21
|
+
*/
|
|
22
|
+
export function getTasks(): Promise<any>;
|
|
18
23
|
/**
|
|
19
24
|
* 获取rss配置
|
|
20
25
|
* @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.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.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");
|
|
@@ -165,6 +165,7 @@ async function getConfig() {
|
|
|
165
165
|
if (config.userInfo.role === 'vip') {
|
|
166
166
|
await getGptConfig();
|
|
167
167
|
await getRssConfig();
|
|
168
|
+
await getTasks();
|
|
168
169
|
cloudRoom = await getWordCloudRoom();
|
|
169
170
|
}
|
|
170
171
|
let cres = await (0, configDb_js_1.updateConfig)({
|
|
@@ -226,6 +227,28 @@ async function getGptConfig() {
|
|
|
226
227
|
}
|
|
227
228
|
}
|
|
228
229
|
exports.getGptConfig = getGptConfig;
|
|
230
|
+
/**
|
|
231
|
+
* 获取批量任务
|
|
232
|
+
* @return {Promise<*>}
|
|
233
|
+
*/
|
|
234
|
+
async function getTasks() {
|
|
235
|
+
try {
|
|
236
|
+
let option = {
|
|
237
|
+
method: 'GET',
|
|
238
|
+
url: '/user/task',
|
|
239
|
+
params: {},
|
|
240
|
+
};
|
|
241
|
+
let content = await (0, superagent_js_1.aiBotReq)(option);
|
|
242
|
+
if (content.data) {
|
|
243
|
+
const list = content.data.map(item => ({ ...item, _id: item.id }));
|
|
244
|
+
global_js_1.default.updateAllTasks(list);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
console.log('获取批量任务失败:' + error);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.getTasks = getTasks;
|
|
229
252
|
/**
|
|
230
253
|
* 获取rss配置
|
|
231
254
|
* @return {Promise<*>}
|
|
@@ -183,6 +183,10 @@ async function initMqtt(that) {
|
|
|
183
183
|
console.log('触发了rss立即更新事件');
|
|
184
184
|
await (0, rss_js_1.sendRssTaskMessage)(that, content);
|
|
185
185
|
}
|
|
186
|
+
else if (content.target === 'Tasks') {
|
|
187
|
+
console.log('触发了批量任务立即发送');
|
|
188
|
+
await (0, index_js_2.sendMultiTaskMessage)(that, content.task);
|
|
189
|
+
}
|
|
186
190
|
else if (content.target === 'refreshCode') {
|
|
187
191
|
console.log('强制更新二维码');
|
|
188
192
|
await this.refreshQrCode();
|
|
@@ -223,6 +227,11 @@ async function initMqtt(that) {
|
|
|
223
227
|
await (0, aibotk_js_1.getRssConfig)();
|
|
224
228
|
void (0, rss_js_1.initRssTask)(that);
|
|
225
229
|
}
|
|
230
|
+
else if (topic === `aibotk/${userId}/tasks`) {
|
|
231
|
+
console.log('更新批量定时任务');
|
|
232
|
+
await (0, aibotk_js_1.getTasks)();
|
|
233
|
+
void (0, index_js_2.initMultiTask)(that);
|
|
234
|
+
}
|
|
226
235
|
});
|
|
227
236
|
}
|
|
228
237
|
}
|
|
@@ -17,6 +17,11 @@ export function initTaskLocalSchedule(that: any): Promise<void>;
|
|
|
17
17
|
* @param {*} RoomSayList 群资讯任务列表
|
|
18
18
|
*/
|
|
19
19
|
export function initAllSchedule(that: any): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* 初始化批量定时任务
|
|
22
|
+
* @param that
|
|
23
|
+
*/
|
|
24
|
+
export function initMultiTask(that: any): void;
|
|
20
25
|
/**
|
|
21
26
|
* 初始化提醒任务
|
|
22
27
|
* @param {}} that
|
|
@@ -28,4 +33,10 @@ export function initTimeSchedule(that: any): Promise<void>;
|
|
|
28
33
|
* @param {*} item 任务项 { target: 'Room', event: '', message: { roomName: '', type: 'news 新闻 ||task 定时任务', contents: [] } }
|
|
29
34
|
*/
|
|
30
35
|
export function sendTaskMessage(that: any, info: any): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* 立即发送批量任务消息
|
|
38
|
+
* @param {*} that bot对象
|
|
39
|
+
* @param {*} item 任务项 { target: 'Room', event: '', message: { roomName: '', type: 'news 新闻 ||task 定时任务', contents: [] } }
|
|
40
|
+
*/
|
|
41
|
+
export function sendMultiTaskMessage(that: any, task: any): Promise<void>;
|
|
31
42
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,13 +1,16 @@
|
|
|
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
|
-
exports.sendTaskMessage = exports.initTimeSchedule = exports.initAllSchedule = exports.initTaskLocalSchedule = void 0;
|
|
6
|
+
exports.sendMultiTaskMessage = exports.sendTaskMessage = exports.initTimeSchedule = exports.initMultiTask = exports.initAllSchedule = exports.initTaskLocalSchedule = void 0;
|
|
4
7
|
const index_js_1 = require("../lib/index.js");
|
|
5
8
|
const configDb_js_1 = require("../db/configDb.js");
|
|
6
9
|
const aibotk_js_1 = require("../proxy/aibotk.js");
|
|
7
10
|
const index_js_2 = require("../common/index.js");
|
|
11
|
+
const global_js_1 = __importDefault(require("../db/global.js"));
|
|
8
12
|
const typeMap = {
|
|
9
|
-
contact: "用户名",
|
|
10
|
-
room: "群名"
|
|
13
|
+
contact: "用户名", room: "群名"
|
|
11
14
|
};
|
|
12
15
|
/**
|
|
13
16
|
* 查找发送的目标
|
|
@@ -16,7 +19,7 @@ const typeMap = {
|
|
|
16
19
|
* alias: 别名
|
|
17
20
|
* wxid: wxid
|
|
18
21
|
*/
|
|
19
|
-
async function findTarget({ that, type, name, alias, wxid =
|
|
22
|
+
async function findTarget({ that, type, name, alias, wxid = "" }) {
|
|
20
23
|
let target = null;
|
|
21
24
|
if (type === "contact") {
|
|
22
25
|
target = wxid && that.Contact.find({ id: wxid }) || name && (await that.Contact.find({ name: name })) || alias && (await that.Contact.find({ alias: alias })); // 获取你要发送的联系人
|
|
@@ -38,7 +41,9 @@ async function setTask(that, item, name, callback) {
|
|
|
38
41
|
try {
|
|
39
42
|
let time = item.date;
|
|
40
43
|
item.type = item.type ? item.type : "contact";
|
|
41
|
-
const target = await findTarget({
|
|
44
|
+
const target = await findTarget({
|
|
45
|
+
that, type: item.type, name: item.roomName || item.name, alias: item.alias || "", wxid: item.wxid || ""
|
|
46
|
+
});
|
|
42
47
|
if (!target) {
|
|
43
48
|
console.log(`查找不到${typeMap[item.type]}:${item.roomName || item.name}`);
|
|
44
49
|
}
|
|
@@ -56,17 +61,45 @@ async function setTask(that, item, name, callback) {
|
|
|
56
61
|
* @param that
|
|
57
62
|
* @param target
|
|
58
63
|
* @param item
|
|
64
|
+
* @param isMulti 是否多个目标
|
|
65
|
+
* @param targets 发送的多个目标
|
|
59
66
|
* @return {Promise<void>}
|
|
60
67
|
*/
|
|
61
|
-
const sendCustom = async ({ that, target, item }) => {
|
|
68
|
+
const sendCustom = async ({ that, target, item, isMulti, targets }) => {
|
|
62
69
|
for (let reply of item.contents) {
|
|
63
70
|
console.log("定时任务开始发送,内容:", `${reply.type === 1 ? reply.content : reply.url}`);
|
|
64
71
|
await (0, index_js_1.delay)(1000);
|
|
65
72
|
if (item.type === "room") {
|
|
66
|
-
|
|
73
|
+
if (!isMulti) {
|
|
74
|
+
await index_js_2.roomSay.call(that, target, "", reply);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
for (let single of targets) {
|
|
78
|
+
await index_js_2.roomSay.call(that, single, "", reply);
|
|
79
|
+
if (item.delay) {
|
|
80
|
+
await (0, index_js_1.delay)(item.delay);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
await (0, index_js_1.delay)(1000);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
67
87
|
}
|
|
68
88
|
else {
|
|
69
|
-
|
|
89
|
+
if (!isMulti) {
|
|
90
|
+
await index_js_2.contactSay.call(that, target, reply);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
for (let single of targets) {
|
|
94
|
+
await index_js_2.contactSay.call(that, single, reply);
|
|
95
|
+
if (item.delay) {
|
|
96
|
+
await (0, index_js_1.delay)(item.delay);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
await (0, index_js_1.delay)(1000);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
70
103
|
}
|
|
71
104
|
}
|
|
72
105
|
};
|
|
@@ -75,13 +108,28 @@ const sendCustom = async ({ that, target, item }) => {
|
|
|
75
108
|
* @param that
|
|
76
109
|
* @param target
|
|
77
110
|
* @param item
|
|
111
|
+
* @param isMulti 是否多个目标
|
|
112
|
+
* @param targets 发送的多个目标
|
|
78
113
|
* @return {Promise<void>}
|
|
79
114
|
*/
|
|
80
|
-
const sendNews = async ({ that, target, item }) => {
|
|
115
|
+
const sendNews = async ({ that, target, item, isMulti, targets }) => {
|
|
81
116
|
let content = await (0, index_js_2.getNewsContent)(item.sortId, item.endWord, item.num || 10);
|
|
82
117
|
console.log("新闻资讯开始发送,内容:", content);
|
|
83
|
-
await (0, index_js_1.delay)(
|
|
84
|
-
|
|
118
|
+
await (0, index_js_1.delay)(200);
|
|
119
|
+
if (!isMulti) {
|
|
120
|
+
await target.say(content);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
for (let single of targets) {
|
|
124
|
+
await single.say(content);
|
|
125
|
+
if (item.delay) {
|
|
126
|
+
await (0, index_js_1.delay)(item.delay);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
await (0, index_js_1.delay)(1000);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
85
133
|
};
|
|
86
134
|
/**
|
|
87
135
|
* 发送每日说
|
|
@@ -99,7 +147,7 @@ const sendEveryDay = async ({ that, target, item }) => {
|
|
|
99
147
|
content = await (0, index_js_2.getEveryDayContent)(item.memorialDay, item.city, item.endWord);
|
|
100
148
|
}
|
|
101
149
|
console.log("每日说任务开始工作,发送内容:", content);
|
|
102
|
-
await (0, index_js_1.delay)(
|
|
150
|
+
await (0, index_js_1.delay)(1000);
|
|
103
151
|
await target.say(content);
|
|
104
152
|
};
|
|
105
153
|
/**
|
|
@@ -107,13 +155,28 @@ const sendEveryDay = async ({ that, target, item }) => {
|
|
|
107
155
|
* @param that
|
|
108
156
|
* @param target
|
|
109
157
|
* @param item
|
|
158
|
+
* @param isMulti 是否多个目标
|
|
159
|
+
* @param targets 发送的多个目标
|
|
110
160
|
* @return {Promise<void>}
|
|
111
161
|
*/
|
|
112
|
-
const sendCountDown = async ({ that, target, item }) => {
|
|
162
|
+
const sendCountDown = async ({ that, target, item, isMulti, targets }) => {
|
|
113
163
|
let content = await (0, index_js_2.getCountDownContent)(item.memorialDay, item.prefix, item.suffix, item.endWord);
|
|
114
164
|
console.log("倒计时任务开始工作,发送内容:", content);
|
|
115
|
-
await (0, index_js_1.delay)(
|
|
116
|
-
|
|
165
|
+
await (0, index_js_1.delay)(1000);
|
|
166
|
+
if (!isMulti) {
|
|
167
|
+
await target.say(content);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
for (let single of targets) {
|
|
171
|
+
await single.say(content);
|
|
172
|
+
if (item.delay) {
|
|
173
|
+
await (0, index_js_1.delay)(item.delay);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
await (0, index_js_1.delay)(1000);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
117
180
|
};
|
|
118
181
|
/**
|
|
119
182
|
* 立即发送群消息
|
|
@@ -124,7 +187,9 @@ async function sendTaskMessage(that, info) {
|
|
|
124
187
|
try {
|
|
125
188
|
const item = info.message;
|
|
126
189
|
item.type = item.type ? item.type : "room";
|
|
127
|
-
const target = await findTarget({
|
|
190
|
+
const target = await findTarget({
|
|
191
|
+
that, type: item.type, name: item.roomName || item.name, alias: item.alias || "", wxid: item.wxid || ""
|
|
192
|
+
});
|
|
128
193
|
if (!target) {
|
|
129
194
|
console.log(`查找不到${typeMap[item.type]}:${item.roomName || item.name}`);
|
|
130
195
|
}
|
|
@@ -210,19 +275,19 @@ async function initTaskLocalSchedule(that) {
|
|
|
210
275
|
// 每日说定时任务
|
|
211
276
|
if (dayTaskSchedule && dayTaskSchedule.length > 0) {
|
|
212
277
|
dayTaskSchedule.forEach((item, index) => {
|
|
213
|
-
setTask(that, { type:
|
|
278
|
+
setTask(that, { type: "contact", ...item }, `task_day_${index}`, sendEveryDay);
|
|
214
279
|
});
|
|
215
280
|
}
|
|
216
281
|
// 新闻资讯定时任务
|
|
217
282
|
if (roomNewsSchedule && roomNewsSchedule.length > 0) {
|
|
218
283
|
roomNewsSchedule.forEach((item, index) => {
|
|
219
|
-
setTask(that, { type:
|
|
284
|
+
setTask(that, { type: "room", ...item }, `task_news_${index}`, sendNews);
|
|
220
285
|
});
|
|
221
286
|
}
|
|
222
287
|
// 自定义内容定时任务
|
|
223
288
|
if (roomTaskSchedule && roomTaskSchedule.length > 0) {
|
|
224
289
|
roomTaskSchedule.forEach((item, index) => {
|
|
225
|
-
setTask(that, { type:
|
|
290
|
+
setTask(that, { type: "room", ...item }, `task_custom_${index}`, sendCustom);
|
|
226
291
|
});
|
|
227
292
|
}
|
|
228
293
|
// 倒计时定时任务
|
|
@@ -237,6 +302,123 @@ async function initTaskLocalSchedule(that) {
|
|
|
237
302
|
}
|
|
238
303
|
}
|
|
239
304
|
exports.initTaskLocalSchedule = initTaskLocalSchedule;
|
|
305
|
+
async function getMultiTargets(that, type, task) {
|
|
306
|
+
const targets = [];
|
|
307
|
+
if (task.isAll) {
|
|
308
|
+
const allTargets = type === "room" ? await that.Room.findAll() : await that.Contact.findAll();
|
|
309
|
+
if (task.excludeTargets) {
|
|
310
|
+
allTargets.forEach(target => {
|
|
311
|
+
const find = type === "room" ? task.excludeTargets.find(eItem => target.id === eItem.id || target.topic() === eItem.name) : task.excludeTargets.find(eItem => target.id === eItem.id || target.name() === eItem.name);
|
|
312
|
+
if (type === "room") {
|
|
313
|
+
if (!find) {
|
|
314
|
+
targets.push(target);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
if (!find && target.friend()) {
|
|
319
|
+
targets.push(target);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
for (let target of task.targets) {
|
|
327
|
+
const finalTarget = type === "room" ? await that.Room.find({
|
|
328
|
+
id: target.id, topic: target.name
|
|
329
|
+
}) : await that.Contact.find({ id: target.id, name: target.name });
|
|
330
|
+
if (finalTarget) {
|
|
331
|
+
targets.push(finalTarget);
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
console.log(`定时任务查找不到${type === "room" ? "群" : "好友"}:${target.name},请检查${type === "room" ? "群名" : "好友昵称"}是否正确`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return targets;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* 立即发送批量任务消息
|
|
342
|
+
* @param {*} that bot对象
|
|
343
|
+
* @param {*} item 任务项 { target: 'Room', event: '', message: { roomName: '', type: 'news 新闻 ||task 定时任务', contents: [] } }
|
|
344
|
+
*/
|
|
345
|
+
async function sendMultiTaskMessage(that, task) {
|
|
346
|
+
try {
|
|
347
|
+
const targets = await getMultiTargets(that, task.type, task);
|
|
348
|
+
if (!targets.length) {
|
|
349
|
+
console.log("查找不到要发送的目标,请检查后重试");
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (task.taskType === 'news') {
|
|
353
|
+
await sendNews({ that, isMulti: true, targets, item: task.taskInfo });
|
|
354
|
+
}
|
|
355
|
+
else if (task.taskType === 'custom') {
|
|
356
|
+
await sendCustom({ that, isMulti: true, targets, item: { ...task.taskInfo, type: task.type } });
|
|
357
|
+
}
|
|
358
|
+
else if (task.taskType === "countdown") {
|
|
359
|
+
await sendCountDown({ that, isMulti: true, targets, item: task.taskInfo });
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
console.log("立即发送定时任务失败:", error);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
exports.sendMultiTaskMessage = sendMultiTaskMessage;
|
|
367
|
+
async function setMultiTask(that, task) {
|
|
368
|
+
try {
|
|
369
|
+
// 获取要发送的目标
|
|
370
|
+
const targets = await getMultiTargets(that, task.type, task);
|
|
371
|
+
if (!targets.length) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
if (task.taskType === "news") {
|
|
375
|
+
(0, index_js_1.setLocalSchedule)(task.cron, sendNews.bind(null, {
|
|
376
|
+
that,
|
|
377
|
+
isMulti: true,
|
|
378
|
+
targets,
|
|
379
|
+
item: task.taskInfo
|
|
380
|
+
}), `schedule_news_${task.id}`);
|
|
381
|
+
}
|
|
382
|
+
else if (task.taskType === "custom") {
|
|
383
|
+
(0, index_js_1.setLocalSchedule)(task.cron, sendCustom.bind(null, {
|
|
384
|
+
that,
|
|
385
|
+
isMulti: true,
|
|
386
|
+
targets,
|
|
387
|
+
item: { ...task.taskInfo, type: task.type }
|
|
388
|
+
}), `schedule_custom_${task.id}`);
|
|
389
|
+
}
|
|
390
|
+
else if (task.taskType === "countDown") {
|
|
391
|
+
(0, index_js_1.setLocalSchedule)(task.cron, sendCountDown.bind(null, {
|
|
392
|
+
that,
|
|
393
|
+
isMulti: true,
|
|
394
|
+
targets,
|
|
395
|
+
item: task.taskInfo
|
|
396
|
+
}), `schedule_countdown_${task.id}`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
catch (e) {
|
|
400
|
+
console.log("catch error:" + e);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* 初始化批量定时任务
|
|
405
|
+
* @param that
|
|
406
|
+
*/
|
|
407
|
+
function initMultiTask(that) {
|
|
408
|
+
try {
|
|
409
|
+
(0, index_js_1.cancelAllSchedule)("schedule");
|
|
410
|
+
const tasks = global_js_1.default.getAllTasks(); // 获取所有任务
|
|
411
|
+
if (tasks && tasks.length) {
|
|
412
|
+
tasks.forEach((item, index) => {
|
|
413
|
+
void setMultiTask(that, item);
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
catch (e) {
|
|
418
|
+
console.log("initMultiTask error:" + e);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
exports.initMultiTask = initMultiTask;
|
|
240
422
|
/**
|
|
241
423
|
* 初始化小助手任务
|
|
242
424
|
* @param {*} that bot对象
|
|
@@ -250,8 +432,6 @@ async function initAllSchedule(that) {
|
|
|
250
432
|
}
|
|
251
433
|
exports.initAllSchedule = initAllSchedule;
|
|
252
434
|
exports.default = {
|
|
253
|
-
initTaskLocalSchedule,
|
|
254
|
-
initAllSchedule,
|
|
255
|
-
initTimeSchedule,
|
|
435
|
+
initTaskLocalSchedule, initAllSchedule, initTimeSchedule
|
|
256
436
|
};
|
|
257
437
|
//# sourceMappingURL=index.js.map
|
|
@@ -7,6 +7,13 @@ class Config {
|
|
|
7
7
|
this.verifyCode = ''; // 企微验证码
|
|
8
8
|
this.verifyId = ''; // 企微验证码id
|
|
9
9
|
this.gptconfig = [];
|
|
10
|
+
this.allTasks = [];
|
|
11
|
+
}
|
|
12
|
+
getAllTasks() {
|
|
13
|
+
return this.allTasks;
|
|
14
|
+
}
|
|
15
|
+
updateAllTasks(list) {
|
|
16
|
+
this.allTasks = list;
|
|
10
17
|
}
|
|
11
18
|
getVerifyId() {
|
|
12
19
|
return this.verifyId;
|
|
@@ -118,7 +118,7 @@ async function dispatchFriendFilterByMsgType(that, msg) {
|
|
|
118
118
|
async function dispatchRoomFilterByMsgType(that, room, msg) {
|
|
119
119
|
const aibotConfig = await getAibotConfig();
|
|
120
120
|
const config = await allConfig();
|
|
121
|
-
const { role } = config.userInfo;
|
|
121
|
+
const { role } = config && config.userInfo || { role: 'default' };
|
|
122
122
|
try {
|
|
123
123
|
const eol = await getPuppetEol();
|
|
124
124
|
const contact = msg.talker(); // 发消息人
|
|
@@ -2,7 +2,7 @@ import common from '../common/index.js';
|
|
|
2
2
|
import { delay } from '../lib/index.js';
|
|
3
3
|
import { getConfig, sendHeartBeat } from "../proxy/aibotk.js";
|
|
4
4
|
import { getUser } from '../db/userDb.js';
|
|
5
|
-
import { initAllSchedule } from "../task/index.js";
|
|
5
|
+
import { initAllSchedule, initMultiTask } from "../task/index.js";
|
|
6
6
|
import { updatePuppetConfig } from "../db/puppetDb.js";
|
|
7
7
|
import { initRssTask } from "../task/rss.js";
|
|
8
8
|
import { allConfig } from "../db/configDb.js";
|
|
@@ -14,6 +14,7 @@ async function onReady() {
|
|
|
14
14
|
await updatePuppetConfig({ puppetType: this.puppet.constructor.name });
|
|
15
15
|
await getConfig(); // 获取配置文件
|
|
16
16
|
initAllSchedule(this); // 初始化任务
|
|
17
|
+
initMultiTask(this); // 初始化批量定时任务
|
|
17
18
|
const config = await allConfig();
|
|
18
19
|
const { role } = config.userInfo;
|
|
19
20
|
if (role === 'vip') {
|
|
@@ -15,6 +15,11 @@ export function getWordCloud(wordcontent: any, background: any, border: any): Pr
|
|
|
15
15
|
* @return {Promise<*>}
|
|
16
16
|
*/
|
|
17
17
|
export function getGptConfig(): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* 获取批量任务
|
|
20
|
+
* @return {Promise<*>}
|
|
21
|
+
*/
|
|
22
|
+
export function getTasks(): Promise<any>;
|
|
18
23
|
/**
|
|
19
24
|
* 获取rss配置
|
|
20
25
|
* @return {Promise<*>}
|
|
@@ -153,6 +153,7 @@ async function getConfig() {
|
|
|
153
153
|
if (config.userInfo.role === 'vip') {
|
|
154
154
|
await getGptConfig();
|
|
155
155
|
await getRssConfig();
|
|
156
|
+
await getTasks();
|
|
156
157
|
cloudRoom = await getWordCloudRoom();
|
|
157
158
|
}
|
|
158
159
|
let cres = await updateConfig({
|
|
@@ -212,6 +213,27 @@ export async function getGptConfig() {
|
|
|
212
213
|
console.log('获取gpt配置文件失败:' + error);
|
|
213
214
|
}
|
|
214
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* 获取批量任务
|
|
218
|
+
* @return {Promise<*>}
|
|
219
|
+
*/
|
|
220
|
+
export async function getTasks() {
|
|
221
|
+
try {
|
|
222
|
+
let option = {
|
|
223
|
+
method: 'GET',
|
|
224
|
+
url: '/user/task',
|
|
225
|
+
params: {},
|
|
226
|
+
};
|
|
227
|
+
let content = await aiBotReq(option);
|
|
228
|
+
if (content.data) {
|
|
229
|
+
const list = content.data.map(item => ({ ...item, _id: item.id }));
|
|
230
|
+
globalConfig.updateAllTasks(list);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
console.log('获取批量任务失败:' + error);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
215
237
|
/**
|
|
216
238
|
* 获取rss配置
|
|
217
239
|
* @return {Promise<*>}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as mqtt from 'mqtt';
|
|
2
2
|
import { allConfig } from '../db/configDb.js';
|
|
3
3
|
import { contactSay, roomSay, sendRoomNotice } from '../common/index.js';
|
|
4
|
-
import { getConfig, getMqttConfig, getGptConfig, getRssConfig, getVerifyCode } from "./aibotk.js";
|
|
4
|
+
import { getConfig, getMqttConfig, getGptConfig, getRssConfig, getVerifyCode, getTasks } from "./aibotk.js";
|
|
5
5
|
import { dispatchEventContent } from '../service/event-dispatch-service.js';
|
|
6
|
-
import { sendTaskMessage } from "../task/index.js";
|
|
6
|
+
import { sendTaskMessage, initMultiTask, sendMultiTaskMessage } from "../task/index.js";
|
|
7
7
|
import { delay, randomRange } from "../lib/index.js";
|
|
8
8
|
import { reset } from './bot/chatgpt.js';
|
|
9
9
|
import { reset as webReset } from './bot/chatgpt-web.js';
|
|
@@ -154,6 +154,10 @@ async function initMqtt(that) {
|
|
|
154
154
|
console.log('触发了rss立即更新事件');
|
|
155
155
|
await sendRssTaskMessage(that, content);
|
|
156
156
|
}
|
|
157
|
+
else if (content.target === 'Tasks') {
|
|
158
|
+
console.log('触发了批量任务立即发送');
|
|
159
|
+
await sendMultiTaskMessage(that, content.task);
|
|
160
|
+
}
|
|
157
161
|
else if (content.target === 'refreshCode') {
|
|
158
162
|
console.log('强制更新二维码');
|
|
159
163
|
await this.refreshQrCode();
|
|
@@ -194,6 +198,11 @@ async function initMqtt(that) {
|
|
|
194
198
|
await getRssConfig();
|
|
195
199
|
void initRssTask(that);
|
|
196
200
|
}
|
|
201
|
+
else if (topic === `aibotk/${userId}/tasks`) {
|
|
202
|
+
console.log('更新批量定时任务');
|
|
203
|
+
await getTasks();
|
|
204
|
+
void initMultiTask(that);
|
|
205
|
+
}
|
|
197
206
|
});
|
|
198
207
|
}
|
|
199
208
|
}
|
|
@@ -17,6 +17,11 @@ export function initTaskLocalSchedule(that: any): Promise<void>;
|
|
|
17
17
|
* @param {*} RoomSayList 群资讯任务列表
|
|
18
18
|
*/
|
|
19
19
|
export function initAllSchedule(that: any): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* 初始化批量定时任务
|
|
22
|
+
* @param that
|
|
23
|
+
*/
|
|
24
|
+
export function initMultiTask(that: any): void;
|
|
20
25
|
/**
|
|
21
26
|
* 初始化提醒任务
|
|
22
27
|
* @param {}} that
|
|
@@ -28,4 +33,10 @@ export function initTimeSchedule(that: any): Promise<void>;
|
|
|
28
33
|
* @param {*} item 任务项 { target: 'Room', event: '', message: { roomName: '', type: 'news 新闻 ||task 定时任务', contents: [] } }
|
|
29
34
|
*/
|
|
30
35
|
export function sendTaskMessage(that: any, info: any): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* 立即发送批量任务消息
|
|
38
|
+
* @param {*} that bot对象
|
|
39
|
+
* @param {*} item 任务项 { target: 'Room', event: '', message: { roomName: '', type: 'news 新闻 ||task 定时任务', contents: [] } }
|
|
40
|
+
*/
|
|
41
|
+
export function sendMultiTaskMessage(that: any, task: any): Promise<void>;
|
|
31
42
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -2,9 +2,9 @@ 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
4
|
import { getNewsContent, getEveryDayContent, roomSay, getRoomEveryDayContent, contactSay, getCountDownContent } from "../common/index.js";
|
|
5
|
+
import globalConfig from "../db/global.js";
|
|
5
6
|
const typeMap = {
|
|
6
|
-
contact: "用户名",
|
|
7
|
-
room: "群名"
|
|
7
|
+
contact: "用户名", room: "群名"
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* 查找发送的目标
|
|
@@ -13,7 +13,7 @@ const typeMap = {
|
|
|
13
13
|
* alias: 别名
|
|
14
14
|
* wxid: wxid
|
|
15
15
|
*/
|
|
16
|
-
async function findTarget({ that, type, name, alias, wxid =
|
|
16
|
+
async function findTarget({ that, type, name, alias, wxid = "" }) {
|
|
17
17
|
let target = null;
|
|
18
18
|
if (type === "contact") {
|
|
19
19
|
target = wxid && that.Contact.find({ id: wxid }) || name && (await that.Contact.find({ name: name })) || alias && (await that.Contact.find({ alias: alias })); // 获取你要发送的联系人
|
|
@@ -35,7 +35,9 @@ async function setTask(that, item, name, callback) {
|
|
|
35
35
|
try {
|
|
36
36
|
let time = item.date;
|
|
37
37
|
item.type = item.type ? item.type : "contact";
|
|
38
|
-
const target = await findTarget({
|
|
38
|
+
const target = await findTarget({
|
|
39
|
+
that, type: item.type, name: item.roomName || item.name, alias: item.alias || "", wxid: item.wxid || ""
|
|
40
|
+
});
|
|
39
41
|
if (!target) {
|
|
40
42
|
console.log(`查找不到${typeMap[item.type]}:${item.roomName || item.name}`);
|
|
41
43
|
}
|
|
@@ -53,17 +55,45 @@ async function setTask(that, item, name, callback) {
|
|
|
53
55
|
* @param that
|
|
54
56
|
* @param target
|
|
55
57
|
* @param item
|
|
58
|
+
* @param isMulti 是否多个目标
|
|
59
|
+
* @param targets 发送的多个目标
|
|
56
60
|
* @return {Promise<void>}
|
|
57
61
|
*/
|
|
58
|
-
const sendCustom = async ({ that, target, item }) => {
|
|
62
|
+
const sendCustom = async ({ that, target, item, isMulti, targets }) => {
|
|
59
63
|
for (let reply of item.contents) {
|
|
60
64
|
console.log("定时任务开始发送,内容:", `${reply.type === 1 ? reply.content : reply.url}`);
|
|
61
65
|
await delay(1000);
|
|
62
66
|
if (item.type === "room") {
|
|
63
|
-
|
|
67
|
+
if (!isMulti) {
|
|
68
|
+
await roomSay.call(that, target, "", reply);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
for (let single of targets) {
|
|
72
|
+
await roomSay.call(that, single, "", reply);
|
|
73
|
+
if (item.delay) {
|
|
74
|
+
await delay(item.delay);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
await delay(1000);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
64
81
|
}
|
|
65
82
|
else {
|
|
66
|
-
|
|
83
|
+
if (!isMulti) {
|
|
84
|
+
await contactSay.call(that, target, reply);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
for (let single of targets) {
|
|
88
|
+
await contactSay.call(that, single, reply);
|
|
89
|
+
if (item.delay) {
|
|
90
|
+
await delay(item.delay);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
await delay(1000);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
67
97
|
}
|
|
68
98
|
}
|
|
69
99
|
};
|
|
@@ -72,13 +102,28 @@ const sendCustom = async ({ that, target, item }) => {
|
|
|
72
102
|
* @param that
|
|
73
103
|
* @param target
|
|
74
104
|
* @param item
|
|
105
|
+
* @param isMulti 是否多个目标
|
|
106
|
+
* @param targets 发送的多个目标
|
|
75
107
|
* @return {Promise<void>}
|
|
76
108
|
*/
|
|
77
|
-
const sendNews = async ({ that, target, item }) => {
|
|
109
|
+
const sendNews = async ({ that, target, item, isMulti, targets }) => {
|
|
78
110
|
let content = await getNewsContent(item.sortId, item.endWord, item.num || 10);
|
|
79
111
|
console.log("新闻资讯开始发送,内容:", content);
|
|
80
|
-
await delay(
|
|
81
|
-
|
|
112
|
+
await delay(200);
|
|
113
|
+
if (!isMulti) {
|
|
114
|
+
await target.say(content);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
for (let single of targets) {
|
|
118
|
+
await single.say(content);
|
|
119
|
+
if (item.delay) {
|
|
120
|
+
await delay(item.delay);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
await delay(1000);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
82
127
|
};
|
|
83
128
|
/**
|
|
84
129
|
* 发送每日说
|
|
@@ -96,7 +141,7 @@ const sendEveryDay = async ({ that, target, item }) => {
|
|
|
96
141
|
content = await getEveryDayContent(item.memorialDay, item.city, item.endWord);
|
|
97
142
|
}
|
|
98
143
|
console.log("每日说任务开始工作,发送内容:", content);
|
|
99
|
-
await delay(
|
|
144
|
+
await delay(1000);
|
|
100
145
|
await target.say(content);
|
|
101
146
|
};
|
|
102
147
|
/**
|
|
@@ -104,13 +149,28 @@ const sendEveryDay = async ({ that, target, item }) => {
|
|
|
104
149
|
* @param that
|
|
105
150
|
* @param target
|
|
106
151
|
* @param item
|
|
152
|
+
* @param isMulti 是否多个目标
|
|
153
|
+
* @param targets 发送的多个目标
|
|
107
154
|
* @return {Promise<void>}
|
|
108
155
|
*/
|
|
109
|
-
const sendCountDown = async ({ that, target, item }) => {
|
|
156
|
+
const sendCountDown = async ({ that, target, item, isMulti, targets }) => {
|
|
110
157
|
let content = await getCountDownContent(item.memorialDay, item.prefix, item.suffix, item.endWord);
|
|
111
158
|
console.log("倒计时任务开始工作,发送内容:", content);
|
|
112
|
-
await delay(
|
|
113
|
-
|
|
159
|
+
await delay(1000);
|
|
160
|
+
if (!isMulti) {
|
|
161
|
+
await target.say(content);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
for (let single of targets) {
|
|
165
|
+
await single.say(content);
|
|
166
|
+
if (item.delay) {
|
|
167
|
+
await delay(item.delay);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
await delay(1000);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
114
174
|
};
|
|
115
175
|
/**
|
|
116
176
|
* 立即发送群消息
|
|
@@ -121,7 +181,9 @@ async function sendTaskMessage(that, info) {
|
|
|
121
181
|
try {
|
|
122
182
|
const item = info.message;
|
|
123
183
|
item.type = item.type ? item.type : "room";
|
|
124
|
-
const target = await findTarget({
|
|
184
|
+
const target = await findTarget({
|
|
185
|
+
that, type: item.type, name: item.roomName || item.name, alias: item.alias || "", wxid: item.wxid || ""
|
|
186
|
+
});
|
|
125
187
|
if (!target) {
|
|
126
188
|
console.log(`查找不到${typeMap[item.type]}:${item.roomName || item.name}`);
|
|
127
189
|
}
|
|
@@ -205,19 +267,19 @@ async function initTaskLocalSchedule(that) {
|
|
|
205
267
|
// 每日说定时任务
|
|
206
268
|
if (dayTaskSchedule && dayTaskSchedule.length > 0) {
|
|
207
269
|
dayTaskSchedule.forEach((item, index) => {
|
|
208
|
-
setTask(that, { type:
|
|
270
|
+
setTask(that, { type: "contact", ...item }, `task_day_${index}`, sendEveryDay);
|
|
209
271
|
});
|
|
210
272
|
}
|
|
211
273
|
// 新闻资讯定时任务
|
|
212
274
|
if (roomNewsSchedule && roomNewsSchedule.length > 0) {
|
|
213
275
|
roomNewsSchedule.forEach((item, index) => {
|
|
214
|
-
setTask(that, { type:
|
|
276
|
+
setTask(that, { type: "room", ...item }, `task_news_${index}`, sendNews);
|
|
215
277
|
});
|
|
216
278
|
}
|
|
217
279
|
// 自定义内容定时任务
|
|
218
280
|
if (roomTaskSchedule && roomTaskSchedule.length > 0) {
|
|
219
281
|
roomTaskSchedule.forEach((item, index) => {
|
|
220
|
-
setTask(that, { type:
|
|
282
|
+
setTask(that, { type: "room", ...item }, `task_custom_${index}`, sendCustom);
|
|
221
283
|
});
|
|
222
284
|
}
|
|
223
285
|
// 倒计时定时任务
|
|
@@ -231,6 +293,121 @@ async function initTaskLocalSchedule(that) {
|
|
|
231
293
|
console.log("initTaskLocalSchedule error", e);
|
|
232
294
|
}
|
|
233
295
|
}
|
|
296
|
+
async function getMultiTargets(that, type, task) {
|
|
297
|
+
const targets = [];
|
|
298
|
+
if (task.isAll) {
|
|
299
|
+
const allTargets = type === "room" ? await that.Room.findAll() : await that.Contact.findAll();
|
|
300
|
+
if (task.excludeTargets) {
|
|
301
|
+
allTargets.forEach(target => {
|
|
302
|
+
const find = type === "room" ? task.excludeTargets.find(eItem => target.id === eItem.id || target.topic() === eItem.name) : task.excludeTargets.find(eItem => target.id === eItem.id || target.name() === eItem.name);
|
|
303
|
+
if (type === "room") {
|
|
304
|
+
if (!find) {
|
|
305
|
+
targets.push(target);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
if (!find && target.friend()) {
|
|
310
|
+
targets.push(target);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
for (let target of task.targets) {
|
|
318
|
+
const finalTarget = type === "room" ? await that.Room.find({
|
|
319
|
+
id: target.id, topic: target.name
|
|
320
|
+
}) : await that.Contact.find({ id: target.id, name: target.name });
|
|
321
|
+
if (finalTarget) {
|
|
322
|
+
targets.push(finalTarget);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
console.log(`定时任务查找不到${type === "room" ? "群" : "好友"}:${target.name},请检查${type === "room" ? "群名" : "好友昵称"}是否正确`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return targets;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* 立即发送批量任务消息
|
|
333
|
+
* @param {*} that bot对象
|
|
334
|
+
* @param {*} item 任务项 { target: 'Room', event: '', message: { roomName: '', type: 'news 新闻 ||task 定时任务', contents: [] } }
|
|
335
|
+
*/
|
|
336
|
+
async function sendMultiTaskMessage(that, task) {
|
|
337
|
+
try {
|
|
338
|
+
const targets = await getMultiTargets(that, task.type, task);
|
|
339
|
+
if (!targets.length) {
|
|
340
|
+
console.log("查找不到要发送的目标,请检查后重试");
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (task.taskType === 'news') {
|
|
344
|
+
await sendNews({ that, isMulti: true, targets, item: task.taskInfo });
|
|
345
|
+
}
|
|
346
|
+
else if (task.taskType === 'custom') {
|
|
347
|
+
await sendCustom({ that, isMulti: true, targets, item: { ...task.taskInfo, type: task.type } });
|
|
348
|
+
}
|
|
349
|
+
else if (task.taskType === "countdown") {
|
|
350
|
+
await sendCountDown({ that, isMulti: true, targets, item: task.taskInfo });
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
console.log("立即发送定时任务失败:", error);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
async function setMultiTask(that, task) {
|
|
358
|
+
try {
|
|
359
|
+
// 获取要发送的目标
|
|
360
|
+
const targets = await getMultiTargets(that, task.type, task);
|
|
361
|
+
if (!targets.length) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (task.taskType === "news") {
|
|
365
|
+
setLocalSchedule(task.cron, sendNews.bind(null, {
|
|
366
|
+
that,
|
|
367
|
+
isMulti: true,
|
|
368
|
+
targets,
|
|
369
|
+
item: task.taskInfo
|
|
370
|
+
}), `schedule_news_${task.id}`);
|
|
371
|
+
}
|
|
372
|
+
else if (task.taskType === "custom") {
|
|
373
|
+
setLocalSchedule(task.cron, sendCustom.bind(null, {
|
|
374
|
+
that,
|
|
375
|
+
isMulti: true,
|
|
376
|
+
targets,
|
|
377
|
+
item: { ...task.taskInfo, type: task.type }
|
|
378
|
+
}), `schedule_custom_${task.id}`);
|
|
379
|
+
}
|
|
380
|
+
else if (task.taskType === "countDown") {
|
|
381
|
+
setLocalSchedule(task.cron, sendCountDown.bind(null, {
|
|
382
|
+
that,
|
|
383
|
+
isMulti: true,
|
|
384
|
+
targets,
|
|
385
|
+
item: task.taskInfo
|
|
386
|
+
}), `schedule_countdown_${task.id}`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
catch (e) {
|
|
390
|
+
console.log("catch error:" + e);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* 初始化批量定时任务
|
|
395
|
+
* @param that
|
|
396
|
+
*/
|
|
397
|
+
function initMultiTask(that) {
|
|
398
|
+
try {
|
|
399
|
+
cancelAllSchedule("schedule");
|
|
400
|
+
const tasks = globalConfig.getAllTasks(); // 获取所有任务
|
|
401
|
+
if (tasks && tasks.length) {
|
|
402
|
+
tasks.forEach((item, index) => {
|
|
403
|
+
void setMultiTask(that, item);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
catch (e) {
|
|
408
|
+
console.log("initMultiTask error:" + e);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
234
411
|
/**
|
|
235
412
|
* 初始化小助手任务
|
|
236
413
|
* @param {*} that bot对象
|
|
@@ -244,11 +421,11 @@ async function initAllSchedule(that) {
|
|
|
244
421
|
}
|
|
245
422
|
export { initTaskLocalSchedule };
|
|
246
423
|
export { initAllSchedule };
|
|
424
|
+
export { initMultiTask };
|
|
247
425
|
export { initTimeSchedule };
|
|
248
426
|
export { sendTaskMessage };
|
|
427
|
+
export { sendMultiTaskMessage };
|
|
249
428
|
export default {
|
|
250
|
-
initTaskLocalSchedule,
|
|
251
|
-
initAllSchedule,
|
|
252
|
-
initTimeSchedule,
|
|
429
|
+
initTaskLocalSchedule, initAllSchedule, initTimeSchedule
|
|
253
430
|
};
|
|
254
431
|
//# sourceMappingURL=index.js.map
|