koishi-plugin-ccb-plus 1.0.1 → 1.0.4
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 +1 -0
- package/lib/index.js +44 -18
- package/package.json +1 -1
- package/readme.md +65 -4
package/lib/config.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -56,7 +56,11 @@ 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
|
+
resetAllUsers: import_koishi.Schema.union([
|
|
61
|
+
import_koishi.Schema.const("on").description("重置为开放模式"),
|
|
62
|
+
import_koishi.Schema.const("off").description("重置为保护模式")
|
|
63
|
+
]).description("一键重置所有用户的全局状态(针对性设置不变)").role("radio")
|
|
60
64
|
});
|
|
61
65
|
|
|
62
66
|
// src/model.ts
|
|
@@ -358,7 +362,7 @@ __name(updateCCBRecord, "updateCCBRecord");
|
|
|
358
362
|
|
|
359
363
|
// src/commands/ccb.ts
|
|
360
364
|
function applyCcbCommand(ctx, config, state) {
|
|
361
|
-
ctx.command("ccb [target:user]", "给群友注入生命因子").option("off", "--off [user:string]
|
|
365
|
+
ctx.command("ccb [target:user]", "给群友注入生命因子").option("off", "--off [user:string] 开启保护模式(禁止被ccb),可指定用户").option("on", "--on [user:string] 关闭保护模式(允许被ccb),默认所有用户处于保护状态").action(async ({ session, options }, target) => {
|
|
362
366
|
const checkResult = state.checkGroupCommand(session);
|
|
363
367
|
if (checkResult) return checkResult;
|
|
364
368
|
const senderId = session.userId;
|
|
@@ -423,11 +427,11 @@ function applyCcbCommand(ctx, config, state) {
|
|
|
423
427
|
return newOptOut ? "已开启全局保护模式,阻止你被ccb。" : "已关闭全局保护模式,允许你被ccb。";
|
|
424
428
|
} else {
|
|
425
429
|
const targetId = targetUserStr;
|
|
426
|
-
const
|
|
427
|
-
|
|
430
|
+
const overrides2 = { ...userSetting?.overrides || {} };
|
|
431
|
+
overrides2[targetId] = !isOff;
|
|
428
432
|
await ctx.database.upsert("ccb_setting", [{
|
|
429
433
|
userId: senderId,
|
|
430
|
-
overrides,
|
|
434
|
+
overrides: overrides2,
|
|
431
435
|
optOut: userSetting?.optOut ?? false,
|
|
432
436
|
lastToggleTime: userSetting?.lastToggleTime || 0,
|
|
433
437
|
// 不改变全局旧字段
|
|
@@ -438,8 +442,11 @@ function applyCcbCommand(ctx, config, state) {
|
|
|
438
442
|
}
|
|
439
443
|
}
|
|
440
444
|
const [senderSetting] = await ctx.database.get("ccb_setting", { userId: senderId });
|
|
441
|
-
|
|
442
|
-
|
|
445
|
+
const senderOptOut = senderSetting?.optOut ?? true;
|
|
446
|
+
const senderIsInitial = !senderSetting;
|
|
447
|
+
if (senderOptOut) {
|
|
448
|
+
const message2 = senderIsInitial ? "你还未开启ccb功能。请先使用 ccb --on 来开启。" : "你已开启保护模式,无法ccb他人。请先使用 ccb --on 解除保护。";
|
|
449
|
+
return message2;
|
|
443
450
|
}
|
|
444
451
|
const actorId = senderId;
|
|
445
452
|
const now = Date.now() / 1e3;
|
|
@@ -475,23 +482,24 @@ function applyCcbCommand(ctx, config, state) {
|
|
|
475
482
|
}
|
|
476
483
|
if (config.whiteList.includes(targetUserId)) {
|
|
477
484
|
const nickname = await state.getUserNickname(session, targetUserId) || targetUserId;
|
|
478
|
-
return `${nickname}
|
|
485
|
+
return `${nickname} 已开启保护模式,拒绝了和你ccb。`;
|
|
479
486
|
}
|
|
480
487
|
if (senderSetting?.overrides?.[targetUserId] === false) {
|
|
481
488
|
const nickname = await state.getUserNickname(session, targetUserId) || targetUserId;
|
|
482
489
|
return `你已禁止与 ${nickname} 进行ccb。`;
|
|
483
490
|
}
|
|
484
491
|
const [targetSetting] = await ctx.database.get("ccb_setting", { userId: targetUserId });
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
492
|
+
const targetOptOut = targetSetting?.optOut ?? true;
|
|
493
|
+
const overrides = targetSetting?.overrides || {};
|
|
494
|
+
const isInitialState = !targetSetting;
|
|
495
|
+
if (overrides[actorId] === false) {
|
|
496
|
+
const nickname = await state.getUserNickname(session, targetUserId) || targetUserId;
|
|
497
|
+
return `${nickname} 已开启针对你的保护,拒绝了和你ccb。`;
|
|
498
|
+
}
|
|
499
|
+
if (overrides[actorId] !== true && targetOptOut) {
|
|
500
|
+
const nickname = await state.getUserNickname(session, targetUserId) || targetUserId;
|
|
501
|
+
const message2 = isInitialState ? `${nickname} 还未开启ccb功能。请让ta使用 ccb --on 来开启。` : `${nickname} 已开启保护模式,拒绝了和你ccb。请让ta使用 ccb --on 来允许被ccb。`;
|
|
502
|
+
return message2;
|
|
495
503
|
}
|
|
496
504
|
if (targetUserId === actorId && !config.selfCcb) {
|
|
497
505
|
return "怎么还能对自己下手啊(恼)";
|
|
@@ -730,6 +738,24 @@ function apply(ctx, config) {
|
|
|
730
738
|
applyDatabase(ctx);
|
|
731
739
|
const state = new CcbState(ctx);
|
|
732
740
|
applyCommands(ctx, config, state);
|
|
741
|
+
ctx.on("ready", async () => {
|
|
742
|
+
if (config.resetAllUsers) {
|
|
743
|
+
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);
|
|
755
|
+
}
|
|
756
|
+
ctx.logger.info(`已将 ${updates.length} 个用户的全局状态重置为${mode === "off" ? "保护" : "开放"}模式`);
|
|
757
|
+
}
|
|
758
|
+
});
|
|
733
759
|
}
|
|
734
760
|
__name(apply, "apply");
|
|
735
761
|
// Annotate the CommonJS export names for ESM import in node:
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -2,10 +2,71 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/koishi-plugin-ccb-plus)
|
|
4
4
|
|
|
5
|
-
Koishi插件,与群友发生ccb
|
|
5
|
+
Koishi 插件,与群友发生 ccb 行为。移植自 [astrbot_plugin_ccb_plus](https://github.com/Koikokokokoro/astrbot_plugin_ccb_plus)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## 功能特性
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- 🎲 随机生成 ccb 时长和注入量
|
|
10
|
+
- 💥 暴击机制
|
|
11
|
+
- 🛡️ 保护模式(默认开启,需手动关闭)
|
|
12
|
+
- 👥 支持全局/针对性开关
|
|
13
|
+
- 📊 排行榜和个人数据查询
|
|
14
|
+
- 💾 数据库持久化存储
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install koishi-plugin-ccb-plus
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 使用说明
|
|
23
|
+
|
|
24
|
+
### 基础命令
|
|
25
|
+
|
|
26
|
+
- `ccb [@用户]` - 对指定用户进行 ccb(需要双方都关闭保护模式)
|
|
27
|
+
- `ccb.rank` - 查看群内 ccb 排行榜
|
|
28
|
+
- `ccb.info [@用户]` - 查看指定用户的 ccb 数据
|
|
29
|
+
- `ccb.charm` - 查看自己的魅力值
|
|
30
|
+
|
|
31
|
+
### 保护模式
|
|
32
|
+
|
|
33
|
+
**默认所有用户处于保护模式,需要手动关闭才能参与。**
|
|
34
|
+
|
|
35
|
+
#### 全局开关
|
|
36
|
+
- `ccb --on` - 关闭保护模式,允许所有人对你 ccb
|
|
37
|
+
- `ccb --off` - 开启保护模式,禁止所有人对你 ccb
|
|
38
|
+
|
|
39
|
+
#### 针对性开关(优先级更高)
|
|
40
|
+
- `ccb --on @用户` - 允许指定用户对你 ccb
|
|
41
|
+
- `ccb --off @用户` - 禁止指定用户对你 ccb
|
|
42
|
+
|
|
43
|
+
**注意:** 处于保护模式的用户无法 ccb 他人,需先使用 `ccb --on` 解除。
|
|
44
|
+
|
|
45
|
+
### 管理功能
|
|
46
|
+
|
|
47
|
+
管理员可以在插件配置界面使用"重置所有用户状态"功能:
|
|
48
|
+
- 选择"重置为开放模式" - 一键将所有用户的全局状态设为开放
|
|
49
|
+
- 选择"重置为保护模式" - 一键将所有用户的全局状态设为保护
|
|
50
|
+
|
|
51
|
+
**说明:** 重置功能只影响全局状态,用户的针对性设置不受影响。
|
|
52
|
+
|
|
53
|
+
## 配置项
|
|
54
|
+
|
|
55
|
+
| 配置项 | 类型 | 默认值 | 说明 |
|
|
56
|
+
|--------|------|--------|------|
|
|
57
|
+
| `selfCcb` | boolean | false | 是否允许自己 ccb 自己 |
|
|
58
|
+
| `critProb` | number | 0.1 | 暴击概率 (0-1) |
|
|
59
|
+
| `ywWindow` | number | 60 | 阳痿检测时间窗口(秒)|
|
|
60
|
+
| `ywThreshold` | number | 5 | 阳痿检测次数阈值 |
|
|
61
|
+
| `ywBanDuration` | number | 300 | 阳痿惩罚时长(秒)|
|
|
62
|
+
| `ywProbability` | number | 0.05 | 炸膛概率 (0-1) |
|
|
63
|
+
| `toggleCooldown` | number | 10 | 开关冷却时间(秒)|
|
|
64
|
+
| `whiteList` | string[] | [] | 永久保护名单(用户ID)|
|
|
65
|
+
|
|
66
|
+
## 许可证
|
|
67
|
+
|
|
68
|
+
MIT
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
> 使用 Claude Opus 4.6 协助开发
|