koishi-plugin-maple-drift-bottle 0.0.1 → 0.0.3

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.js CHANGED
@@ -31,12 +31,18 @@ var name = "maple-drift-bottle";
31
31
  var using = ["database"];
32
32
  var Config = import_koishi.Schema.object({
33
33
  anonymousByDefault: import_koishi.Schema.boolean().default(false).description("默认是否匿名(true: 匿名,false: 不匿名)"),
34
- maxContentLength: import_koishi.Schema.number().default(500).min(50).max(2e3).description("漂流瓶内容最大长度(字)(50-2000)")
34
+ maxContentLength: import_koishi.Schema.number().default(500).min(50).max(2e3).description("漂流瓶内容最大长度(字)(50-2000)"),
35
+ maxPreviewLength: import_koishi.Schema.number().default(8).min(3).max(50).description('指令"我的漂流瓶"最大预览长度(字)(3-50)'),
36
+ adminQQ: import_koishi.Schema.array(String).role("table").default([]).description("管理人QQ号(可添加多个)")
35
37
  });
36
- function getAuthorDisplay(bottle) {
37
- return bottle.anonymous ? "匿名" : bottle.authorName;
38
+ function getSenderDisplay(bottle) {
39
+ if (bottle.anonymous) {
40
+ return "匿名";
41
+ } else {
42
+ return `${bottle.authorName} (${bottle.author})`;
43
+ }
38
44
  }
39
- __name(getAuthorDisplay, "getAuthorDisplay");
45
+ __name(getSenderDisplay, "getSenderDisplay");
40
46
  function formatTime(date) {
41
47
  return date.toLocaleString("zh-CN", {
42
48
  year: "numeric",
@@ -48,6 +54,13 @@ function formatTime(date) {
48
54
  });
49
55
  }
50
56
  __name(formatTime, "formatTime");
57
+ function getContentPreview(content, maxLength) {
58
+ if (content.length <= maxLength) {
59
+ return content;
60
+ }
61
+ return content.substring(0, maxLength) + "...";
62
+ }
63
+ __name(getContentPreview, "getContentPreview");
51
64
  function apply(ctx, config) {
52
65
  console.log("maple-drift-bottle 漂流瓶插件加载中...");
53
66
  ctx.model.extend("maple-drift-bottles", {
@@ -77,10 +90,10 @@ function apply(ctx, config) {
77
90
  }
78
91
  const randomIndex = Math.floor(Math.random() * allBottles.length);
79
92
  const bottle = allBottles[randomIndex];
80
- const authorDisplay = getAuthorDisplay(bottle);
93
+ const senderDisplay = getSenderDisplay(bottle);
81
94
  const timeDisplay = formatTime(bottle.created);
82
95
  return `【漂流瓶 #${bottle.id}】
83
- 作者:${authorDisplay}
96
+ 发送者:${senderDisplay}
84
97
  时间:${timeDisplay}
85
98
  内容:
86
99
  ${bottle.content}`;
@@ -153,10 +166,12 @@ ID: #${newBottle.id}
153
166
  const displayIndex = startIndex + index + 1;
154
167
  const timeDisplay = formatTime(bottle.created);
155
168
  const anonymousText = bottle.anonymous ? "(匿名)" : "";
169
+ const contentPreview = getContentPreview(bottle.content, config.maxPreviewLength);
156
170
  output += `${displayIndex}. 漂流瓶 #${bottle.id} ${anonymousText} - ${timeDisplay}
171
+ 预览: ${contentPreview}
157
172
  `;
158
173
  });
159
- output += "\n──────────────\n";
174
+ output += "\n──────────\n";
160
175
  if (page > 1) {
161
176
  output += `输入"我的漂流瓶 ${page - 1}"查看上一页
162
177
  `;
@@ -172,7 +187,7 @@ ID: #${newBottle.id}
172
187
  return "查看漂流瓶时出错了,请稍后再试。";
173
188
  }
174
189
  });
175
- ctx.command("漂流瓶/查看漂流瓶 [id:number]", "查看特定的漂流瓶内容").alias("查看漂流瓶").alias("查看瓶子").option("all", "-a 查看任意漂流瓶(不受作者限制)").example("查看漂流瓶 1").example("查看漂流瓶 -a 1").action(async ({ session, options }, id) => {
190
+ ctx.command("漂流瓶/查看漂流瓶 [id:number]", "查看特定的漂流瓶内容").alias("查看漂流瓶").alias("查看瓶子").option("all", "-a 查看任意漂流瓶(不受发送者限制)").example("查看漂流瓶 1").action(async ({ session, options }, id) => {
176
191
  try {
177
192
  if (!id) {
178
193
  return '请提供漂流瓶序号!\n格式:查看漂流瓶 序号\n可以发送"我的漂流瓶"查看你发送的所有漂流瓶序号。';
@@ -187,10 +202,10 @@ ID: #${newBottle.id}
187
202
  return `仅可查看由你自己发送的漂流瓶。
188
203
  可以发送"我的漂流瓶"查看你发送的所有漂流瓶序号。`;
189
204
  }
190
- const authorDisplay = getAuthorDisplay(bottle);
205
+ const senderDisplay = getSenderDisplay(bottle);
191
206
  const timeDisplay = formatTime(bottle.created);
192
207
  return `【漂流瓶 #${bottle.id}】
193
- 作者:${authorDisplay}
208
+ 发送者:${senderDisplay}
194
209
  时间:${timeDisplay}
195
210
  状态:${bottle.anonymous ? "匿名" : "公开"}
196
211
  内容:
@@ -200,7 +215,7 @@ ${bottle.content}`;
200
215
  return "查看漂流瓶时出错了,请稍后再试。";
201
216
  }
202
217
  });
203
- ctx.command("漂流瓶/删除漂流瓶 [id:number]", "删除漂流瓶").alias("删除漂流瓶").alias("删除瓶子").option("all", "-a 删除任意漂流瓶(不受作者限制)").example("删除漂流瓶 1").example("删除漂流瓶 -a 1").action(async ({ session, options }, id) => {
218
+ ctx.command("漂流瓶/删除漂流瓶 [id:number]", "删除漂流瓶").alias("删除漂流瓶").alias("删除瓶子").option("all", "-a 删除任意漂流瓶(不受发送者限制)").example("删除漂流瓶 1").action(async ({ session, options }, id) => {
204
219
  try {
205
220
  if (!id) {
206
221
  return '请提供漂流瓶序号!\n格式:删除漂流瓶 序号\n可以发送"我的漂流瓶"查看你发送的所有漂流瓶序号。';
@@ -215,20 +230,20 @@ ${bottle.content}`;
215
230
  return `仅可删除由你自己发送的漂流瓶。
216
231
  可以发送"我的漂流瓶"查看你发送的所有漂流瓶序号。`;
217
232
  }
218
- const authorDisplay = getAuthorDisplay(bottle);
233
+ const senderDisplay = getSenderDisplay(bottle);
219
234
  const timeDisplay = formatTime(bottle.created);
220
235
  const contentPreview = bottle.content.length > 50 ? bottle.content.substring(0, 50) + "..." : bottle.content;
221
236
  await ctx.database.remove("maple-drift-bottles", { id });
222
237
  return `已成功删除漂流瓶 #${id}
223
- 作者:${authorDisplay}
238
+ 发送者:${senderDisplay}
224
239
  时间:${timeDisplay}
225
- 内容预览:${contentPreview}`;
240
+ 预览:${contentPreview}`;
226
241
  } catch (error) {
227
242
  ctx.logger("maple-drift-bottle").error("删除漂流瓶时出错:", error);
228
243
  return "删除漂流瓶时出错了,请稍后再试。";
229
244
  }
230
245
  });
231
- ctx.command("漂流瓶/清空漂流瓶 [options]", "清空漂流瓶").alias("清空漂流瓶").alias("清空瓶子").option("all", "-a 清空所有漂流瓶(默认)").option("user", "-u <userId:string> 清空指定用户的所有漂流瓶").option("date", "-d <date:string> 清空指定日期之前的漂流瓶(格式: yyyy-mm-dd)").example("清空漂流瓶").example("清空漂流瓶 -u 123456").action(async ({ session, options }) => {
246
+ ctx.command("漂流瓶/清空漂流瓶 [options]", "清空漂流瓶").alias("清空漂流瓶").alias("清空瓶子").option("all", "-a 清空所有漂流瓶(默认)").option("user", "-u <userId:string> 清空指定用户的所有漂流瓶").option("date", "-d <date:string> 清空指定日期之前的漂流瓶(格式: yyyy-mm-dd)").example("清空漂流瓶").example("清空漂流瓶 -d 2023-12-31").action(async ({ session, options }) => {
232
247
  try {
233
248
  const query = {};
234
249
  let description = "";
@@ -265,10 +280,59 @@ ${bottle.content}`;
265
280
  return "清空漂流瓶时出错了,请稍后再试。";
266
281
  }
267
282
  });
283
+ ctx.command("漂流瓶/联系漂流瓶管理人 <content:text>", "联系漂流瓶管理人").alias("联系漂流瓶管理人").example("联系漂流瓶管理人 我有一个建议").example("联系漂流瓶管理人 我发现了一个bug").action(async ({ session }, content) => {
284
+ try {
285
+ if (!content || content.trim().length === 0) {
286
+ return "联系内容不能为空!";
287
+ }
288
+ if (!config.adminQQ || config.adminQQ.length === 0) {
289
+ return "系统未配置管理人QQ,请联系管理员添加配置。";
290
+ }
291
+ const userInfo = await session.getUser(session.userId);
292
+ const senderName = userInfo?.name || session.username || `用户${session.userId}`;
293
+ const senderId = session.userId;
294
+ const currentTime = /* @__PURE__ */ new Date();
295
+ const timeDisplay = formatTime(currentTime);
296
+ const message = `您收到一条来自漂流瓶的联系消息!
297
+
298
+ 发送者: ${senderName} (${senderId})
299
+ 发送时间: ${timeDisplay}
300
+ 内容:
301
+ ${content.trim()}`;
302
+ let successCount = 0;
303
+ let failCount = 0;
304
+ const failDetails = [];
305
+ for (const adminQQ of config.adminQQ) {
306
+ try {
307
+ await session.bot.sendPrivateMessage(adminQQ, message);
308
+ successCount++;
309
+ } catch (error) {
310
+ failCount++;
311
+ failDetails.push(`QQ ${adminQQ}: ${error.message}`);
312
+ }
313
+ }
314
+ if (successCount === 0) {
315
+ return `消息发送失败,所有管理人都无法接收消息。
316
+ 失败详情:
317
+ ${failDetails.join("\n")}`;
318
+ } else if (failCount > 0) {
319
+ return `消息已发送给 ${successCount} 位管理人,但有 ${failCount} 位发送失败。
320
+ 失败详情:
321
+ ${failDetails.join("\n")}`;
322
+ } else {
323
+ return `消息已成功发送给 ${successCount} 位管理人!`;
324
+ }
325
+ } catch (error) {
326
+ ctx.logger("maple-drift-bottle").error("联系漂流瓶管理人时出错:", error);
327
+ return "联系漂流瓶管理人时出错了,请稍后再试。";
328
+ }
329
+ });
268
330
  ctx.on("ready", () => {
269
331
  console.log("maple-drift-bottle 漂流瓶插件已加载完成");
270
332
  ctx.logger("maple-drift-bottle").info(`默认匿名设置: ${config.anonymousByDefault ? "是" : "否"}`);
271
333
  ctx.logger("maple-drift-bottle").info(`内容最大长度: ${config.maxContentLength} 字`);
334
+ ctx.logger("maple-drift-bottle").info(`我的漂流瓶最大预览字数: ${config.maxPreviewLength} 字`);
335
+ ctx.logger("maple-drift-bottle").info(`管理人QQ: ${config.adminQQ.length > 0 ? config.adminQQ.join(", ") : "未配置"}`);
272
336
  });
273
337
  }
274
338
  __name(apply, "apply");
package/package.json CHANGED
@@ -1,18 +1,13 @@
1
1
  {
2
2
  "name": "koishi-plugin-maple-drift-bottle",
3
3
  "description": "-",
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
8
8
  "lib",
9
9
  "dist"
10
10
  ],
11
- "koishi": {
12
- "service": {
13
- "required": ["database"]
14
- }
15
- },
16
11
  "license": "MIT",
17
12
  "keywords": [
18
13
  "maple"
package/lib/index.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import { Context, Schema } from 'koishi';
2
- export declare const name = "maple-drift-bottle";
3
- export declare const using: readonly ["database"];
4
- interface DriftBottle {
5
- id: number;
6
- author: string;
7
- authorName: string;
8
- anonymous: boolean;
9
- content: string;
10
- created: Date;
11
- }
12
- declare module 'koishi' {
13
- interface Tables {
14
- 'maple-drift-bottles': DriftBottle;
15
- }
16
- }
17
- export interface Config {
18
- anonymousByDefault: boolean;
19
- maxContentLength: number;
20
- }
21
- export declare const Config: Schema<Config>;
22
- export declare function apply(ctx: Context, config: Config): void;
23
- export {};