koishi-plugin-echo-cave 1.6.5 → 1.7.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/README.md +2 -0
- package/lib/index.cjs +21 -9
- package/lib/index.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
- 👤 **个人追踪**:支持查看自己投稿的消息列表
|
|
19
19
|
- 🔍 **发言回溯**:支持查看自己被他人投稿的消息列表
|
|
20
20
|
- 🎨 **精美展示**:消息展示时自带多种风格的外部包裹信息,显示消息详情
|
|
21
|
+
- 🔒 **管理员保护**:可配置管理员消息保护,确保管理员发布的消息安全
|
|
21
22
|
|
|
22
23
|
## 📋 命令列表
|
|
23
24
|
|
|
@@ -76,6 +77,7 @@ src/
|
|
|
76
77
|
- 存储的转发消息会保留原始发送者信息
|
|
77
78
|
- 消息展示时会自动添加精美的外部包裹信息,包括消息 ID、创建时间、原始发送者和投递者信息
|
|
78
79
|
- 外部包裹信息有多种随机风格,为每次消息展示带来不同的视觉体验
|
|
80
|
+
- 可通过配置开启管理员消息保护,使管理员发布的消息只能由其他管理员删除
|
|
79
81
|
|
|
80
82
|
## 🤝 贡献指南
|
|
81
83
|
|
package/lib/index.cjs
CHANGED
|
@@ -237,8 +237,12 @@ function formatDate(date) {
|
|
|
237
237
|
// src/index.ts
|
|
238
238
|
var name = "echo-cave";
|
|
239
239
|
var inject = ["database"];
|
|
240
|
-
var Config = import_koishi.Schema.object({
|
|
241
|
-
|
|
240
|
+
var Config = import_koishi.Schema.object({
|
|
241
|
+
adminMessageProtection: import_koishi.Schema.boolean().description(
|
|
242
|
+
"\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"
|
|
243
|
+
).default(false)
|
|
244
|
+
});
|
|
245
|
+
function apply(ctx, cfg) {
|
|
242
246
|
const imgPath = import_node_path2.default.join(ctx.baseDir, "data", "cave", "images");
|
|
243
247
|
if (!import_fs.default.existsSync(imgPath)) {
|
|
244
248
|
import_fs.default.mkdirSync(imgPath, { recursive: true });
|
|
@@ -268,7 +272,7 @@ function apply(ctx) {
|
|
|
268
272
|
async ({ session }) => await addCave(ctx, session)
|
|
269
273
|
);
|
|
270
274
|
ctx.command("cave.wipe <id:number>", "\u62B9\u53BB\u7279\u5B9A id \u7684\u56DE\u58F0\u6D1E\u4FE1\u606F").action(
|
|
271
|
-
async ({ session }, id) => await deleteCave(ctx, session, id)
|
|
275
|
+
async ({ session }, id) => await deleteCave(ctx, session, cfg, id)
|
|
272
276
|
);
|
|
273
277
|
ctx.command("cave.listen", "\u83B7\u5F97\u7531\u81EA\u5DF1\u6295\u7A3F\u7684\u56DE\u58F0\u6D1E\u5217\u8868").action(
|
|
274
278
|
async ({ session }) => await getCaveListByUser(ctx, session)
|
|
@@ -343,7 +347,7 @@ async function getCave(ctx, session, id) {
|
|
|
343
347
|
}
|
|
344
348
|
await sendCaveMsg(ctx, session, caveMsg);
|
|
345
349
|
}
|
|
346
|
-
async function deleteCave(ctx, session, id) {
|
|
350
|
+
async function deleteCave(ctx, session, cfg, id) {
|
|
347
351
|
if (!session.guildId) {
|
|
348
352
|
return "\u274C \u8BF7\u5728\u7FA4\u804A\u4E2D\u4F7F\u7528\u8BE5\u547D\u4EE4\uFF01";
|
|
349
353
|
}
|
|
@@ -358,7 +362,18 @@ async function deleteCave(ctx, session, id) {
|
|
|
358
362
|
const currentUserId = session.userId;
|
|
359
363
|
const user = await ctx.database.getUser(session.platform, currentUserId);
|
|
360
364
|
const userAuthority = user.authority;
|
|
361
|
-
|
|
365
|
+
const isCurrentUserAdmin = userAuthority >= 4;
|
|
366
|
+
if (cfg.adminMessageProtection) {
|
|
367
|
+
const caveUser = await ctx.database.getUser(
|
|
368
|
+
session.platform,
|
|
369
|
+
caveMsg.userId
|
|
370
|
+
);
|
|
371
|
+
const isCaveUserAdmin = caveUser.authority >= 4;
|
|
372
|
+
if (isCaveUserAdmin && !isCurrentUserAdmin) {
|
|
373
|
+
return "\u26D4 \u8BE5\u6D88\u606F\u7531\u7BA1\u7406\u5458\u53D1\u5E03\uFF0C\u5DF2\u5F00\u542F\u7BA1\u7406\u5458\u6D88\u606F\u4FDD\u62A4\uFF0C\u53EA\u6709\u7BA1\u7406\u5458\u53EF\u4EE5\u5220\u9664\u3002";
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (currentUserId !== caveMsg.userId && currentUserId !== caveMsg.originUserId && !isCurrentUserAdmin) {
|
|
362
377
|
return "\u26D4 \u60A8\u6CA1\u6709\u6743\u9650\u5220\u9664\u6B64\u6D88\u606F\uFF01\u53EA\u6709\u6D88\u606F\u7684\u5B58\u50A8\u8005\u3001\u539F\u59CB\u53D1\u9001\u8005\u6216\u7BA1\u7406\u5458\u53EF\u4EE5\u5220\u9664\u3002";
|
|
363
378
|
}
|
|
364
379
|
await ctx.database.remove("echo_cave", id);
|
|
@@ -402,10 +417,7 @@ async function addCave(ctx, session) {
|
|
|
402
417
|
type,
|
|
403
418
|
content
|
|
404
419
|
});
|
|
405
|
-
|
|
406
|
-
session.channelId,
|
|
407
|
-
`\u2705 \u56DE\u58F0\u6D1E\u6D88\u606F\u5DF2\u6210\u529F\u5B58\u5165\uFF0C\u6D88\u606F ID\uFF1A${result.id}`
|
|
408
|
-
);
|
|
420
|
+
return `\u2705 \u56DE\u58F0\u6D1E\u6D88\u606F\u5DF2\u6210\u529F\u5B58\u5165\uFF0C\u6D88\u606F ID\uFF1A${result.id}`;
|
|
409
421
|
} catch (error) {
|
|
410
422
|
return "\u274C \u56DE\u58F0\u6D1E\u4FDD\u5B58\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF01";
|
|
411
423
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Context, Schema } from 'koishi';
|
|
|
3
3
|
export declare const name = "echo-cave";
|
|
4
4
|
export declare const inject: string[];
|
|
5
5
|
export interface Config {
|
|
6
|
+
adminMessageProtection?: boolean;
|
|
6
7
|
}
|
|
7
8
|
export declare const Config: Schema<Config>;
|
|
8
9
|
export interface EchoCave {
|
|
@@ -19,4 +20,4 @@ declare module 'koishi' {
|
|
|
19
20
|
echo_cave: EchoCave;
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
|
-
export declare function apply(ctx: Context): void;
|
|
23
|
+
export declare function apply(ctx: Context, cfg: Config): void;
|