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