koishi-plugin-booknews 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 +25 -19
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -44,27 +44,33 @@ function apply(ctx, config) {
|
|
|
44
44
|
}, { autoInc: true });
|
|
45
45
|
const sendDailyReport = /* @__PURE__ */ __name(async (isManual = false) => {
|
|
46
46
|
const newsList = await ctx.database.get("daily_book_news", {});
|
|
47
|
-
if (newsList.length === 0) return "
|
|
47
|
+
if (newsList.length === 0) return "今日暂无书讯。";
|
|
48
48
|
const bot = ctx.bots[0];
|
|
49
|
-
if (!bot) return
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
49
|
+
if (!bot) return;
|
|
50
|
+
const chunkSize = 10;
|
|
51
|
+
for (let i = 0; i < newsList.length; i += chunkSize) {
|
|
52
|
+
const chunk = newsList.slice(i, i + chunkSize);
|
|
53
|
+
const nodes = chunk.map((item) => (0, import_koishi.h)("message", {
|
|
54
|
+
forward: true,
|
|
55
|
+
userId: bot.selfId,
|
|
56
|
+
nickname: item.authorName
|
|
57
|
+
}, import_koishi.h.parse(item.content)));
|
|
58
|
+
const partNum = Math.floor(i / chunkSize) + 1;
|
|
59
|
+
const totalParts = Math.ceil(newsList.length / chunkSize);
|
|
60
|
+
nodes.unshift((0, import_koishi.h)("message", {
|
|
61
|
+
forward: true,
|
|
62
|
+
userId: bot.selfId,
|
|
63
|
+
nickname: "书讯助手"
|
|
64
|
+
}, `书讯汇总 (${partNum}/${totalParts})
|
|
65
|
+
本段包含 ${chunk.length} 条资讯`));
|
|
66
|
+
try {
|
|
67
|
+
await bot.sendMessage(config.dstGroupIds, nodes);
|
|
68
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
69
|
+
} catch (e) {
|
|
70
|
+
ctx.logger("book").error(`分段 ${partNum} 发送失败`, e);
|
|
71
|
+
}
|
|
67
72
|
}
|
|
73
|
+
return `已尝试发送 ${newsList.length} 条书讯(分段处理完毕)。`;
|
|
68
74
|
}, "sendDailyReport");
|
|
69
75
|
ctx.on("message", async (session) => {
|
|
70
76
|
if (session.guildId !== config.sourceGroupId) return;
|