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.
Files changed (2) hide show
  1. package/lib/index.js +25 -19
  2. 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 nodes = newsList.map((item) => (0, import_koishi.h)("message", {
51
- forward: true,
52
- userId: bot.selfId,
53
- nickname: item.authorName
54
- }, import_koishi.h.parse(item.content)));
55
- nodes.unshift((0, import_koishi.h)("message", {
56
- forward: true,
57
- userId: bot.selfId,
58
- nickname: "书讯助手"
59
- }, `${(/* @__PURE__ */ new Date()).toLocaleDateString()} 书讯汇总
60
- 共收录 ${newsList.length} 条资讯`));
61
- try {
62
- await bot.sendMessage(config.dstGroupIds, nodes);
63
- return `发送成功,共 ${newsList.length} 条。`;
64
- } catch (e) {
65
- ctx.logger("book").error("发送失败", e);
66
- return "发送失败,请检查日志。";
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-booknews",
3
3
  "description": "It's a plugin for booknews collection",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [