koishi-plugin-best-cave 2.0.0 → 2.0.1

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/index.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ import { Context, Schema } from 'koishi';
2
+ export declare const name = "best-cave";
3
+ export declare const inject: string[];
4
+ export declare const usage = "\n<div style=\"border-radius: 10px; border: 1px solid #ddd; padding: 16px; margin-bottom: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);\">\n <h2 style=\"margin-top: 0; color: #4a6ee0;\">\uD83D\uDCCC \u63D2\u4EF6\u8BF4\u660E</h2>\n <p>\uD83D\uDCD6 <strong>\u4F7F\u7528\u6587\u6863</strong>\uFF1A\u8BF7\u70B9\u51FB\u5DE6\u4E0A\u89D2\u7684 <strong>\u63D2\u4EF6\u4E3B\u9875</strong> \u67E5\u770B\u63D2\u4EF6\u4F7F\u7528\u6587\u6863</p>\n <p>\uD83D\uDD0D <strong>\u66F4\u591A\u63D2\u4EF6</strong>\uFF1A\u53EF\u8BBF\u95EE <a href=\"https://github.com/YisRime\" style=\"color:#4a6ee0;text-decoration:none;\">\u82E1\u6DDE\u7684 GitHub</a> \u67E5\u770B\u672C\u4EBA\u7684\u6240\u6709\u63D2\u4EF6</p>\n</div>\n\n<div style=\"border-radius: 10px; border: 1px solid #ddd; padding: 16px; margin-bottom: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);\">\n <h2 style=\"margin-top: 0; color: #e0574a;\">\u2764\uFE0F \u652F\u6301\u4E0E\u53CD\u9988</h2>\n <p>\uD83C\uDF1F \u559C\u6B22\u8FD9\u4E2A\u63D2\u4EF6\uFF1F\u8BF7\u5728 <a href=\"https://github.com/YisRime\" style=\"color:#e0574a;text-decoration:none;\">GitHub</a> \u4E0A\u7ED9\u6211\u4E00\u4E2A Star\uFF01</p>\n <p>\uD83D\uDC1B \u9047\u5230\u95EE\u9898\uFF1F\u8BF7\u901A\u8FC7 <strong>Issues</strong> \u63D0\u4EA4\u53CD\u9988\uFF0C\u6216\u52A0\u5165 QQ \u7FA4 <a href=\"https://qm.qq.com/q/PdLMx9Jowq\" style=\"color:#e0574a;text-decoration:none;\"><strong>855571375</strong></a> \u8FDB\u884C\u4EA4\u6D41</p>\n</div>\n";
5
+ /**
6
+ * 存储在数据库中的单个消息元素。
7
+ * @property type - 元素类型。
8
+ * @property content - 文本内容,仅用于 'text' 类型。
9
+ * @property file - 文件标识符(本地文件名或 S3 Key),用于媒体类型。
10
+ */
11
+ export interface StoredElement {
12
+ type: 'text' | 'img' | 'video' | 'audio' | 'file';
13
+ content?: string;
14
+ file?: string;
15
+ }
16
+ /**
17
+ * 数据库中 `cave` 表的完整对象模型。
18
+ * @property id - 回声洞的唯一数字 ID。
19
+ * @property elements - 构成回声洞内容的元素数组。
20
+ * @property channelId - 提交回声洞的频道 ID,若为私聊则为 null。
21
+ * @property userId - 提交用户的 ID。
22
+ * @property userName - 提交用户的昵称。
23
+ * @property status - 回声洞状态: 'active' (活跃), 'delete' (待删除), 'pending' (待审核)。
24
+ * @property time - 提交时间。
25
+ */
26
+ export interface CaveObject {
27
+ id: number;
28
+ elements: StoredElement[];
29
+ channelId: string;
30
+ userId: string;
31
+ userName: string;
32
+ status: 'active' | 'delete' | 'pending';
33
+ time: Date;
34
+ }
35
+ declare module 'koishi' {
36
+ interface Tables {
37
+ cave: CaveObject;
38
+ }
39
+ }
40
+ /**
41
+ * 插件的配置接口。
42
+ */
43
+ export interface Config {
44
+ cooldown: number;
45
+ perChannel: boolean;
46
+ adminUsers: string[];
47
+ enableProfile: boolean;
48
+ enableDataIO: boolean;
49
+ enableReview: boolean;
50
+ caveFormat: string;
51
+ enableS3: boolean;
52
+ endpoint?: string;
53
+ region?: string;
54
+ accessKeyId?: string;
55
+ secretAccessKey?: string;
56
+ bucket?: string;
57
+ publicUrl?: string;
58
+ }
59
+ /**
60
+ * 使用 Koishi Schema 定义插件的配置项,用于生成配置界面。
61
+ */
62
+ export declare const Config: Schema<Config>;
63
+ /**
64
+ * 插件的入口函数。
65
+ * @param ctx - Koishi 上下文。
66
+ * @param config - 用户提供的插件配置。
67
+ */
68
+ export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -298,23 +298,40 @@ async function mediaElementToBase64(element, fileManager, logger2) {
298
298
  __name(mediaElementToBase64, "mediaElementToBase64");
299
299
  async function buildCaveMessage(cave, config, fileManager, logger2) {
300
300
  const caveHElements = storedFormatToHElements(cave.elements);
301
- const processedElements = await Promise.all(caveHElements.map((element) => {
301
+ const processedElements = await Promise.all(caveHElements.map(async (element) => {
302
302
  const isMedia = ["image", "video", "audio", "file"].includes(element.type);
303
303
  const fileName = element.attrs.src;
304
304
  if (!isMedia || !fileName) {
305
- return Promise.resolve(element);
305
+ return element;
306
306
  }
307
307
  if (config.enableS3 && config.publicUrl) {
308
308
  const fullUrl = config.publicUrl.endsWith("/") ? `${config.publicUrl}${fileName}` : `${config.publicUrl}/${fileName}`;
309
- return Promise.resolve((0, import_koishi.h)(element.type, { ...element.attrs, src: fullUrl }));
309
+ return (0, import_koishi.h)(element.type, { ...element.attrs, src: fullUrl });
310
310
  }
311
311
  return mediaElementToBase64(element, fileManager, logger2);
312
312
  }));
313
- return [
314
- (0, import_koishi.h)("p", {}, `回声洞 ——(${cave.id})`),
315
- ...processedElements,
316
- (0, import_koishi.h)("p", {}, `—— ${cave.userName}`)
317
- ];
313
+ const finalMessage = [];
314
+ const formatString = config.caveFormat;
315
+ const separatorIndex = formatString.indexOf("|");
316
+ let headerFormat;
317
+ let footerFormat;
318
+ if (separatorIndex === -1) {
319
+ headerFormat = formatString;
320
+ footerFormat = "";
321
+ } else {
322
+ headerFormat = formatString.substring(0, separatorIndex);
323
+ footerFormat = formatString.substring(separatorIndex + 1);
324
+ }
325
+ const headerText = headerFormat.replace("{id}", cave.id.toString()).replace("{name}", cave.userName);
326
+ if (headerText.trim()) {
327
+ finalMessage.push((0, import_koishi.h)("p", {}, headerText));
328
+ }
329
+ finalMessage.push(...processedElements);
330
+ const footerText = footerFormat.replace("{id}", cave.id.toString()).replace("{name}", cave.userName);
331
+ if (footerText.trim()) {
332
+ finalMessage.push((0, import_koishi.h)("p", {}, footerText));
333
+ }
334
+ return finalMessage;
318
335
  }
319
336
  __name(buildCaveMessage, "buildCaveMessage");
320
337
  async function cleanupPendingDeletions(ctx, fileManager, logger2) {
@@ -620,7 +637,8 @@ var Config = import_koishi3.Schema.intersect([
620
637
  perChannel: import_koishi3.Schema.boolean().default(false).description("启用分群模式"),
621
638
  enableProfile: import_koishi3.Schema.boolean().default(false).description("启用自定义昵称"),
622
639
  enableDataIO: import_koishi3.Schema.boolean().default(false).description("启用导入导出"),
623
- adminUsers: import_koishi3.Schema.array(import_koishi3.Schema.string()).default([]).description("管理员 ID 列表")
640
+ adminUsers: import_koishi3.Schema.array(import_koishi3.Schema.string()).default([]).description("管理员 ID 列表"),
641
+ caveFormat: import_koishi3.Schema.string().default("回声洞 ——({id})|—— {name}").required().description("自定义文本(使用|分隔)")
624
642
  }).description("基础配置"),
625
643
  import_koishi3.Schema.object({
626
644
  enableReview: import_koishi3.Schema.boolean().default(false).description("启用审核")
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-best-cave",
3
3
  "description": "最强大的回声洞现已重构完成啦!注意数据格式需要使用脚本转换哦~",
4
- "version": "2.0.0",
4
+ "version": "2.0.1",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],