koishi-plugin-booknews 0.0.2 → 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.
Files changed (2) hide show
  1. package/lib/index.js +36 -19
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -44,27 +44,44 @@ 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 = 30;
51
+ for (let i = 0; i < newsList.length; i += chunkSize) {
52
+ const chunk = newsList.slice(i, i + chunkSize);
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
+ });
68
+ const partNum = Math.floor(i / chunkSize) + 1;
69
+ const totalParts = Math.ceil(newsList.length / chunkSize);
70
+ nodes.unshift((0, import_koishi.h)("message", {
71
+ forward: true,
72
+ userId: bot.selfId,
73
+ nickname: "书讯助手"
74
+ }, `📅 书讯汇总 (文字版 ${partNum}/${totalParts})
75
+ 本段包含 ${chunk.length} 条资讯`));
76
+ try {
77
+ await bot.sendMessage(config.dstGroupIds, nodes);
78
+ await new Promise((resolve) => setTimeout(resolve, 1500));
79
+ } catch (e) {
80
+ ctx.logger("book").error(`文字版分段 ${partNum} 发送失败`, e);
81
+ }
67
82
  }
83
+ if (!isManual) await ctx.database.remove("daily_book_news", {});
84
+ return "文字版汇总发送完毕。";
68
85
  }, "sendDailyReport");
69
86
  ctx.on("message", async (session) => {
70
87
  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.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [