koishi-plugin-ccb-plus 1.0.0-alpha.0 → 1.0.1

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/lib/index.js CHANGED
@@ -77,8 +77,9 @@ function applyDatabase(ctx) {
77
77
  ctx.model.extend("ccb_setting", {
78
78
  userId: "string",
79
79
  optOut: "boolean",
80
- lastToggleTime: "unsigned",
81
- overrides: "json"
80
+ lastToggleTime: "double",
81
+ overrides: "json",
82
+ lastToggleTimes: "json"
82
83
  }, {
83
84
  primary: "userId"
84
85
  });
@@ -224,8 +225,14 @@ var CcbState = class _CcbState {
224
225
  return String(atEl.attrs.id);
225
226
  }
226
227
  } catch (e) {
227
- const atMatch = input.match(/<at\s+(?:.*?\s+)?id=(["'])(.*?)\1/i);
228
- if (atMatch) return atMatch[2];
228
+ }
229
+ const atMatch = input.match(/<at\s+[^<]*?id=(["'])(.*?)\1/i);
230
+ if (atMatch) return atMatch[2];
231
+ if (/<at\b/i.test(input)) {
232
+ const atEl = session.elements?.find((el) => el.type === "at");
233
+ if (atEl?.attrs?.id) {
234
+ return String(atEl.attrs.id);
235
+ }
229
236
  }
230
237
  const colonIndex = input.indexOf(":");
231
238
  if (colonIndex > 0 && colonIndex < input.length - 1) {
@@ -393,28 +400,38 @@ function applyCcbCommand(ctx, config, state) {
393
400
  }
394
401
  }
395
402
  const [userSetting] = await ctx.database.get("ccb_setting", { userId: senderId });
396
- 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
+ }
397
409
  const cooldownResult = checkCooldown(lastToggle);
398
410
  if (cooldownResult) return cooldownResult;
399
411
  const nowMs = Date.now();
412
+ lastToggleTimes[targetKey] = nowMs;
400
413
  if (!targetUserStr) {
401
414
  const newOptOut = !!isOff;
402
415
  await ctx.database.upsert("ccb_setting", [{
403
416
  userId: senderId,
404
417
  optOut: newOptOut,
405
418
  lastToggleTime: nowMs,
406
- overrides: userSetting?.overrides || {}
419
+ // 保持更新以供兼容
420
+ lastToggleTimes,
421
+ overrides: { ...userSetting?.overrides || {} }
407
422
  }]);
408
423
  return newOptOut ? "已开启全局保护模式,阻止你被ccb。" : "已关闭全局保护模式,允许你被ccb。";
409
424
  } else {
410
425
  const targetId = targetUserStr;
411
- const overrides = userSetting?.overrides || {};
426
+ const overrides = { ...userSetting?.overrides || {} };
412
427
  overrides[targetId] = !isOff;
413
428
  await ctx.database.upsert("ccb_setting", [{
414
429
  userId: senderId,
415
430
  overrides,
416
431
  optOut: userSetting?.optOut ?? false,
417
- lastToggleTime: nowMs
432
+ lastToggleTime: userSetting?.lastToggleTime || 0,
433
+ // 不改变全局旧字段
434
+ lastToggleTimes
418
435
  }]);
419
436
  const targetNick = await state.getUserNickname(session, targetId).catch(() => targetId) || targetId;
420
437
  return isOff ? `已禁止用户 ${targetNick} 对你ccb。` : `已允许用户 ${targetNick} 对你ccb。`;
package/lib/model.d.ts CHANGED
@@ -18,6 +18,7 @@ export interface CCBUserSetting {
18
18
  optOut: boolean;
19
19
  lastToggleTime: number;
20
20
  overrides: Record<string, boolean>;
21
+ lastToggleTimes?: Record<string, number>;
21
22
  }
22
23
  declare module 'koishi' {
23
24
  interface Tables {
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": "1.0.0-alpha.0",
4
+ "version": "1.0.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -18,6 +18,6 @@
18
18
  "group"
19
19
  ],
20
20
  "peerDependencies": {
21
- "koishi": "^4.18.7"
21
+ "koishi": "^4.18.10"
22
22
  }
23
23
  }