koishi-plugin-ccb-plus 0.2.10 → 0.2.11

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 +16 -5
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -78,7 +78,8 @@ function applyDatabase(ctx) {
78
78
  userId: "string",
79
79
  optOut: "boolean",
80
80
  lastToggleTime: "unsigned",
81
- overrides: "json"
81
+ overrides: "json",
82
+ lastToggleTimes: "json"
82
83
  }, {
83
84
  primary: "userId"
84
85
  });
@@ -399,28 +400,38 @@ function applyCcbCommand(ctx, config, state) {
399
400
  }
400
401
  }
401
402
  const [userSetting] = await ctx.database.get("ccb_setting", { userId: senderId });
402
- const lastToggle = userSetting?.lastToggleTime || 0;
403
+ const targetKey = targetUserStr || "__global__";
404
+ const lastToggleTimes = { ...userSetting?.lastToggleTimes || {} };
405
+ let lastToggle = lastToggleTimes[targetKey] || 0;
406
+ if (targetKey === "__global__" && !lastToggle) {
407
+ lastToggle = userSetting?.lastToggleTime || 0;
408
+ }
403
409
  const cooldownResult = checkCooldown(lastToggle);
404
410
  if (cooldownResult) return cooldownResult;
405
411
  const nowMs = Date.now();
412
+ lastToggleTimes[targetKey] = nowMs;
406
413
  if (!targetUserStr) {
407
414
  const newOptOut = !!isOff;
408
415
  await ctx.database.upsert("ccb_setting", [{
409
416
  userId: senderId,
410
417
  optOut: newOptOut,
411
418
  lastToggleTime: nowMs,
412
- overrides: userSetting?.overrides || {}
419
+ // 保持更新以供兼容
420
+ lastToggleTimes,
421
+ overrides: { ...userSetting?.overrides || {} }
413
422
  }]);
414
423
  return newOptOut ? "已开启全局保护模式,阻止你被ccb。" : "已关闭全局保护模式,允许你被ccb。";
415
424
  } else {
416
425
  const targetId = targetUserStr;
417
- const overrides = userSetting?.overrides || {};
426
+ const overrides = { ...userSetting?.overrides || {} };
418
427
  overrides[targetId] = !isOff;
419
428
  await ctx.database.upsert("ccb_setting", [{
420
429
  userId: senderId,
421
430
  overrides,
422
431
  optOut: userSetting?.optOut ?? false,
423
- lastToggleTime: nowMs
432
+ lastToggleTime: userSetting?.lastToggleTime || 0,
433
+ // 不改变全局旧字段
434
+ lastToggleTimes
424
435
  }]);
425
436
  const targetNick = await state.getUserNickname(session, targetId).catch(() => targetId) || targetId;
426
437
  return isOff ? `已禁止用户 ${targetNick} 对你ccb。` : `已允许用户 ${targetNick} 对你ccb。`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ccb-plus",
3
3
  "description": "Koishi 插件,与群友发生 ccb 行为。(移植自 astrbot_plugin_ccb_plus )",
4
- "version": "0.2.10",
4
+ "version": "0.2.11",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [