koishi-plugin-ccb-plus 1.0.4 → 1.0.6
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 -1
- package/lib/index.js +45 -21
- package/package.json +1 -1
- package/readme.md +16 -12
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
|
-
|
|
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
|
-
|
|
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
|
|
@@ -386,10 +389,23 @@ function applyCcbCommand(ctx, config, state) {
|
|
|
386
389
|
if (typeof optionVal === "string" && optionVal.trim()) {
|
|
387
390
|
targetUserStr = await state.findTargetUser(session, optionVal.trim());
|
|
388
391
|
}
|
|
389
|
-
if (!targetUserStr) {
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
392
|
+
if (!targetUserStr && session.elements) {
|
|
393
|
+
const optionFlag = isOff ? "--off" : "--on";
|
|
394
|
+
const els = session.elements;
|
|
395
|
+
for (let i = 0; i < els.length; i++) {
|
|
396
|
+
if (els[i].type === "text" && els[i].attrs?.content?.includes(optionFlag)) {
|
|
397
|
+
const textAfterFlag = els[i].attrs.content.split(optionFlag).pop() || "";
|
|
398
|
+
if (!textAfterFlag.trim() && i + 1 < els.length) {
|
|
399
|
+
for (let j = i + 1; j < els.length; j++) {
|
|
400
|
+
if (els[j].type === "at" && els[j].attrs?.id) {
|
|
401
|
+
targetUserStr = String(els[j].attrs.id);
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
if (els[j].type === "text" && els[j].attrs?.content?.trim()) break;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
393
409
|
}
|
|
394
410
|
}
|
|
395
411
|
if (!targetUserStr && typeof optionVal === "string" && optionVal.trim()) {
|
|
@@ -442,7 +458,7 @@ function applyCcbCommand(ctx, config, state) {
|
|
|
442
458
|
}
|
|
443
459
|
}
|
|
444
460
|
const [senderSetting] = await ctx.database.get("ccb_setting", { userId: senderId });
|
|
445
|
-
const senderOptOut = senderSetting?.optOut ??
|
|
461
|
+
const senderOptOut = senderSetting?.optOut ?? config.defaultOptOut;
|
|
446
462
|
const senderIsInitial = !senderSetting;
|
|
447
463
|
if (senderOptOut) {
|
|
448
464
|
const message2 = senderIsInitial ? "你还未开启ccb功能。请先使用 ccb --on 来开启。" : "你已开启保护模式,无法ccb他人。请先使用 ccb --on 解除保护。";
|
|
@@ -489,7 +505,7 @@ function applyCcbCommand(ctx, config, state) {
|
|
|
489
505
|
return `你已禁止与 ${nickname} 进行ccb。`;
|
|
490
506
|
}
|
|
491
507
|
const [targetSetting] = await ctx.database.get("ccb_setting", { userId: targetUserId });
|
|
492
|
-
const targetOptOut = targetSetting?.optOut ??
|
|
508
|
+
const targetOptOut = targetSetting?.optOut ?? config.defaultOptOut;
|
|
493
509
|
const overrides = targetSetting?.overrides || {};
|
|
494
510
|
const isInitialState = !targetSetting;
|
|
495
511
|
if (overrides[actorId] === false) {
|
|
@@ -739,21 +755,29 @@ function apply(ctx, config) {
|
|
|
739
755
|
const state = new CcbState(ctx);
|
|
740
756
|
applyCommands(ctx, config, state);
|
|
741
757
|
ctx.on("ready", async () => {
|
|
742
|
-
if (config.resetAllUsers) {
|
|
758
|
+
if (config.resetAllUsers && config.resetAllUsers !== "none") {
|
|
743
759
|
const mode = config.resetAllUsers;
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
760
|
+
if (mode === "clear") {
|
|
761
|
+
const allSettings = await ctx.database.get("ccb_setting", {});
|
|
762
|
+
if (allSettings.length > 0) {
|
|
763
|
+
await ctx.database.remove("ccb_setting", {});
|
|
764
|
+
ctx.logger.info(`已清空 ${allSettings.length} 个用户的所有设置`);
|
|
765
|
+
}
|
|
766
|
+
} else {
|
|
767
|
+
const newOptOut = mode === "off";
|
|
768
|
+
const allSettings = await ctx.database.get("ccb_setting", {});
|
|
769
|
+
const updates = allSettings.map((setting) => ({
|
|
770
|
+
userId: setting.userId,
|
|
771
|
+
optOut: newOptOut,
|
|
772
|
+
overrides: setting.overrides,
|
|
773
|
+
lastToggleTime: setting.lastToggleTime,
|
|
774
|
+
lastToggleTimes: setting.lastToggleTimes
|
|
775
|
+
}));
|
|
776
|
+
if (updates.length > 0) {
|
|
777
|
+
await ctx.database.upsert("ccb_setting", updates);
|
|
778
|
+
ctx.logger.info(`已将 ${updates.length} 个用户的全局状态重置为${mode === "off" ? "保护" : "开放"}模式`);
|
|
779
|
+
}
|
|
755
780
|
}
|
|
756
|
-
ctx.logger.info(`已将 ${updates.length} 个用户的全局状态重置为${mode === "off" ? "保护" : "开放"}模式`);
|
|
757
781
|
}
|
|
758
782
|
});
|
|
759
783
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -44,11 +44,18 @@ npm install koishi-plugin-ccb-plus
|
|
|
44
44
|
|
|
45
45
|
### 管理功能
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
- 选择"重置为开放模式" - 一键将所有用户的全局状态设为开放
|
|
49
|
-
- 选择"重置为保护模式" - 一键将所有用户的全局状态设为保护
|
|
47
|
+
管理员可以在插件配置界面进行批量管理:
|
|
50
48
|
|
|
51
|
-
|
|
49
|
+
**批量操作:**
|
|
50
|
+
- 无操作 - 默认选项,操作完成后请改回此项
|
|
51
|
+
- 重置为开放模式 - 将所有用户的全局状态设为开放
|
|
52
|
+
- 重置为保护模式 - 将所有用户的全局状态设为保护
|
|
53
|
+
- 清空所有设置 - 删除所有用户的设置记录,恢复初始状态
|
|
54
|
+
|
|
55
|
+
**说明:**
|
|
56
|
+
- 重置操作只影响全局状态,用户的针对性设置不受影响
|
|
57
|
+
- 清空操作会删除所有设置,包括针对性设置
|
|
58
|
+
- 操作完成后请将选项改回"无操作",避免重复执行
|
|
52
59
|
|
|
53
60
|
## 配置项
|
|
54
61
|
|
|
@@ -56,17 +63,14 @@ npm install koishi-plugin-ccb-plus
|
|
|
56
63
|
|--------|------|--------|------|
|
|
57
64
|
| `selfCcb` | boolean | false | 是否允许自己 ccb 自己 |
|
|
58
65
|
| `critProb` | number | 0.1 | 暴击概率 (0-1) |
|
|
59
|
-
| `ywWindow` | number | 60 |
|
|
60
|
-
| `ywThreshold` | number | 5 |
|
|
61
|
-
| `ywBanDuration` | number | 300 |
|
|
66
|
+
| `ywWindow` | number | 60 | 冷却检测时间窗口(秒)|
|
|
67
|
+
| `ywThreshold` | number | 5 | 冷却检测次数阈值 |
|
|
68
|
+
| `ywBanDuration` | number | 300 | 冷却时长(秒)|
|
|
62
69
|
| `ywProbability` | number | 0.05 | 炸膛概率 (0-1) |
|
|
63
70
|
| `toggleCooldown` | number | 10 | 开关冷却时间(秒)|
|
|
64
71
|
| `whiteList` | string[] | [] | 永久保护名单(用户ID)|
|
|
65
|
-
|
|
66
|
-
## 许可证
|
|
67
|
-
|
|
68
|
-
MIT
|
|
72
|
+
| `defaultOptOut` | boolean | true | 新用户默认状态(true=保护,false=开放)|
|
|
69
73
|
|
|
70
74
|
---
|
|
71
75
|
|
|
72
|
-
> 使用 Claude Opus 4.6 协助开发
|
|
76
|
+
> 使用 Claude Opus 4.6 协助开发
|