koishi-plugin-ccb-plus 1.0.3 → 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 +2 -0
- package/lib/index.js +39 -4
- package/package.json +1 -1
- package/readme.md +8 -0
package/lib/config.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -56,7 +56,14 @@ var Config = import_koishi.Schema.object({
|
|
|
56
56
|
ywProbability: import_koishi.Schema.number().default(0).min(0).max(1).description("特权冷却概率"),
|
|
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
|
-
})).role("table").description("开挂名单(优先级高于全局设置)")
|
|
59
|
+
})).role("table").description("开挂名单(优先级高于全局设置)"),
|
|
60
|
+
defaultOptOut: import_koishi.Schema.boolean().default(true).description("新用户默认状态(true=保护模式,false=开放模式)"),
|
|
61
|
+
resetAllUsers: import_koishi.Schema.union([
|
|
62
|
+
import_koishi.Schema.const("none").description("无操作"),
|
|
63
|
+
import_koishi.Schema.const("on").description("重置为开放模式"),
|
|
64
|
+
import_koishi.Schema.const("off").description("重置为保护模式"),
|
|
65
|
+
import_koishi.Schema.const("clear").description("清空所有设置(恢复初始状态)")
|
|
66
|
+
]).default("none").description('批量管理用户状态(操作完成后请改回"无操作")').role("radio")
|
|
60
67
|
});
|
|
61
68
|
|
|
62
69
|
// src/model.ts
|
|
@@ -438,9 +445,11 @@ function applyCcbCommand(ctx, config, state) {
|
|
|
438
445
|
}
|
|
439
446
|
}
|
|
440
447
|
const [senderSetting] = await ctx.database.get("ccb_setting", { userId: senderId });
|
|
441
|
-
const senderOptOut = senderSetting?.optOut ??
|
|
448
|
+
const senderOptOut = senderSetting?.optOut ?? config.defaultOptOut;
|
|
449
|
+
const senderIsInitial = !senderSetting;
|
|
442
450
|
if (senderOptOut) {
|
|
443
|
-
|
|
451
|
+
const message2 = senderIsInitial ? "你还未开启ccb功能。请先使用 ccb --on 来开启。" : "你已开启保护模式,无法ccb他人。请先使用 ccb --on 解除保护。";
|
|
452
|
+
return message2;
|
|
444
453
|
}
|
|
445
454
|
const actorId = senderId;
|
|
446
455
|
const now = Date.now() / 1e3;
|
|
@@ -483,7 +492,7 @@ function applyCcbCommand(ctx, config, state) {
|
|
|
483
492
|
return `你已禁止与 ${nickname} 进行ccb。`;
|
|
484
493
|
}
|
|
485
494
|
const [targetSetting] = await ctx.database.get("ccb_setting", { userId: targetUserId });
|
|
486
|
-
const targetOptOut = targetSetting?.optOut ??
|
|
495
|
+
const targetOptOut = targetSetting?.optOut ?? config.defaultOptOut;
|
|
487
496
|
const overrides = targetSetting?.overrides || {};
|
|
488
497
|
const isInitialState = !targetSetting;
|
|
489
498
|
if (overrides[actorId] === false) {
|
|
@@ -732,6 +741,32 @@ function apply(ctx, config) {
|
|
|
732
741
|
applyDatabase(ctx);
|
|
733
742
|
const state = new CcbState(ctx);
|
|
734
743
|
applyCommands(ctx, config, state);
|
|
744
|
+
ctx.on("ready", async () => {
|
|
745
|
+
if (config.resetAllUsers && config.resetAllUsers !== "none") {
|
|
746
|
+
const mode = config.resetAllUsers;
|
|
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
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
});
|
|
735
770
|
}
|
|
736
771
|
__name(apply, "apply");
|
|
737
772
|
// Annotate the CommonJS export names for ESM import in node:
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -42,6 +42,14 @@ npm install koishi-plugin-ccb-plus
|
|
|
42
42
|
|
|
43
43
|
**注意:** 处于保护模式的用户无法 ccb 他人,需先使用 `ccb --on` 解除。
|
|
44
44
|
|
|
45
|
+
### 管理功能
|
|
46
|
+
|
|
47
|
+
管理员可以在插件配置界面使用"重置所有用户状态"功能:
|
|
48
|
+
- 选择"重置为开放模式" - 一键将所有用户的全局状态设为开放
|
|
49
|
+
- 选择"重置为保护模式" - 一键将所有用户的全局状态设为保护
|
|
50
|
+
|
|
51
|
+
**说明:** 重置功能只影响全局状态,用户的针对性设置不受影响。
|
|
52
|
+
|
|
45
53
|
## 配置项
|
|
46
54
|
|
|
47
55
|
| 配置项 | 类型 | 默认值 | 说明 |
|