koishi-plugin-cat-raising 1.3.7 → 1.3.8

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.
Files changed (2) hide show
  1. package/lib/index.js +23 -1
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -315,6 +315,8 @@ __name(fetchBilibiliInfo, "fetchBilibiliInfo");
315
315
  function apply(ctx, config) {
316
316
  const forwardedHistory = [];
317
317
  const warningMessageMap = /* @__PURE__ */ new Map();
318
+ const pendingDanmakuTimersByMessage = /* @__PURE__ */ new Map();
319
+ const pendingDanmakuTimersByRoom = /* @__PURE__ */ new Map();
318
320
  ctx.on("message", async (session) => {
319
321
  const groupConfig = config.monitorGroups.find((g) => g.groupId === session.channelId);
320
322
  if (!groupConfig) return;
@@ -380,12 +382,22 @@ function apply(ctx, config) {
380
382
  const max = Math.max(min, config.danmakuDelayMaxSeconds ?? 10);
381
383
  const delayMs = (Math.floor(Math.random() * (max - min + 1)) + min) * 1e3;
382
384
  ctx.logger.info(`[弹幕] ${config.biliAccessKeys.length} 个账号将于 ${Math.round(delayMs / 1e3)} 秒后发送弹幕到直播间 ${roomId}。`);
383
- setTimeout(() => {
385
+ const timer = setTimeout(() => {
386
+ const list1 = pendingDanmakuTimersByMessage.get(session.messageId);
387
+ if (list1) pendingDanmakuTimersByMessage.set(session.messageId, list1.filter((t) => t !== timer));
388
+ const list2 = pendingDanmakuTimersByRoom.get(roomId);
389
+ if (list2) pendingDanmakuTimersByRoom.set(roomId, list2.filter((t) => t !== timer));
384
390
  const danmakuPromises = config.biliAccessKeys.map(
385
391
  (keyConfig) => sendBilibiliDanmaku(ctx, keyConfig, roomId, "喵喵喵")
386
392
  );
387
393
  Promise.allSettled(danmakuPromises);
388
394
  }, delayMs);
395
+ const byMsg = pendingDanmakuTimersByMessage.get(session.messageId) || [];
396
+ byMsg.push(timer);
397
+ pendingDanmakuTimersByMessage.set(session.messageId, byMsg);
398
+ const byRoom = pendingDanmakuTimersByRoom.get(roomId) || [];
399
+ byRoom.push(timer);
400
+ pendingDanmakuTimersByRoom.set(roomId, byRoom);
389
401
  }
390
402
  } catch (error) {
391
403
  session.send("🐱 - 转发失败,请检查目标QQ/群号配置是否正确");
@@ -399,6 +411,16 @@ function apply(ctx, config) {
399
411
  const entryIndex = forwardedHistory.findIndex((entry) => entry.originalMessageId === originalMessageId);
400
412
  if (entryIndex !== -1) {
401
413
  const entry = forwardedHistory[entryIndex];
414
+ const timersByMsg = pendingDanmakuTimersByMessage.get(originalMessageId);
415
+ if (timersByMsg) {
416
+ for (const t of timersByMsg) clearTimeout(t);
417
+ pendingDanmakuTimersByMessage.delete(originalMessageId);
418
+ }
419
+ const timersByRoom = pendingDanmakuTimersByRoom.get(entry.roomId);
420
+ if (timersByRoom) {
421
+ for (const t of timersByRoom) clearTimeout(t);
422
+ pendingDanmakuTimersByRoom.delete(entry.roomId);
423
+ }
402
424
  if (entry.helperMessageId) {
403
425
  try {
404
426
  await session.bot.deleteMessage(session.channelId, entry.helperMessageId);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cat-raising",
3
3
  "description": "",
4
- "version": "1.3.7",
4
+ "version": "1.3.8",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [