wechaty-web-panel 1.6.29 → 1.6.31

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 CHANGED
@@ -1,6 +1,9 @@
1
1
  ## 更新日志
2
2
 
3
- ### V1.6.28(2023-11-09)
3
+ ### V1.6.31(2023-11-18)
4
+ 1、修复批量定时任务的查询逻辑
5
+
6
+ ### V1.6.29(2023-11-09)
4
7
  1、添加批量定时任务功能
5
8
 
6
9
  ### V1.6.28(2023-11-07)
@@ -6,7 +6,7 @@ exports.packageJson = void 0;
6
6
  */
7
7
  exports.packageJson = {
8
8
  "name": "wechaty-web-panel",
9
- "version": "1.6.29",
9
+ "version": "1.6.31",
10
10
  "description": "智能微秘书插件",
11
11
  "exports": {
12
12
  ".": {
@@ -75,12 +75,17 @@ const sendCustom = async ({ that, target, item, isMulti, targets }) => {
75
75
  }
76
76
  else {
77
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);
78
+ try {
79
+ await index_js_2.roomSay.call(that, single, "", reply);
80
+ if (item.delay) {
81
+ await (0, index_js_1.delay)(item.delay);
82
+ }
83
+ else {
84
+ await (0, index_js_1.delay)(1000);
85
+ }
81
86
  }
82
- else {
83
- await (0, index_js_1.delay)(1000);
87
+ catch (e) {
88
+ console.log(`定时任务失败,可能群已经解散或者好友不存在: ${e}`);
84
89
  }
85
90
  }
86
91
  }
@@ -91,12 +96,17 @@ const sendCustom = async ({ that, target, item, isMulti, targets }) => {
91
96
  }
92
97
  else {
93
98
  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);
99
+ try {
100
+ await index_js_2.contactSay.call(that, single, reply);
101
+ if (item.delay) {
102
+ await (0, index_js_1.delay)(item.delay);
103
+ }
104
+ else {
105
+ await (0, index_js_1.delay)(1000);
106
+ }
97
107
  }
98
- else {
99
- await (0, index_js_1.delay)(1000);
108
+ catch (e) {
109
+ console.log(`定时任务失败,可能群已经解散或者好友不存在: ${e}`);
100
110
  }
101
111
  }
102
112
  }
@@ -121,12 +131,17 @@ const sendNews = async ({ that, target, item, isMulti, targets }) => {
121
131
  }
122
132
  else {
123
133
  for (let single of targets) {
124
- await single.say(content);
125
- if (item.delay) {
126
- await (0, index_js_1.delay)(item.delay);
134
+ try {
135
+ await single.say(content);
136
+ if (item.delay) {
137
+ await (0, index_js_1.delay)(item.delay);
138
+ }
139
+ else {
140
+ await (0, index_js_1.delay)(1000);
141
+ }
127
142
  }
128
- else {
129
- await (0, index_js_1.delay)(1000);
143
+ catch (e) {
144
+ console.log(`定时任务失败,可能群已经解散或者好友不存在: ${e}`);
130
145
  }
131
146
  }
132
147
  }
@@ -168,12 +183,17 @@ const sendCountDown = async ({ that, target, item, isMulti, targets }) => {
168
183
  }
169
184
  else {
170
185
  for (let single of targets) {
171
- await single.say(content);
172
- if (item.delay) {
173
- await (0, index_js_1.delay)(item.delay);
186
+ try {
187
+ await single.say(content);
188
+ if (item.delay) {
189
+ await (0, index_js_1.delay)(item.delay);
190
+ }
191
+ else {
192
+ await (0, index_js_1.delay)(1000);
193
+ }
174
194
  }
175
- else {
176
- await (0, index_js_1.delay)(1000);
195
+ catch (e) {
196
+ console.log(`定时任务失败,可能群已经解散或者好友不存在,不影响其他群发消息: ${e}`);
177
197
  }
178
198
  }
179
199
  }
@@ -321,6 +341,7 @@ async function getMultiTargets(that, type, task) {
321
341
  }
322
342
  });
323
343
  }
344
+ console.log(`查询到全部${type === 'room' ? '群聊' : '好友'}数量为:${targets.length}`);
324
345
  }
325
346
  else {
326
347
  for (let target of task.targets) {
@@ -364,35 +385,54 @@ async function sendMultiTaskMessage(that, task) {
364
385
  }
365
386
  }
366
387
  exports.sendMultiTaskMessage = sendMultiTaskMessage;
388
+ async function startSendMultiTask({ that, task }) {
389
+ const targets = await getMultiTargets(that, task.type, task);
390
+ if (!targets.length) {
391
+ return;
392
+ }
393
+ if (task.taskType === "news") {
394
+ await sendNews({
395
+ that,
396
+ isMulti: true,
397
+ targets,
398
+ item: task.taskInfo
399
+ });
400
+ }
401
+ else if (task.taskType === "custom") {
402
+ await sendCustom({
403
+ that,
404
+ isMulti: true,
405
+ targets,
406
+ item: { ...task.taskInfo, type: task.type }
407
+ });
408
+ }
409
+ else if (task.taskType === "countDown") {
410
+ await sendCountDown({
411
+ that,
412
+ isMulti: true,
413
+ targets,
414
+ item: task.taskInfo
415
+ });
416
+ }
417
+ }
367
418
  async function setMultiTask(that, task) {
368
419
  try {
369
- // 获取要发送的目标
370
- const targets = await getMultiTargets(that, task.type, task);
371
- if (!targets.length) {
372
- return;
373
- }
374
420
  if (task.taskType === "news") {
375
- (0, index_js_1.setLocalSchedule)(task.cron, sendNews.bind(null, {
421
+ (0, index_js_1.setLocalSchedule)(task.cron, startSendMultiTask.bind(null, {
376
422
  that,
377
- isMulti: true,
378
- targets,
379
- item: task.taskInfo
423
+ task
380
424
  }), `schedule_news_${task.id}`);
381
425
  }
382
426
  else if (task.taskType === "custom") {
383
- (0, index_js_1.setLocalSchedule)(task.cron, sendCustom.bind(null, {
427
+ (0, index_js_1.setLocalSchedule)(task.cron, startSendMultiTask.bind(null, {
384
428
  that,
385
- isMulti: true,
386
- targets,
387
- item: { ...task.taskInfo, type: task.type }
429
+ task
388
430
  }), `schedule_custom_${task.id}`);
389
431
  }
390
432
  else if (task.taskType === "countDown") {
391
- (0, index_js_1.setLocalSchedule)(task.cron, sendCountDown.bind(null, {
433
+ (0, index_js_1.setLocalSchedule)(task.cron, startSendMultiTask.bind(null, {
392
434
  that,
393
- isMulti: true,
394
- targets,
395
- item: task.taskInfo
435
+ task
396
436
  }), `schedule_countdown_${task.id}`);
397
437
  }
398
438
  }
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const packageJson = {
5
5
  "name": "wechaty-web-panel",
6
- "version": "1.6.29",
6
+ "version": "1.6.31",
7
7
  "description": "智能微秘书插件",
8
8
  "exports": {
9
9
  ".": {
@@ -69,12 +69,17 @@ const sendCustom = async ({ that, target, item, isMulti, targets }) => {
69
69
  }
70
70
  else {
71
71
  for (let single of targets) {
72
- await roomSay.call(that, single, "", reply);
73
- if (item.delay) {
74
- await delay(item.delay);
72
+ try {
73
+ await roomSay.call(that, single, "", reply);
74
+ if (item.delay) {
75
+ await delay(item.delay);
76
+ }
77
+ else {
78
+ await delay(1000);
79
+ }
75
80
  }
76
- else {
77
- await delay(1000);
81
+ catch (e) {
82
+ console.log(`定时任务失败,可能群已经解散或者好友不存在: ${e}`);
78
83
  }
79
84
  }
80
85
  }
@@ -85,12 +90,17 @@ const sendCustom = async ({ that, target, item, isMulti, targets }) => {
85
90
  }
86
91
  else {
87
92
  for (let single of targets) {
88
- await contactSay.call(that, single, reply);
89
- if (item.delay) {
90
- await delay(item.delay);
93
+ try {
94
+ await contactSay.call(that, single, reply);
95
+ if (item.delay) {
96
+ await delay(item.delay);
97
+ }
98
+ else {
99
+ await delay(1000);
100
+ }
91
101
  }
92
- else {
93
- await delay(1000);
102
+ catch (e) {
103
+ console.log(`定时任务失败,可能群已经解散或者好友不存在: ${e}`);
94
104
  }
95
105
  }
96
106
  }
@@ -115,12 +125,17 @@ const sendNews = async ({ that, target, item, isMulti, targets }) => {
115
125
  }
116
126
  else {
117
127
  for (let single of targets) {
118
- await single.say(content);
119
- if (item.delay) {
120
- await delay(item.delay);
128
+ try {
129
+ await single.say(content);
130
+ if (item.delay) {
131
+ await delay(item.delay);
132
+ }
133
+ else {
134
+ await delay(1000);
135
+ }
121
136
  }
122
- else {
123
- await delay(1000);
137
+ catch (e) {
138
+ console.log(`定时任务失败,可能群已经解散或者好友不存在: ${e}`);
124
139
  }
125
140
  }
126
141
  }
@@ -162,12 +177,17 @@ const sendCountDown = async ({ that, target, item, isMulti, targets }) => {
162
177
  }
163
178
  else {
164
179
  for (let single of targets) {
165
- await single.say(content);
166
- if (item.delay) {
167
- await delay(item.delay);
180
+ try {
181
+ await single.say(content);
182
+ if (item.delay) {
183
+ await delay(item.delay);
184
+ }
185
+ else {
186
+ await delay(1000);
187
+ }
168
188
  }
169
- else {
170
- await delay(1000);
189
+ catch (e) {
190
+ console.log(`定时任务失败,可能群已经解散或者好友不存在,不影响其他群发消息: ${e}`);
171
191
  }
172
192
  }
173
193
  }
@@ -312,6 +332,7 @@ async function getMultiTargets(that, type, task) {
312
332
  }
313
333
  });
314
334
  }
335
+ console.log(`查询到全部${type === 'room' ? '群聊' : '好友'}数量为:${targets.length}`);
315
336
  }
316
337
  else {
317
338
  for (let target of task.targets) {
@@ -354,35 +375,54 @@ async function sendMultiTaskMessage(that, task) {
354
375
  console.log("立即发送定时任务失败:", error);
355
376
  }
356
377
  }
378
+ async function startSendMultiTask({ that, task }) {
379
+ const targets = await getMultiTargets(that, task.type, task);
380
+ if (!targets.length) {
381
+ return;
382
+ }
383
+ if (task.taskType === "news") {
384
+ await sendNews({
385
+ that,
386
+ isMulti: true,
387
+ targets,
388
+ item: task.taskInfo
389
+ });
390
+ }
391
+ else if (task.taskType === "custom") {
392
+ await sendCustom({
393
+ that,
394
+ isMulti: true,
395
+ targets,
396
+ item: { ...task.taskInfo, type: task.type }
397
+ });
398
+ }
399
+ else if (task.taskType === "countDown") {
400
+ await sendCountDown({
401
+ that,
402
+ isMulti: true,
403
+ targets,
404
+ item: task.taskInfo
405
+ });
406
+ }
407
+ }
357
408
  async function setMultiTask(that, task) {
358
409
  try {
359
- // 获取要发送的目标
360
- const targets = await getMultiTargets(that, task.type, task);
361
- if (!targets.length) {
362
- return;
363
- }
364
410
  if (task.taskType === "news") {
365
- setLocalSchedule(task.cron, sendNews.bind(null, {
411
+ setLocalSchedule(task.cron, startSendMultiTask.bind(null, {
366
412
  that,
367
- isMulti: true,
368
- targets,
369
- item: task.taskInfo
413
+ task
370
414
  }), `schedule_news_${task.id}`);
371
415
  }
372
416
  else if (task.taskType === "custom") {
373
- setLocalSchedule(task.cron, sendCustom.bind(null, {
417
+ setLocalSchedule(task.cron, startSendMultiTask.bind(null, {
374
418
  that,
375
- isMulti: true,
376
- targets,
377
- item: { ...task.taskInfo, type: task.type }
419
+ task
378
420
  }), `schedule_custom_${task.id}`);
379
421
  }
380
422
  else if (task.taskType === "countDown") {
381
- setLocalSchedule(task.cron, sendCountDown.bind(null, {
423
+ setLocalSchedule(task.cron, startSendMultiTask.bind(null, {
382
424
  that,
383
- isMulti: true,
384
- targets,
385
- item: task.taskInfo
425
+ task
386
426
  }), `schedule_countdown_${task.id}`);
387
427
  }
388
428
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechaty-web-panel",
3
- "version": "1.6.29",
3
+ "version": "1.6.31",
4
4
  "description": "智能微秘书插件",
5
5
  "exports": {
6
6
  ".": {