koishi-plugin-maple-drift-bottle 0.0.2 → 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 +10 -8
- package/package.json +1 -1
- package/lib/index.d.ts +0 -24
package/lib/index.js
CHANGED
|
@@ -31,7 +31,8 @@ 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("漂流瓶内容最大长度(字)(50-2000)"),
|
|
35
|
+
maxPreviewLength: import_koishi.Schema.number().default(8).min(3).max(50).description('指令"我的漂流瓶"最大预览长度(字)(3-50)'),
|
|
35
36
|
adminQQ: import_koishi.Schema.array(String).role("table").default([]).description("管理人QQ号(可添加多个)")
|
|
36
37
|
});
|
|
37
38
|
function getSenderDisplay(bottle) {
|
|
@@ -53,11 +54,11 @@ function formatTime(date) {
|
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
56
|
__name(formatTime, "formatTime");
|
|
56
|
-
function getContentPreview(content) {
|
|
57
|
-
if (content.length <=
|
|
57
|
+
function getContentPreview(content, maxLength) {
|
|
58
|
+
if (content.length <= maxLength) {
|
|
58
59
|
return content;
|
|
59
60
|
}
|
|
60
|
-
return content.substring(0,
|
|
61
|
+
return content.substring(0, maxLength) + "...";
|
|
61
62
|
}
|
|
62
63
|
__name(getContentPreview, "getContentPreview");
|
|
63
64
|
function apply(ctx, config) {
|
|
@@ -108,7 +109,7 @@ ${bottle.content}`;
|
|
|
108
109
|
}
|
|
109
110
|
const trimmedContent = content.trim();
|
|
110
111
|
if (trimmedContent.length > config.maxContentLength) {
|
|
111
|
-
return `漂流瓶内容太长了!最多只能输入${config.maxContentLength}
|
|
112
|
+
return `漂流瓶内容太长了!最多只能输入${config.maxContentLength}个字(当前: ${trimmedContent.length})。`;
|
|
112
113
|
}
|
|
113
114
|
if (options.invisible && options.visible) {
|
|
114
115
|
return "选项冲突:-i(匿名)和-v(公开)不能同时使用";
|
|
@@ -165,12 +166,12 @@ ID: #${newBottle.id}
|
|
|
165
166
|
const displayIndex = startIndex + index + 1;
|
|
166
167
|
const timeDisplay = formatTime(bottle.created);
|
|
167
168
|
const anonymousText = bottle.anonymous ? "(匿名)" : "";
|
|
168
|
-
const contentPreview = getContentPreview(bottle.content);
|
|
169
|
+
const contentPreview = getContentPreview(bottle.content, config.maxPreviewLength);
|
|
169
170
|
output += `${displayIndex}. 漂流瓶 #${bottle.id} ${anonymousText} - ${timeDisplay}
|
|
170
171
|
预览: ${contentPreview}
|
|
171
172
|
`;
|
|
172
173
|
});
|
|
173
|
-
output += "\n
|
|
174
|
+
output += "\n──────────\n";
|
|
174
175
|
if (page > 1) {
|
|
175
176
|
output += `输入"我的漂流瓶 ${page - 1}"查看上一页
|
|
176
177
|
`;
|
|
@@ -329,7 +330,8 @@ ${failDetails.join("\n")}`;
|
|
|
329
330
|
ctx.on("ready", () => {
|
|
330
331
|
console.log("maple-drift-bottle 漂流瓶插件已加载完成");
|
|
331
332
|
ctx.logger("maple-drift-bottle").info(`默认匿名设置: ${config.anonymousByDefault ? "是" : "否"}`);
|
|
332
|
-
ctx.logger("maple-drift-bottle").info(`内容最大长度: ${config.maxContentLength}
|
|
333
|
+
ctx.logger("maple-drift-bottle").info(`内容最大长度: ${config.maxContentLength} 字`);
|
|
334
|
+
ctx.logger("maple-drift-bottle").info(`我的漂流瓶最大预览字数: ${config.maxPreviewLength} 字`);
|
|
333
335
|
ctx.logger("maple-drift-bottle").info(`管理人QQ: ${config.adminQQ.length > 0 ? config.adminQQ.join(", ") : "未配置"}`);
|
|
334
336
|
});
|
|
335
337
|
}
|
package/package.json
CHANGED
package/lib/index.d.ts
DELETED
|
@@ -1,24 +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
|
-
adminQQ: string[];
|
|
21
|
-
}
|
|
22
|
-
export declare const Config: Schema<Config>;
|
|
23
|
-
export declare function apply(ctx: Context, config: Config): void;
|
|
24
|
-
export {};
|