koishi-plugin-echo-cave 1.33.0 → 1.34.0
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/config.d.ts +2 -0
- package/lib/index.cjs +25 -0
- package/package.json +1 -1
package/lib/config/config.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export type OversizedMediaCleanupMode = 'delete-cave' | 'keep-cave';
|
|
|
4
4
|
export type ForwardSpecialUserHandlingMode = 'ignore' | 'reject' | 'confirm';
|
|
5
5
|
export type S3UploadFailureFallbackMode = 'local' | 'original-link';
|
|
6
6
|
export interface Config {
|
|
7
|
+
enableChannelWhitelist?: boolean;
|
|
8
|
+
channelWhitelist?: string[];
|
|
7
9
|
adminMessageProtection?: boolean;
|
|
8
10
|
adminIds?: string[];
|
|
9
11
|
allowContributorDelete?: boolean;
|
package/lib/index.cjs
CHANGED
|
@@ -4083,6 +4083,8 @@ var zh_CN_default = {
|
|
|
4083
4083
|
|
|
4084
4084
|
// src/config/locales/zh-CN.json
|
|
4085
4085
|
var zh_CN_default2 = {
|
|
4086
|
+
enableChannelWhitelist: "\u662F\u5426\u542F\u7528\u7FA4\u804A\u767D\u540D\u5355\u6A21\u5F0F\uFF0C\u5F00\u542F\u540E\u4EC5\u5728\u767D\u540D\u5355\u4E2D\u7684\u7FA4\u804A\u53EF\u4EE5\u4F7F\u7528\u56DE\u58F0\u6D1E\u529F\u80FD\uFF1B\u5173\u95ED\u5219\u9ED8\u8BA4\u5168\u90E8\u7FA4\u804A\u5747\u53EF\u7528",
|
|
4087
|
+
channelWhitelist: "\u7FA4\u804A\u767D\u540D\u5355 (channel ID \u5217\u8868)\uFF0C\u4EC5\u5728\u542F\u7528\u767D\u540D\u5355\u6A21\u5F0F\u65F6\u751F\u6548",
|
|
4086
4088
|
adminMessageProtection: "\u5F00\u542F\u7BA1\u7406\u5458\u6D88\u606F\u4FDD\u62A4\uFF0C\u5F00\u542F\u540E\u7BA1\u7406\u5458\u53D1\u5E03\u7684\u6D88\u606F\u53EA\u80FD\u7531\u7BA1\u7406\u5458\u5220\u9664",
|
|
4087
4089
|
adminIds: "\u7BA1\u7406\u5458 ID \u5217\u8868\uFF0C\u4EC5\u8FD9\u4E9B\u7528\u6237\u53EF\u5728\u79C1\u804A\u4F7F\u7528\u7BA1\u7406\u8FC1\u79FB\u547D\u4EE4",
|
|
4088
4090
|
allowContributorDelete: "\u5141\u8BB8\u6295\u7A3F\u8005\u5220\u9664\u81EA\u5DF1\u6295\u7A3F\u7684\u56DE\u58F0\u6D1E",
|
|
@@ -4123,6 +4125,10 @@ var zh_CN_default2 = {
|
|
|
4123
4125
|
// src/config/config.ts
|
|
4124
4126
|
var import_koishi2 = require("koishi");
|
|
4125
4127
|
var Config = import_koishi2.Schema.intersect([
|
|
4128
|
+
import_koishi2.Schema.object({
|
|
4129
|
+
enableChannelWhitelist: import_koishi2.Schema.boolean().default(false),
|
|
4130
|
+
channelWhitelist: import_koishi2.Schema.array(String).role("table").default([])
|
|
4131
|
+
}).description("\u7FA4\u804A\u767D\u540D\u5355"),
|
|
4126
4132
|
import_koishi2.Schema.object({
|
|
4127
4133
|
adminMessageProtection: import_koishi2.Schema.boolean().default(false),
|
|
4128
4134
|
adminIds: import_koishi2.Schema.array(String).role("table").default([]),
|
|
@@ -4268,6 +4274,24 @@ function apply(ctx, cfg) {
|
|
|
4268
4274
|
primary: "userId"
|
|
4269
4275
|
}
|
|
4270
4276
|
);
|
|
4277
|
+
const isCaveCommandWord = (word) => word === "cave" || word.startsWith("cave.");
|
|
4278
|
+
const isChannelAllowed = (channelId) => {
|
|
4279
|
+
if (!cfg.enableChannelWhitelist) return true;
|
|
4280
|
+
if (!channelId) return true;
|
|
4281
|
+
return (cfg.channelWhitelist ?? []).includes(channelId);
|
|
4282
|
+
};
|
|
4283
|
+
ctx.middleware(async (session, next) => {
|
|
4284
|
+
if (!cfg.enableChannelWhitelist) return next();
|
|
4285
|
+
if (!session.guildId) return next();
|
|
4286
|
+
if (isChannelAllowed(session.channelId)) return next();
|
|
4287
|
+
const parsedContent = session.parsed?.content;
|
|
4288
|
+
const content = (parsedContent ?? session.content ?? "").trim();
|
|
4289
|
+
const firstWord = content.split(/\s+/)[0] ?? "";
|
|
4290
|
+
if (isCaveCommandWord(firstWord)) {
|
|
4291
|
+
return;
|
|
4292
|
+
}
|
|
4293
|
+
return next();
|
|
4294
|
+
}, true);
|
|
4271
4295
|
ctx.model.migrate("echo_cave_v2", {}, async (database) => {
|
|
4272
4296
|
const existing = await database.get(ACTIVE_CAVE_TABLE, {});
|
|
4273
4297
|
if (existing.length > 0) {
|
|
@@ -4287,6 +4311,7 @@ function apply(ctx, cfg) {
|
|
|
4287
4311
|
if (!session.guildId) return;
|
|
4288
4312
|
if (session["targetId"] !== session.selfId) return;
|
|
4289
4313
|
if (cfg.enablePokeTrigger === false) return;
|
|
4314
|
+
if (!isChannelAllowed(session.channelId)) return;
|
|
4290
4315
|
const key = `${session.channelId}:${session.userId}`;
|
|
4291
4316
|
const now = Date.now();
|
|
4292
4317
|
if (now - (pokeCooldown.get(key) ?? 0) < POKE_COOLDOWN_MS) return;
|