koishi-plugin-booknews 0.0.4 → 0.0.6
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 -15
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -47,23 +47,16 @@ 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 = 10;
|
|
51
51
|
for (let i = 0; i < newsList.length; i += chunkSize) {
|
|
52
52
|
const chunk = newsList.slice(i, i + chunkSize);
|
|
53
53
|
const nodes = chunk.map((item) => {
|
|
54
|
-
const
|
|
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
|
-
});
|
|
54
|
+
const pureText = item.content.replace(/<img[^>]*>|<img>.*?<\/img>/g, "");
|
|
62
55
|
return (0, import_koishi.h)("message", {
|
|
63
56
|
forward: true,
|
|
64
57
|
userId: bot.selfId,
|
|
65
58
|
nickname: item.authorName
|
|
66
|
-
},
|
|
59
|
+
}, pureText);
|
|
67
60
|
});
|
|
68
61
|
const partNum = Math.floor(i / chunkSize) + 1;
|
|
69
62
|
const totalParts = Math.ceil(newsList.length / chunkSize);
|
|
@@ -71,17 +64,19 @@ function apply(ctx, config) {
|
|
|
71
64
|
forward: true,
|
|
72
65
|
userId: bot.selfId,
|
|
73
66
|
nickname: "书讯助手"
|
|
74
|
-
}, `📅 书讯汇总 (
|
|
67
|
+
}, `📅 书讯汇总 (${partNum}/${totalParts})
|
|
75
68
|
本段包含 ${chunk.length} 条资讯`));
|
|
76
69
|
try {
|
|
77
70
|
await bot.sendMessage(config.dstGroupIds, nodes);
|
|
78
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
71
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
79
72
|
} catch (e) {
|
|
80
|
-
ctx.logger("book").error(
|
|
73
|
+
ctx.logger("book").error(`分段 ${partNum} 发送失败`, e);
|
|
81
74
|
}
|
|
82
75
|
}
|
|
83
|
-
if (!isManual)
|
|
84
|
-
|
|
76
|
+
if (!isManual) {
|
|
77
|
+
await ctx.database.remove("daily_book_news", {});
|
|
78
|
+
}
|
|
79
|
+
return `已尝试发送 ${newsList.length} 条书讯(分段处理完毕)。`;
|
|
85
80
|
}, "sendDailyReport");
|
|
86
81
|
ctx.on("message", async (session) => {
|
|
87
82
|
if (session.guildId !== config.sourceGroupId) return;
|