yz-yuki-plugin 2.0.7-6 → 2.0.7-7

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.
@@ -421,15 +421,22 @@ class BiliTask {
421
421
  }
422
422
  }
423
423
  if (sendMode === 'SINGLE') {
424
+ let allSent = true;
424
425
  for (let i = 0; i < messages.length; i++) {
425
- await this.sendMessageApi(chatId, bot_id, chatType, messages[i]);
426
+ if (!(await this.sendMessageApi(chatId, bot_id, chatType, messages[i]))) {
427
+ allSent = false;
428
+ break; // 如果有任何一条消息发送失败,停止发送后续消息
429
+ }
430
+ }
431
+ if (allSent) {
432
+ await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
433
+ await this.randomDelay(1000, 2000); // 随机延时1-2秒
426
434
  }
427
- await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
428
- await this.randomDelay(1000, 2000); // 随机延时1-2秒
429
435
  }
430
436
  else if (sendMode === 'MERGE') {
431
- await this.sendMessageApi(chatId, bot_id, chatType, messages);
432
- await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
437
+ if (await this.sendMessageApi(chatId, bot_id, chatType, messages)) {
438
+ await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
439
+ }
433
440
  }
434
441
  }
435
442
  }
@@ -445,21 +452,18 @@ class BiliTask {
445
452
  * @param message 消息内容
446
453
  */
447
454
  async sendMessageApi(chatId, bot_id, chatType, message) {
448
- if (chatType === 'group') {
449
- await (Bot[bot_id] ?? Bot)
450
- ?.pickGroup(String(chatId))
451
- .sendMsg(message) // 发送群聊
452
- .catch((error) => {
453
- global?.logger?.error(`群组[${chatId}]推送失败:${JSON.stringify(error)}`);
454
- });
455
+ try {
456
+ if (chatType === 'group') {
457
+ await (Bot[bot_id] ?? Bot)?.pickGroup(String(chatId)).sendMsg(message); // 发送群聊
458
+ }
459
+ else if (chatType === 'private') {
460
+ await (Bot[bot_id] ?? Bot)?.pickFriend(String(chatId)).sendMsg(message); // 发送好友私聊
461
+ }
462
+ return true; // 发送成功
455
463
  }
456
- else if (chatType === 'private') {
457
- await (Bot[bot_id] ?? Bot)
458
- ?.pickFriend(String(chatId))
459
- .sendMsg(message)
460
- .catch((error) => {
461
- global?.logger?.error(`用户[${chatId}]推送失败:${JSON.stringify(error)}`);
462
- }); // 发送好友私聊
464
+ catch (error) {
465
+ global?.logger?.error(`${chatType === 'group' ? '群聊' : '私聊'} ${chatId} 消息发送失败:${JSON.stringify(error)}`);
466
+ return false; // 发送失败
463
467
  }
464
468
  }
465
469
  /**
@@ -368,15 +368,22 @@ class WeiboTask {
368
368
  LogMark.add('1');
369
369
  }
370
370
  if (sendMode === 'SINGLE') {
371
+ let allSent = true;
371
372
  for (let i = 0; i < messages.length; i++) {
372
- await this.sendMessageApi(chatId, bot_id, chatType, messages[i]);
373
+ if (!(await this.sendMessageApi(chatId, bot_id, chatType, messages[i]))) {
374
+ allSent = false;
375
+ break; // 如果有任何一条消息发送失败,停止发送后续消息
376
+ }
377
+ }
378
+ if (allSent) {
379
+ await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
380
+ await this.randomDelay(1000, 2000); // 随机延时1-2秒
373
381
  }
374
- await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
375
- await this.randomDelay(1000, 2000); // 随机延时1-2秒
376
382
  }
377
383
  else if (sendMode === 'MERGE') {
378
- await this.sendMessageApi(chatId, bot_id, chatType, messages);
379
- await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
384
+ if (await this.sendMessageApi(chatId, bot_id, chatType, messages)) {
385
+ await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
386
+ }
380
387
  }
381
388
  }
382
389
  }
@@ -392,21 +399,18 @@ class WeiboTask {
392
399
  * @param message 消息内容
393
400
  */
394
401
  async sendMessageApi(chatId, bot_id, chatType, message) {
395
- if (chatType === 'group') {
396
- await (Bot[bot_id] ?? Bot)
397
- ?.pickGroup(String(chatId))
398
- .sendMsg(message) // 发送群聊
399
- .catch(error => {
400
- global?.logger?.error(`群组[${chatId}]推送失败:${JSON.stringify(error)}`);
401
- });
402
+ try {
403
+ if (chatType === 'group') {
404
+ await (Bot[bot_id] ?? Bot)?.pickGroup(String(chatId)).sendMsg(message); // 发送群聊
405
+ }
406
+ else if (chatType === 'private') {
407
+ await (Bot[bot_id] ?? Bot)?.pickFriend(String(chatId)).sendMsg(message); // 发送好友私聊
408
+ }
409
+ return true; // 发送成功
402
410
  }
403
- else if (chatType === 'private') {
404
- await (Bot[bot_id] ?? Bot)
405
- ?.pickFriend(String(chatId))
406
- .sendMsg(message)
407
- .catch(error => {
408
- global?.logger?.error(`用户[${chatId}]推送失败:${JSON.stringify(error)}`);
409
- }); // 发送好友私聊
411
+ catch (error) {
412
+ global?.logger?.error(`${chatType === 'group' ? '群聊' : '私聊'} ${chatId} 消息发送失败:${JSON.stringify(error)}`);
413
+ return false; // 发送失败
410
414
  }
411
415
  }
412
416
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yz-yuki-plugin",
3
- "version": "2.0.7-6",
3
+ "version": "2.0.7-7",
4
4
  "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
5
5
  "author": "snowtafir",
6
6
  "type": "module",