koishi-plugin-ccb-plus 1.0.4 → 1.0.5

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/config.d.ts CHANGED
@@ -17,6 +17,7 @@ export interface CCBConfig {
17
17
  critProb: number;
18
18
  toggleCooldown: number;
19
19
  cheatList: CheatConfig[];
20
- resetAllUsers?: 'on' | 'off';
20
+ defaultOptOut: boolean;
21
+ resetAllUsers?: 'none' | 'on' | 'off' | 'clear';
21
22
  }
22
23
  export declare const Config: Schema<CCBConfig>;
package/lib/index.js CHANGED
@@ -57,10 +57,13 @@ var Config = import_koishi.Schema.object({
57
57
  critProb: import_koishi.Schema.number().default(0.8).min(0).max(1).description("特权暴击概率"),
58
58
  ywBanDuration: import_koishi.Schema.number().default(60).description("特权冷却时长(秒)")
59
59
  })).role("table").description("开挂名单(优先级高于全局设置)"),
60
+ defaultOptOut: import_koishi.Schema.boolean().default(true).description("新用户默认状态(true=保护模式,false=开放模式)"),
60
61
  resetAllUsers: import_koishi.Schema.union([
62
+ import_koishi.Schema.const("none").description("无操作"),
61
63
  import_koishi.Schema.const("on").description("重置为开放模式"),
62
- import_koishi.Schema.const("off").description("重置为保护模式")
63
- ]).description("一键重置所有用户的全局状态(针对性设置不变)").role("radio")
64
+ import_koishi.Schema.const("off").description("重置为保护模式"),
65
+ import_koishi.Schema.const("clear").description("清空所有设置(恢复初始状态)")
66
+ ]).default("none").description('批量管理用户状态(操作完成后请改回"无操作")').role("radio")
64
67
  });
65
68
 
66
69
  // src/model.ts
@@ -442,7 +445,7 @@ function applyCcbCommand(ctx, config, state) {
442
445
  }
443
446
  }
444
447
  const [senderSetting] = await ctx.database.get("ccb_setting", { userId: senderId });
445
- const senderOptOut = senderSetting?.optOut ?? true;
448
+ const senderOptOut = senderSetting?.optOut ?? config.defaultOptOut;
446
449
  const senderIsInitial = !senderSetting;
447
450
  if (senderOptOut) {
448
451
  const message2 = senderIsInitial ? "你还未开启ccb功能。请先使用 ccb --on 来开启。" : "你已开启保护模式,无法ccb他人。请先使用 ccb --on 解除保护。";
@@ -489,7 +492,7 @@ function applyCcbCommand(ctx, config, state) {
489
492
  return `你已禁止与 ${nickname} 进行ccb。`;
490
493
  }
491
494
  const [targetSetting] = await ctx.database.get("ccb_setting", { userId: targetUserId });
492
- const targetOptOut = targetSetting?.optOut ?? true;
495
+ const targetOptOut = targetSetting?.optOut ?? config.defaultOptOut;
493
496
  const overrides = targetSetting?.overrides || {};
494
497
  const isInitialState = !targetSetting;
495
498
  if (overrides[actorId] === false) {
@@ -739,21 +742,29 @@ function apply(ctx, config) {
739
742
  const state = new CcbState(ctx);
740
743
  applyCommands(ctx, config, state);
741
744
  ctx.on("ready", async () => {
742
- if (config.resetAllUsers) {
745
+ if (config.resetAllUsers && config.resetAllUsers !== "none") {
743
746
  const mode = config.resetAllUsers;
744
- const newOptOut = mode === "off";
745
- const allSettings = await ctx.database.get("ccb_setting", {});
746
- const updates = allSettings.map((setting) => ({
747
- userId: setting.userId,
748
- optOut: newOptOut,
749
- overrides: setting.overrides,
750
- lastToggleTime: setting.lastToggleTime,
751
- lastToggleTimes: setting.lastToggleTimes
752
- }));
753
- if (updates.length > 0) {
754
- await ctx.database.upsert("ccb_setting", updates);
747
+ if (mode === "clear") {
748
+ const allSettings = await ctx.database.get("ccb_setting", {});
749
+ if (allSettings.length > 0) {
750
+ await ctx.database.remove("ccb_setting", {});
751
+ ctx.logger.info(`已清空 ${allSettings.length} 个用户的所有设置`);
752
+ }
753
+ } else {
754
+ const newOptOut = mode === "off";
755
+ const allSettings = await ctx.database.get("ccb_setting", {});
756
+ const updates = allSettings.map((setting) => ({
757
+ userId: setting.userId,
758
+ optOut: newOptOut,
759
+ overrides: setting.overrides,
760
+ lastToggleTime: setting.lastToggleTime,
761
+ lastToggleTimes: setting.lastToggleTimes
762
+ }));
763
+ if (updates.length > 0) {
764
+ await ctx.database.upsert("ccb_setting", updates);
765
+ ctx.logger.info(`已将 ${updates.length} 个用户的全局状态重置为${mode === "off" ? "保护" : "开放"}模式`);
766
+ }
755
767
  }
756
- ctx.logger.info(`已将 ${updates.length} 个用户的全局状态重置为${mode === "off" ? "保护" : "开放"}模式`);
757
768
  }
758
769
  });
759
770
  }
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.4",
4
+ "version": "1.0.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [