koishi-plugin-booknews 0.0.3 → 0.0.4
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 +21 -10
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -47,30 +47,41 @@ function apply(ctx, config) {
|
|
|
47
47
|
if (newsList.length === 0) return "今日暂无书讯。";
|
|
48
48
|
const bot = ctx.bots[0];
|
|
49
49
|
if (!bot) return;
|
|
50
|
-
const chunkSize =
|
|
50
|
+
const chunkSize = 30;
|
|
51
51
|
for (let i = 0; i < newsList.length; i += chunkSize) {
|
|
52
52
|
const chunk = newsList.slice(i, i + chunkSize);
|
|
53
|
-
const nodes = chunk.map((item) =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
const nodes = chunk.map((item) => {
|
|
54
|
+
const elements = import_koishi.h.parse(item.content);
|
|
55
|
+
const textOnlyElements = import_koishi.h.transform(elements, {
|
|
56
|
+
// 当遇到 image 元素时,返回 null 即可将其从结果中移除
|
|
57
|
+
image: /* @__PURE__ */ __name(() => null, "image"),
|
|
58
|
+
// 如果有录音或视频也可以在此移除
|
|
59
|
+
audio: /* @__PURE__ */ __name(() => null, "audio"),
|
|
60
|
+
video: /* @__PURE__ */ __name(() => null, "video")
|
|
61
|
+
});
|
|
62
|
+
return (0, import_koishi.h)("message", {
|
|
63
|
+
forward: true,
|
|
64
|
+
userId: bot.selfId,
|
|
65
|
+
nickname: item.authorName
|
|
66
|
+
}, textOnlyElements);
|
|
67
|
+
});
|
|
58
68
|
const partNum = Math.floor(i / chunkSize) + 1;
|
|
59
69
|
const totalParts = Math.ceil(newsList.length / chunkSize);
|
|
60
70
|
nodes.unshift((0, import_koishi.h)("message", {
|
|
61
71
|
forward: true,
|
|
62
72
|
userId: bot.selfId,
|
|
63
73
|
nickname: "书讯助手"
|
|
64
|
-
},
|
|
74
|
+
}, `📅 书讯汇总 (文字版 ${partNum}/${totalParts})
|
|
65
75
|
本段包含 ${chunk.length} 条资讯`));
|
|
66
76
|
try {
|
|
67
77
|
await bot.sendMessage(config.dstGroupIds, nodes);
|
|
68
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
78
|
+
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
69
79
|
} catch (e) {
|
|
70
|
-
ctx.logger("book").error(
|
|
80
|
+
ctx.logger("book").error(`文字版分段 ${partNum} 发送失败`, e);
|
|
71
81
|
}
|
|
72
82
|
}
|
|
73
|
-
|
|
83
|
+
if (!isManual) await ctx.database.remove("daily_book_news", {});
|
|
84
|
+
return "文字版汇总发送完毕。";
|
|
74
85
|
}, "sendDailyReport");
|
|
75
86
|
ctx.on("message", async (session) => {
|
|
76
87
|
if (session.guildId !== config.sourceGroupId) return;
|