koishi-plugin-echo-cave 1.3.0 → 1.3.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 pynickle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,73 @@
1
- # koishi-plugin-cave
1
+ # 📣 koishi-plugin-echo-cave
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/koishi-plugin-echo-cave?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-echo-cave)
4
+ [![downloads](https://img.shields.io/npm/dm/koishi-plugin-echo-cave?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-echo-cave)
5
+ [![license](https://img.shields.io/github/license/pynickle/koishi-plugin-echo-cave?style=flat-square)](LICENSE)
4
6
 
5
- Group echo cave
7
+ ## 🌌 插件简介
8
+
9
+ **koishi-plugin-echo-cave** 是一个为 Koishi 机器人框架设计的群聊消息存储与回溯插件。它能够将群聊中的消息(包括普通消息和转发消息)存储到"回声洞"中,并支持随时随机或指定 ID 调取这些消息,为群聊增添更多互动乐趣和记录功能。
10
+
11
+ ## ✨ 功能特性
12
+
13
+ - 📥 **消息存储**:支持存储普通消息和转发消息到数据库
14
+ - 🖼️ **图片保存**:自动保存消息中的图片资源到本地
15
+ - 🔍 **消息查询**:支持随机获取消息或通过 ID 精确查找
16
+ - 🗑️ **消息管理**:支持删除特定 ID 的消息(需要管理员权限)
17
+ - 📊 **数据持久化**:使用 Koishi 数据库系统,确保数据不会丢失
18
+
19
+ ## 📋 命令列表
20
+
21
+ | 命令 | 说明 | 权限要求 |
22
+ |------------------|----------------|-----------------|
23
+ | `cave` | 随机获取一条回声洞消息 | 所有人 |
24
+ | `cave <id>` | 获取特定 ID 的回声洞消息 | 所有人 |
25
+ | `cave.echo` | 将引用的消息存入回声洞 | 所有人 |
26
+ | `cave.wipe <id>` | 删除特定 ID 的回声洞消息 | 消息存储者、原始发送者或管理员 |
27
+
28
+ ## 🚀 使用指南
29
+
30
+ ### 1. 安装插件
31
+
32
+ ```bash
33
+ npm install koishi-plugin-echo-cave
34
+ ```
35
+
36
+ ### 2. 基本使用
37
+
38
+ 1. **存储消息**:在群聊中引用一条消息,然后发送命令 `cave.echo`
39
+ 2. **查看随机消息**:发送命令 `cave` 获取一条随机消息
40
+ 3. **查看特定消息**:发送命令 `cave <id>` 查看指定 ID 的消息
41
+ 4. **删除消息**:管理员发送命令 `cave.wipe <id>` 删除指定 ID 的消息
42
+
43
+ ## 📁 文件结构
44
+
45
+ ```
46
+ src/
47
+ ├── index.ts # 插件主入口,命令注册和核心功能
48
+ ├── forward-helper.ts # 转发消息处理辅助函数
49
+ ├── image-helper.ts # 图片保存辅助函数
50
+ └── msg-helper.ts # 消息发送辅助函数
51
+ ```
52
+
53
+ ## 🔧 技术说明
54
+
55
+ - 插件使用 Koishi 数据库系统存储消息记录
56
+ - 图片会保存在 `data/cave/images` 目录下
57
+ - 支持嵌套转发消息的处理
58
+ - 自动检测重复消息,避免存储重复内容
59
+
60
+ ## 📝 注意事项
61
+
62
+ - 插件只能在群聊中使用,私聊模式下无法正常工作
63
+ - 使用 `cave.echo` 命令前必须先引用一条消息
64
+ - 删除消息需要消息存储者、原始发送者或管理员权限(权限等级 4)
65
+ - 存储的转发消息会保留原始发送者信息
66
+
67
+ ## 🤝 贡献指南
68
+
69
+ 欢迎提交 Issue 或 Pull Request 来帮助改进这个插件!
70
+
71
+ ## 📄 许可证
72
+
73
+ 本项目采用 MIT 许可证 - 详情请查看 [LICENSE](LICENSE) 文件
package/lib/index.cjs CHANGED
@@ -146,12 +146,12 @@ function apply(ctx) {
146
146
  "cave [id:number]",
147
147
  "\u968F\u673A\u83B7\u53D6 / \u83B7\u53D6\u7279\u5B9A id \u7684\u56DE\u58F0\u6D1E\u4FE1\u606F"
148
148
  ).action(async ({ session }, id) => await getCave(ctx, session, id));
149
- ctx.command("cave.echo", "\u5C06\u6D88\u606F\u5B58\u5165\u56DE\u58F0\u6D1E\u7A74").action(
149
+ ctx.command("cave echo", "\u5C06\u6D88\u606F\u5B58\u5165\u56DE\u58F0\u6D1E\u7A74").action(
150
150
  async ({ session }) => await addCave(ctx, session)
151
151
  );
152
- ctx.command("cave.wipe <id:number>", "\u62B9\u53BB\u7279\u5B9A id \u7684\u56DE\u58F0\u6D1E\u4FE1\u606F", {
153
- authority: 4
154
- }).action(async ({ session }, id) => await deleteCave(ctx, session, id));
152
+ ctx.command("cave wipe <id:number>", "\u62B9\u53BB\u7279\u5B9A id \u7684\u56DE\u58F0\u6D1E\u4FE1\u606F").action(
153
+ async ({ session }, id) => await deleteCave(ctx, session, id)
154
+ );
155
155
  }
156
156
  async function getCave(ctx, session, id) {
157
157
  if (!session.guildId) {
@@ -184,6 +184,11 @@ async function deleteCave(ctx, session, id) {
184
184
  if (caves.length === 0) {
185
185
  return "\u{1F50D} \u672A\u627E\u5230\u8BE5 ID \u7684\u56DE\u58F0\u6D1E\u6D88\u606F";
186
186
  }
187
+ const caveMsg = caves[0];
188
+ const currentUserId = session.userId;
189
+ if (currentUserId !== caveMsg.userId && currentUserId !== caveMsg.originUserId && (await session.getUser(currentUserId)).authority < 4) {
190
+ 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";
191
+ }
187
192
  await ctx.database.remove("echo_cave", id);
188
193
  return `\u2705 \u5DF2\u6210\u529F\u62B9\u53BB\u56DE\u58F0\u6D1E\u6D88\u606F ID\uFF1A${id}`;
189
194
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-echo-cave",
3
3
  "description": "Group echo cave",
4
- "version": "1.3.0",
4
+ "version": "1.3.2",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",