koishi-plugin-booknews 0.0.3 → 0.0.5

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 +14 -10
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -47,30 +47,34 @@ 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 = 10;
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) => (0, import_koishi.h)("message", {
54
- forward: true,
55
- userId: bot.selfId,
56
- nickname: item.authorName
57
- }, import_koishi.h.parse(item.content)));
53
+ const nodes = chunk.map((item) => {
54
+ const pureText = item.content.replace(/<img[^>]*>|<img>.*?<\/img>/g, "");
55
+ return (0, import_koishi.h)("message", {
56
+ forward: true,
57
+ userId: bot.selfId,
58
+ nickname: item.authorName
59
+ }, pureText);
60
+ });
58
61
  const partNum = Math.floor(i / chunkSize) + 1;
59
62
  const totalParts = Math.ceil(newsList.length / chunkSize);
60
63
  nodes.unshift((0, import_koishi.h)("message", {
61
64
  forward: true,
62
65
  userId: bot.selfId,
63
66
  nickname: "书讯助手"
64
- }, `书讯汇总 (${partNum}/${totalParts})
67
+ }, `📅 书讯汇总 (文字版 ${partNum}/${totalParts})
65
68
  本段包含 ${chunk.length} 条资讯`));
66
69
  try {
67
70
  await bot.sendMessage(config.dstGroupIds, nodes);
68
- await new Promise((resolve) => setTimeout(resolve, 2e3));
71
+ await new Promise((resolve) => setTimeout(resolve, 1500));
69
72
  } catch (e) {
70
- ctx.logger("book").error(`分段 ${partNum} 发送失败`, e);
73
+ ctx.logger("book").error(`文字版分段 ${partNum} 发送失败`, e);
71
74
  }
72
75
  }
73
- return `已尝试发送 ${newsList.length} 条书讯(分段处理完毕)。`;
76
+ if (!isManual) await ctx.database.remove("daily_book_news", {});
77
+ return "文字版汇总发送完毕。";
74
78
  }, "sendDailyReport");
75
79
  ctx.on("message", async (session) => {
76
80
  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.3",
4
+ "version": "0.0.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [