@bilibili-notify/dynamic 0.0.1-alpha.0 → 0.0.1-alpha.2

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.cjs CHANGED
@@ -7,6 +7,8 @@ let DynamicFilterReason = /* @__PURE__ */ function(DynamicFilterReason) {
7
7
  DynamicFilterReason["BlacklistKeyword"] = "blacklist-keyword";
8
8
  DynamicFilterReason["BlacklistForward"] = "blacklist-forward";
9
9
  DynamicFilterReason["BlacklistArticle"] = "blacklist-article";
10
+ DynamicFilterReason["BlacklistDraw"] = "blacklist-draw";
11
+ DynamicFilterReason["BlacklistAv"] = "blacklist-av";
10
12
  DynamicFilterReason["WhitelistUnmatched"] = "whitelist-unmatched";
11
13
  return DynamicFilterReason;
12
14
  }({});
@@ -55,6 +57,8 @@ function filterDynamic(dynamic, config, logger) {
55
57
  keywords: [],
56
58
  forward: false,
57
59
  article: false,
60
+ draw: false,
61
+ av: false,
58
62
  whitelistEnable: false,
59
63
  whitelistRegex: "",
60
64
  whitelistKeywords: [],
@@ -70,6 +74,14 @@ function filterDynamic(dynamic, config, logger) {
70
74
  blocked: true,
71
75
  reason: "blacklist-article"
72
76
  };
77
+ if (cfg.draw && dynamic.type === "DYNAMIC_TYPE_DRAW") return {
78
+ blocked: true,
79
+ reason: "blacklist-draw"
80
+ };
81
+ if (cfg.av && dynamic.type === "DYNAMIC_TYPE_AV") return {
82
+ blocked: true,
83
+ reason: "blacklist-av"
84
+ };
73
85
  if (safeRegexTest(cfg.regex, text, logger) || testKeywordMatched(text, cfg.keywords)) return {
74
86
  blocked: true,
75
87
  reason: "blacklist-keyword"
@@ -391,6 +403,8 @@ var DynamicEngine = class {
391
403
  ["blacklist-keyword"]: `${name}发布了一条含有屏蔽关键字的动态`,
392
404
  ["blacklist-forward"]: `${name}转发了一条动态,已屏蔽`,
393
405
  ["blacklist-article"]: `${name}投稿了一条专栏,已屏蔽`,
406
+ ["blacklist-draw"]: `${name}发布了一条图文动态,已屏蔽`,
407
+ ["blacklist-av"]: `${name}投稿了一条视频,已屏蔽`,
394
408
  ["whitelist-unmatched"]: `${name}发布了一条不在白名单范围内的动态,已屏蔽`
395
409
  };
396
410
  try {
@@ -471,16 +485,20 @@ var DynamicEngine = class {
471
485
  text: aiComment ?? `${name}发布了一条动态${dUrl ? `:${dUrl}` : ""}`
472
486
  }];
473
487
  await this.push.broadcastDynamic(uid, segments, "dynamic");
474
- if (this.config.pushImgsInDynamic && item.type === "DYNAMIC_TYPE_DRAW") {
488
+ const subForImgs = this.dynamicSubManager.get(uid);
489
+ if ((subForImgs?.imageGroupEnable ?? this.config.imageGroup.enable) && item.type === "DYNAMIC_TYPE_DRAW") {
475
490
  const major = item.modules?.module_dynamic?.major;
476
491
  const urls = [];
477
492
  for (const it of major?.draw?.items ?? []) if (it.src) urls.push(it.src);
478
493
  for (const pic of major?.opus?.pics ?? []) if (pic.url) urls.push(pic.url);
479
- if (urls.length) await this.push.broadcastDynamic(uid, [{
480
- type: "image-group",
481
- forward: true,
482
- urls
483
- }], "dynamic-images");
494
+ if (urls.length) {
495
+ const forward = (subForImgs?.imageGroupForward ?? this.config.imageGroup.forward) && urls.length > 1;
496
+ await this.push.broadcastDynamic(uid, [{
497
+ type: "image-group",
498
+ forward,
499
+ urls
500
+ }], "dynamic-images");
501
+ }
484
502
  }
485
503
  markOk(uid, postTime);
486
504
  } catch (e) {
package/lib/index.d.cts CHANGED
@@ -90,6 +90,10 @@ interface DynamicFilterConfig {
90
90
  keywords?: string[];
91
91
  forward?: boolean;
92
92
  article?: boolean;
93
+ /** DYNAMIC_TYPE_DRAW(图文动态;新版 B 站把图文挂在 major.opus 下,外层 type 仍为 DRAW)。 */
94
+ draw?: boolean;
95
+ /** DYNAMIC_TYPE_AV(视频投稿动态)。 */
96
+ av?: boolean;
93
97
  whitelistEnable?: boolean;
94
98
  whitelistRegex?: string;
95
99
  whitelistKeywords?: string[];
@@ -98,6 +102,8 @@ declare enum DynamicFilterReason {
98
102
  BlacklistKeyword = "blacklist-keyword",
99
103
  BlacklistForward = "blacklist-forward",
100
104
  BlacklistArticle = "blacklist-article",
105
+ BlacklistDraw = "blacklist-draw",
106
+ BlacklistAv = "blacklist-av",
101
107
  WhitelistUnmatched = "whitelist-unmatched"
102
108
  }
103
109
  interface DynamicFilterResult {
@@ -164,6 +170,16 @@ interface SubItemView {
164
170
  };
165
171
  /** Per-UP AI 覆盖;undefined 时使用 CommentaryGenerator 的全局 config。 */
166
172
  aiOverride?: CommentaryCallOverride;
173
+ /**
174
+ * Per-UP 是否推送动态图集图片;undefined 继承 engine config `imageGroup.enable`。
175
+ * Adapter 折叠 `Subscription.overrides.imageGroup.enable` 后填入。
176
+ */
177
+ imageGroupEnable?: boolean;
178
+ /**
179
+ * Per-UP 图集合并转发开关;undefined 继承 engine config `imageGroup.forward`。
180
+ * 单图永远不走合并转发(在 engine 内已守卫)。
181
+ */
182
+ imageGroupForward?: boolean;
167
183
  }
168
184
  type SubscriptionsView = Record<string, SubItemView>;
169
185
  type SubManagerView = Map<string, SubItemView>;
@@ -202,8 +218,16 @@ interface DynamicEngineConfig {
202
218
  dynamicCron: string;
203
219
  /** 视频动态时是否将 URL 替换为 BV 号。 */
204
220
  dynamicVideoUrlToBV: boolean;
205
- /** 是否额外推送 DYNAMIC_TYPE_DRAW 中的图集(forward message)。 */
206
- pushImgsInDynamic: boolean;
221
+ /**
222
+ * DYNAMIC_TYPE_DRAW 图集图片推送行为。enable=false 时跳过图集广播,
223
+ * 只发文本/卡片。forward=true 时走合并转发(聊天记录卡片,走 OneBot
224
+ * send_group_forward_msg,部分 OneBot 实现/NapCat 长消息通道不稳);
225
+ * forward=false 多图合并到一条普通 send_group_msg。单图永远不走合并转发。
226
+ */
227
+ imageGroup: {
228
+ enable: boolean;
229
+ forward: boolean;
230
+ };
207
231
  /** 内容过滤配置(含 notify:被屏蔽时是否通知)。 */
208
232
  filter: DynamicFilterConfig & {
209
233
  notify?: boolean;
package/lib/index.d.mts CHANGED
@@ -90,6 +90,10 @@ interface DynamicFilterConfig {
90
90
  keywords?: string[];
91
91
  forward?: boolean;
92
92
  article?: boolean;
93
+ /** DYNAMIC_TYPE_DRAW(图文动态;新版 B 站把图文挂在 major.opus 下,外层 type 仍为 DRAW)。 */
94
+ draw?: boolean;
95
+ /** DYNAMIC_TYPE_AV(视频投稿动态)。 */
96
+ av?: boolean;
93
97
  whitelistEnable?: boolean;
94
98
  whitelistRegex?: string;
95
99
  whitelistKeywords?: string[];
@@ -98,6 +102,8 @@ declare enum DynamicFilterReason {
98
102
  BlacklistKeyword = "blacklist-keyword",
99
103
  BlacklistForward = "blacklist-forward",
100
104
  BlacklistArticle = "blacklist-article",
105
+ BlacklistDraw = "blacklist-draw",
106
+ BlacklistAv = "blacklist-av",
101
107
  WhitelistUnmatched = "whitelist-unmatched"
102
108
  }
103
109
  interface DynamicFilterResult {
@@ -164,6 +170,16 @@ interface SubItemView {
164
170
  };
165
171
  /** Per-UP AI 覆盖;undefined 时使用 CommentaryGenerator 的全局 config。 */
166
172
  aiOverride?: CommentaryCallOverride;
173
+ /**
174
+ * Per-UP 是否推送动态图集图片;undefined 继承 engine config `imageGroup.enable`。
175
+ * Adapter 折叠 `Subscription.overrides.imageGroup.enable` 后填入。
176
+ */
177
+ imageGroupEnable?: boolean;
178
+ /**
179
+ * Per-UP 图集合并转发开关;undefined 继承 engine config `imageGroup.forward`。
180
+ * 单图永远不走合并转发(在 engine 内已守卫)。
181
+ */
182
+ imageGroupForward?: boolean;
167
183
  }
168
184
  type SubscriptionsView = Record<string, SubItemView>;
169
185
  type SubManagerView = Map<string, SubItemView>;
@@ -202,8 +218,16 @@ interface DynamicEngineConfig {
202
218
  dynamicCron: string;
203
219
  /** 视频动态时是否将 URL 替换为 BV 号。 */
204
220
  dynamicVideoUrlToBV: boolean;
205
- /** 是否额外推送 DYNAMIC_TYPE_DRAW 中的图集(forward message)。 */
206
- pushImgsInDynamic: boolean;
221
+ /**
222
+ * DYNAMIC_TYPE_DRAW 图集图片推送行为。enable=false 时跳过图集广播,
223
+ * 只发文本/卡片。forward=true 时走合并转发(聊天记录卡片,走 OneBot
224
+ * send_group_forward_msg,部分 OneBot 实现/NapCat 长消息通道不稳);
225
+ * forward=false 多图合并到一条普通 send_group_msg。单图永远不走合并转发。
226
+ */
227
+ imageGroup: {
228
+ enable: boolean;
229
+ forward: boolean;
230
+ };
207
231
  /** 内容过滤配置(含 notify:被屏蔽时是否通知)。 */
208
232
  filter: DynamicFilterConfig & {
209
233
  notify?: boolean;
package/lib/index.mjs CHANGED
@@ -6,6 +6,8 @@ let DynamicFilterReason = /* @__PURE__ */ function(DynamicFilterReason) {
6
6
  DynamicFilterReason["BlacklistKeyword"] = "blacklist-keyword";
7
7
  DynamicFilterReason["BlacklistForward"] = "blacklist-forward";
8
8
  DynamicFilterReason["BlacklistArticle"] = "blacklist-article";
9
+ DynamicFilterReason["BlacklistDraw"] = "blacklist-draw";
10
+ DynamicFilterReason["BlacklistAv"] = "blacklist-av";
9
11
  DynamicFilterReason["WhitelistUnmatched"] = "whitelist-unmatched";
10
12
  return DynamicFilterReason;
11
13
  }({});
@@ -54,6 +56,8 @@ function filterDynamic(dynamic, config, logger) {
54
56
  keywords: [],
55
57
  forward: false,
56
58
  article: false,
59
+ draw: false,
60
+ av: false,
57
61
  whitelistEnable: false,
58
62
  whitelistRegex: "",
59
63
  whitelistKeywords: [],
@@ -69,6 +73,14 @@ function filterDynamic(dynamic, config, logger) {
69
73
  blocked: true,
70
74
  reason: "blacklist-article"
71
75
  };
76
+ if (cfg.draw && dynamic.type === "DYNAMIC_TYPE_DRAW") return {
77
+ blocked: true,
78
+ reason: "blacklist-draw"
79
+ };
80
+ if (cfg.av && dynamic.type === "DYNAMIC_TYPE_AV") return {
81
+ blocked: true,
82
+ reason: "blacklist-av"
83
+ };
72
84
  if (safeRegexTest(cfg.regex, text, logger) || testKeywordMatched(text, cfg.keywords)) return {
73
85
  blocked: true,
74
86
  reason: "blacklist-keyword"
@@ -390,6 +402,8 @@ var DynamicEngine = class {
390
402
  ["blacklist-keyword"]: `${name}发布了一条含有屏蔽关键字的动态`,
391
403
  ["blacklist-forward"]: `${name}转发了一条动态,已屏蔽`,
392
404
  ["blacklist-article"]: `${name}投稿了一条专栏,已屏蔽`,
405
+ ["blacklist-draw"]: `${name}发布了一条图文动态,已屏蔽`,
406
+ ["blacklist-av"]: `${name}投稿了一条视频,已屏蔽`,
393
407
  ["whitelist-unmatched"]: `${name}发布了一条不在白名单范围内的动态,已屏蔽`
394
408
  };
395
409
  try {
@@ -470,16 +484,20 @@ var DynamicEngine = class {
470
484
  text: aiComment ?? `${name}发布了一条动态${dUrl ? `:${dUrl}` : ""}`
471
485
  }];
472
486
  await this.push.broadcastDynamic(uid, segments, "dynamic");
473
- if (this.config.pushImgsInDynamic && item.type === "DYNAMIC_TYPE_DRAW") {
487
+ const subForImgs = this.dynamicSubManager.get(uid);
488
+ if ((subForImgs?.imageGroupEnable ?? this.config.imageGroup.enable) && item.type === "DYNAMIC_TYPE_DRAW") {
474
489
  const major = item.modules?.module_dynamic?.major;
475
490
  const urls = [];
476
491
  for (const it of major?.draw?.items ?? []) if (it.src) urls.push(it.src);
477
492
  for (const pic of major?.opus?.pics ?? []) if (pic.url) urls.push(pic.url);
478
- if (urls.length) await this.push.broadcastDynamic(uid, [{
479
- type: "image-group",
480
- forward: true,
481
- urls
482
- }], "dynamic-images");
493
+ if (urls.length) {
494
+ const forward = (subForImgs?.imageGroupForward ?? this.config.imageGroup.forward) && urls.length > 1;
495
+ await this.push.broadcastDynamic(uid, [{
496
+ type: "image-group",
497
+ forward,
498
+ urls
499
+ }], "dynamic-images");
500
+ }
483
501
  }
484
502
  markOk(uid, postTime);
485
503
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bilibili-notify/dynamic",
3
- "version": "0.0.1-alpha.0",
3
+ "version": "0.0.1-alpha.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/Akokk0/bilibili-notify"
@@ -28,10 +28,10 @@
28
28
  "dependencies": {
29
29
  "cron": "^3.1.7",
30
30
  "luxon": "^3.5.0",
31
- "@bilibili-notify/ai": "^0.0.1-alpha.0",
32
- "@bilibili-notify/api": "^0.2.0-alpha.0",
33
- "@bilibili-notify/internal": "^0.1.0-alpha.0",
34
- "@bilibili-notify/image": "^0.0.1-alpha.0"
31
+ "@bilibili-notify/api": "^0.2.0-alpha.2",
32
+ "@bilibili-notify/ai": "^0.0.1-alpha.1",
33
+ "@bilibili-notify/image": "^0.0.1-alpha.2",
34
+ "@bilibili-notify/internal": "^0.1.0-alpha.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/luxon": "^3.4.2"