koishi-plugin-clocktower 1.0.0 → 1.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.js +28 -30
- package/package.json +2 -2
- package/readme.md +13 -6
package/lib/index.js
CHANGED
|
@@ -486,7 +486,7 @@ function truncate(text, maxLength = 2400) {
|
|
|
486
486
|
const paragraphEnd = text.lastIndexOf("\n", maxLength);
|
|
487
487
|
const end = paragraphEnd > maxLength * 0.8 ? paragraphEnd : maxLength;
|
|
488
488
|
return `${text.slice(0, end).trim()}
|
|
489
|
-
|
|
489
|
+
……内容过长,已截断。`;
|
|
490
490
|
}
|
|
491
491
|
__name(truncate, "truncate");
|
|
492
492
|
function offlineNotice(result) {
|
|
@@ -498,31 +498,40 @@ __name(offlineNotice, "offlineNotice");
|
|
|
498
498
|
function formatPage(result, sectionQuery) {
|
|
499
499
|
const { page } = result;
|
|
500
500
|
const sections = splitSections(page);
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
501
|
+
if (page.kind === "rule") {
|
|
502
|
+
if (!sectionQuery) {
|
|
503
|
+
return `【${page.title}】
|
|
504
504
|
请选择章节:
|
|
505
505
|
${sectionList(sections)}
|
|
506
506
|
|
|
507
|
-
|
|
508
|
-
来源:${page.sourceUrl}`;
|
|
509
|
-
}
|
|
510
|
-
if (!sections.length) return `【${page.title}】
|
|
511
|
-
${truncate(page.text)}${offlineNotice(result)}
|
|
507
|
+
用法:clocktower/规则 ${page.title} <章节名或编号>${offlineNotice(result)}
|
|
512
508
|
来源:${page.sourceUrl}`;
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
509
|
+
}
|
|
510
|
+
const section2 = selectSection(sections, sectionQuery);
|
|
511
|
+
if (!section2) {
|
|
512
|
+
return `未在《${page.title}》中找到唯一匹配的“${sectionQuery}”章节。
|
|
517
513
|
可选章节:
|
|
518
514
|
${sectionList(sections)}`;
|
|
515
|
+
}
|
|
516
|
+
return `【${page.title} · ${section2.line}】
|
|
517
|
+
${truncate(section2.text || "本章节暂无文字内容。")}${offlineNotice(result)}
|
|
518
|
+
来源:${page.sourceUrl}`;
|
|
519
|
+
}
|
|
520
|
+
if (!sections.length) return `【${page.title}】
|
|
521
|
+
${truncate(page.text)}${offlineNotice(result)}`;
|
|
522
|
+
if (!sectionQuery) {
|
|
523
|
+
const defaults = ["角色能力", "角色简介"].map((query) => selectSection(sections, query)).filter((section2) => !!section2?.text);
|
|
524
|
+
if (!defaults.length) return `【${page.title}】
|
|
525
|
+
暂无角色能力和角色简介。${offlineNotice(result)}`;
|
|
526
|
+
const content = defaults.map((section2) => `${section2.line}
|
|
527
|
+
${section2.text || "本章节暂无文字内容。"}`).join("\n\n");
|
|
528
|
+
return `【${page.title}】
|
|
529
|
+
${truncate(content, 3e3)}${offlineNotice(result)}`;
|
|
519
530
|
}
|
|
531
|
+
const section = selectSection(sections, sectionQuery);
|
|
532
|
+
if (!section) return `未在《${page.title}》中找到“${sectionQuery}”章节。`;
|
|
520
533
|
return `【${page.title} · ${section.line}】
|
|
521
|
-
${truncate(section.text || "本章节暂无文字内容。")}${offlineNotice(result)}
|
|
522
|
-
|
|
523
|
-
其他章节:${sections.map((item) => item.line).join("、")}
|
|
524
|
-
用法:${command} ${page.title} <章节名或编号>
|
|
525
|
-
来源:${page.sourceUrl}`;
|
|
534
|
+
${truncate(section.text || "本章节暂无文字内容。")}${offlineNotice(result)}`;
|
|
526
535
|
}
|
|
527
536
|
__name(formatPage, "formatPage");
|
|
528
537
|
function formatLookup(lookup, section) {
|
|
@@ -542,7 +551,7 @@ function apply(ctx, config) {
|
|
|
542
551
|
logger: /* @__PURE__ */ __name((message) => logger.warn(message), "logger")
|
|
543
552
|
});
|
|
544
553
|
ctx.command("clocktower/角色 [name] [section]", "查询血染钟楼角色资料").action(async (_, roleName, section) => {
|
|
545
|
-
if (!roleName) return "
|
|
554
|
+
if (!roleName) return "请输入要查询的角色名称。";
|
|
546
555
|
try {
|
|
547
556
|
return formatLookup(await wiki.findRole(roleName), section);
|
|
548
557
|
} catch (error) {
|
|
@@ -550,17 +559,6 @@ function apply(ctx, config) {
|
|
|
550
559
|
return `角色查询失败:${error instanceof Error ? error.message : String(error)}`;
|
|
551
560
|
}
|
|
552
561
|
});
|
|
553
|
-
ctx.command("clocktower/规则 [name] [section]", "查询血染钟楼规则").action(async (_, ruleName, section) => {
|
|
554
|
-
if (!ruleName) return `用法:clocktower/规则 <规则页名> [章节名或编号]
|
|
555
|
-
可用规则页:
|
|
556
|
-
${RULE_PAGES.join("\n")}`;
|
|
557
|
-
try {
|
|
558
|
-
return formatLookup(await wiki.findRule(ruleName), section);
|
|
559
|
-
} catch (error) {
|
|
560
|
-
logger.warn("规则查询失败:%s", error);
|
|
561
|
-
return `规则查询失败:${error instanceof Error ? error.message : String(error)}`;
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
562
|
ctx.command("clocktower/刷新 <name>", "刷新单个角色或规则页面", { authority: 3 }).action(async (_, pageName) => {
|
|
565
563
|
try {
|
|
566
564
|
const rule = await wiki.findRule(pageName, true);
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# koishi-plugin-clocktower
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
血染钟楼插件。提供钟楼百科角色资料的按需查询、本地缓存和离线兜底,不会在启动时同步整个百科,也不会预下载图片。
|
|
4
4
|
|
|
5
5
|
## 配置项
|
|
6
6
|
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
| 指令 | 权限 | 说明 |
|
|
15
15
|
| --- | --- | --- |
|
|
16
|
-
| `clocktower/角色 <角色名> [章节名或编号]` | 1 |
|
|
17
|
-
| `clocktower/规则 <规则页名> [章节名或编号]` | 1 | 查询规则页;不指定章节时列出可选章节 |
|
|
16
|
+
| `clocktower/角色 <角色名> [章节名或编号]` | 1 | 模糊查询角色,默认合并显示有正文的“角色能力”和“角色简介”;缺少的章节不显示。指定章节时可查询“范例”“提示与技巧”等内容。角色结果不显示章节列表、用法和来源链接 |
|
|
18
17
|
| `clocktower/刷新 <角色名或规则页名>` | 3 | 强制刷新单个页面,不再提供全量同步 |
|
|
19
18
|
|
|
20
19
|
示例:
|
|
@@ -23,8 +22,6 @@
|
|
|
23
22
|
clocktower/角色 洗衣妇
|
|
24
23
|
clocktower/角色 洗衣妇 提示与技巧
|
|
25
24
|
clocktower/角色 洗衣妇 8
|
|
26
|
-
clocktower/规则 规则概要
|
|
27
|
-
clocktower/规则 规则概要 二、夜晚阶段
|
|
28
25
|
clocktower/刷新 洗衣妇
|
|
29
26
|
```
|
|
30
27
|
|
|
@@ -37,7 +34,7 @@ clocktower/刷新 洗衣妇
|
|
|
37
34
|
- 已有 `manifest.json` 和 `pages/` 中的完整抓取数据会作为离线快照保留,不会删除。
|
|
38
35
|
- 新获取的页面写入 `data/clocktower/cache/pages/`,页面目录写入 `cache/catalog.json`,搜索索引写入 `cache/search/`。
|
|
39
36
|
- 正文图片仍保留原始 URL 和已有本地文件信息,但查询消息仅发送文字,不预下载图片。
|
|
40
|
-
-
|
|
37
|
+
- 角色默认合并内容最长显示约 3000 字,单个角色章节最长显示约 2400 字,超出后提示内容已截断。
|
|
41
38
|
|
|
42
39
|
每个页面 JSON 包含原始标题、实际标题、页面 ID、修订 ID、来源 URL、抓取时间、完整 HTML、纯文本、维基源码、图片及本地路径、站内链接、站外链接、目录、分类和页面属性。角色另含 `sourceIndexes`,记录其出现的角色类型或剧本索引。
|
|
43
40
|
|
|
@@ -47,6 +44,16 @@ clocktower/刷新 洗衣妇
|
|
|
47
44
|
|
|
48
45
|
## 更新日志
|
|
49
46
|
|
|
47
|
+
### v1.0.2
|
|
48
|
+
|
|
49
|
+
- 角色能力或角色简介不存在、正文为空时,只显示有内容的章节。
|
|
50
|
+
- 删除 `clocktower/规则` 指令。
|
|
51
|
+
|
|
52
|
+
### v1.0.1
|
|
53
|
+
|
|
54
|
+
- 角色查询默认直接显示“角色能力”和“角色简介”,不再提示其他章节。
|
|
55
|
+
- 角色结果移除来源链接和用法,保留可选章节查询;规则查询输出不变。
|
|
56
|
+
|
|
50
57
|
### v1.0.0
|
|
51
58
|
|
|
52
59
|
- 发布首个 npm 正式版本。
|