yz-yuki-plugin 2.0.7-17 → 2.0.7-18

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.
@@ -389,19 +389,18 @@ class BiliTask {
389
389
  // 遍历组合消息
390
390
  for (const messageCombination of messageCombinationList) {
391
391
  const { sendMode, dynamicUUid_str, dynamicType, messages } = messageCombination;
392
- let sended = null;
393
392
  let markKey = '';
394
393
  if (chatType === 'group') {
395
394
  markKey = this.groupKey;
396
- sended = await Redis.get(`${markKey}${chatId}:${dynamicUUid_str}`);
397
395
  }
398
396
  else if (chatType === 'private') {
399
397
  markKey = this.privateKey;
400
- sended = await Redis.get(`${markKey}${chatId}:${dynamicUUid_str}`);
401
398
  }
402
399
  const sendMarkKey = `${markKey}${chatId}:${dynamicUUid_str}`;
403
- if (sended) {
404
- continue; // 如果已经发送过,则直接跳过
400
+ // 原子性设置标记,防止并发重复
401
+ const setResult = await Redis.set(sendMarkKey, '1', { NX: true, EX: 3600 * 72 });
402
+ if (!setResult) {
403
+ continue; // 已有标记,跳过
405
404
  }
406
405
  if (!LogMark.has('1')) {
407
406
  global?.logger?.mark('优纪插件: B站动态执行推送');
@@ -422,23 +421,26 @@ class BiliTask {
422
421
  }
423
422
  }
424
423
  }
424
+ let sendSuccess = true;
425
425
  if (sendMode === 'SINGLE') {
426
- let allSent = true;
427
426
  for (let i = 0; i < messages.length; i++) {
428
427
  if (!(await this.sendMessageApi(chatId, bot_id, chatType, messages[i]))) {
429
- allSent = false;
430
- break; // 如果有任何一条消息发送失败,停止发送后续消息
428
+ sendSuccess = false;
429
+ break;
431
430
  }
432
431
  }
433
- if (allSent) {
434
- await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
435
- await this.randomDelay(1000, 2000); // 随机延时1-2秒
432
+ if (!sendSuccess) {
433
+ await Redis.del(sendMarkKey); // 失败删除标记
434
+ }
435
+ else {
436
+ await this.randomDelay(1000, 2000);
436
437
  }
437
438
  }
438
439
  else if (sendMode === 'MERGE') {
439
- if (await this.sendMessageApi(chatId, bot_id, chatType, messages)) {
440
- await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
440
+ if (!(await this.sendMessageApi(chatId, bot_id, chatType, messages))) {
441
+ await Redis.del(sendMarkKey); // 失败删除标记
441
442
  }
443
+ await this.randomDelay(1000, 2000);
442
444
  }
443
445
  }
444
446
  }
@@ -351,41 +351,43 @@ class WeiboTask {
351
351
  // 遍历组合消息
352
352
  for (const messageCombination of messageCombinationList) {
353
353
  const { sendMode, dynamicUUid_str, dynamicType, messages } = messageCombination;
354
- let sended = null;
355
354
  let markKey = '';
356
355
  if (chatType === 'group') {
357
356
  markKey = this.groupKey;
358
- sended = await Redis.get(`${markKey}${chatId}:${dynamicUUid_str}`);
359
357
  }
360
358
  else if (chatType === 'private') {
361
359
  markKey = this.privateKey;
362
- sended = await Redis.get(`${markKey}${chatId}:${dynamicUUid_str}`);
363
360
  }
364
361
  const sendMarkKey = `${markKey}${chatId}:${dynamicUUid_str}`;
365
- if (sended) {
366
- continue; // 如果已经发送过,则直接跳过
362
+ // 原子性设置标记,防止并发重复
363
+ const setResult = await Redis.set(sendMarkKey, '1', { NX: true, EX: 3600 * 72 });
364
+ if (!setResult) {
365
+ continue; // 已有标记,跳过
367
366
  }
368
367
  if (!LogMark.has('1')) {
369
368
  global?.logger?.mark('优纪插件: B站动态执行推送');
370
369
  LogMark.add('1');
371
370
  }
371
+ let sendSuccess = true;
372
372
  if (sendMode === 'SINGLE') {
373
- let allSent = true;
374
373
  for (let i = 0; i < messages.length; i++) {
375
374
  if (!(await this.sendMessageApi(chatId, bot_id, chatType, messages[i]))) {
376
- allSent = false;
377
- break; // 如果有任何一条消息发送失败,停止发送后续消息
375
+ sendSuccess = false;
376
+ break;
378
377
  }
379
378
  }
380
- if (allSent) {
381
- await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
382
- await this.randomDelay(1000, 2000); // 随机延时1-2秒
379
+ if (!sendSuccess) {
380
+ await Redis.del(sendMarkKey); // 失败删除标记
381
+ }
382
+ else {
383
+ await this.randomDelay(1000, 2000);
383
384
  }
384
385
  }
385
386
  else if (sendMode === 'MERGE') {
386
- if (await this.sendMessageApi(chatId, bot_id, chatType, messages)) {
387
- await Redis.set(sendMarkKey, '1', { EX: 3600 * 72 }); // 发送成功后设置标记
387
+ if (!(await this.sendMessageApi(chatId, bot_id, chatType, messages))) {
388
+ await Redis.del(sendMarkKey); // 失败删除标记
388
389
  }
390
+ await this.randomDelay(1000, 2000);
389
391
  }
390
392
  }
391
393
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yz-yuki-plugin",
3
- "version": "2.0.7-17",
3
+ "version": "2.0.7-18",
4
4
  "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
5
5
  "author": "snowtafir",
6
6
  "type": "module",