koishi-plugin-bilibili-notify 3.1.6 → 3.1.7-alpha.1

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/biliAPI.d.ts CHANGED
@@ -35,7 +35,7 @@ declare class BiliAPI extends Service {
35
35
  copyUserToGroup(mid: string, groupId: string): Promise<any>;
36
36
  getUserSpaceDynamic(mid: string): Promise<any>;
37
37
  createGroup(tag: string): Promise<any>;
38
- getAllDynamic(updateBaseline?: string): Promise<any>;
38
+ getAllDynamic(): Promise<any>;
39
39
  hasNewDynamic(updateBaseline: string): Promise<any>;
40
40
  follow(fid: string): Promise<any>;
41
41
  getRelationGroupDetail(tagid: string): Promise<any>;
package/lib/biliAPI.js CHANGED
@@ -25,8 +25,8 @@ const mixinKeyEncTab = [
25
25
  ];
26
26
  // 在getUserInfo中检测到番剧出差的UID时,要传回的数据:
27
27
  const bangumiTripData = { code: 0, data: { live_room: { roomid: 931774 } } };
28
- const GET_USER_SPACE_DYNAMIC_LIST = "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space";
29
- const GET_ALL_DYNAMIC_LIST = "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all";
28
+ const GET_USER_SPACE_DYNAMIC_LIST = "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?platform=web&features=itemOpusStyle";
29
+ const GET_ALL_DYNAMIC_LIST = "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?platform=web&features=itemOpusStyle";
30
30
  const HAS_NEW_DYNAMIC = "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all/update";
31
31
  const GET_COOKIES_INFO = "https://passport.bilibili.com/x/passport-login/web/cookie/info";
32
32
  const GET_USER_INFO = "https://api.bilibili.com/x/space/wbi/acc/info";
@@ -179,7 +179,7 @@ class BiliAPI extends koishi_1.Service {
179
179
  return data;
180
180
  }
181
181
  async getUserSpaceDynamic(mid) {
182
- const { data } = await this.client.get(`${GET_USER_SPACE_DYNAMIC_LIST}?host_mid=${mid}`);
182
+ const { data } = await this.client.get(`${GET_USER_SPACE_DYNAMIC_LIST}&host_mid=${mid}`);
183
183
  return data;
184
184
  }
185
185
  async createGroup(tag) {
@@ -193,12 +193,8 @@ class BiliAPI extends koishi_1.Service {
193
193
  });
194
194
  return data;
195
195
  }
196
- async getAllDynamic(updateBaseline) {
197
- let url = GET_ALL_DYNAMIC_LIST;
198
- if (updateBaseline) {
199
- url += `?update_baseline=${updateBaseline}`;
200
- }
201
- const { data } = await this.client.get(url);
196
+ async getAllDynamic() {
197
+ const { data } = await this.client.get(GET_ALL_DYNAMIC_LIST);
202
198
  return data;
203
199
  }
204
200
  async hasNewDynamic(updateBaseline) {
@@ -578,7 +578,7 @@ class ComRegister {
578
578
  // 推送该条动态
579
579
  const buffer = await (0, utils_1.withRetry)(async () => {
580
580
  // 渲染图片
581
- return await this.ctx.gi.generateDynamicImg(item, sub.card);
581
+ return await this.ctx.gi.generateDynamicImg(item, sub.card.enable ? sub.card : undefined);
582
582
  }, 1).catch(async (e) => {
583
583
  // 直播开播动态,不做处理
584
584
  if (e.message === "直播开播动态,不做处理")
@@ -755,7 +755,7 @@ class ComRegister {
755
755
  // 推送该条动态
756
756
  const buffer = await (0, utils_1.withRetry)(async () => {
757
757
  // 渲染图片
758
- return await this.ctx.gi.generateDynamicImg(item, sub.card);
758
+ return await this.ctx.gi.generateDynamicImg(item, sub.card.enable ? sub.card : undefined);
759
759
  }, 1).catch(async (e) => {
760
760
  // 直播开播动态,不做处理
761
761
  if (e.message === "直播开播动态,不做处理")
@@ -926,7 +926,7 @@ class ComRegister {
926
926
  // 生成图片
927
927
  const buffer = await (0, utils_1.withRetry)(async () => {
928
928
  // 获取直播通知卡片
929
- return await this.ctx.gi.generateLiveImg(liveRoomInfo, masterInfo.username, masterInfo.userface, followerDisplay, liveType, cardStyle);
929
+ return await this.ctx.gi.generateLiveImg(liveRoomInfo, masterInfo.username, masterInfo.userface, followerDisplay, liveType, cardStyle.enable ? cardStyle : undefined);
930
930
  }, 1).catch((e) => {
931
931
  this.logger.error(`liveDetect generateLiveImg() 推送卡片生成失败,原因:${e.message}`);
932
932
  });
@@ -1,4 +1,5 @@
1
1
  import { type Context, Schema, Service } from "koishi";
2
+ import type { Dynamic } from "./type";
2
3
  declare module "koishi" {
3
4
  interface Context {
4
5
  gi: GenerateImg;
@@ -15,7 +16,7 @@ declare class GenerateImg extends Service {
15
16
  cardBasePlateColor?: string;
16
17
  cardBasePlateBorder?: string;
17
18
  }): Promise<Buffer<ArrayBufferLike>>;
18
- generateDynamicImg(data: any, { cardColorStart, cardColorEnd, cardBasePlateColor, cardBasePlateBorder, }?: {
19
+ generateDynamicImg(data: Dynamic, { cardColorStart, cardColorEnd, cardBasePlateColor, cardBasePlateBorder, }?: {
19
20
  cardColorStart?: string;
20
21
  cardColorEnd?: string;
21
22
  cardBasePlateColor?: string;
@@ -214,9 +214,7 @@ class GenerateImg extends koishi_1.Service {
214
214
  throw new Error(`生成图片失败!错误: ${e.toString()}`);
215
215
  });
216
216
  }
217
- async generateDynamicImg(
218
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
219
- data, { cardColorStart = this.giConfig.cardColorStart, cardColorEnd = this.giConfig.cardColorEnd, cardBasePlateColor = this.giConfig.cardBasePlateColor, cardBasePlateBorder = this.giConfig.cardBasePlateBorder, } = {}) {
217
+ async generateDynamicImg(data, { cardColorStart = this.giConfig.cardColorStart, cardColorEnd = this.giConfig.cardColorEnd, cardBasePlateColor = this.giConfig.cardBasePlateColor, cardBasePlateBorder = this.giConfig.cardBasePlateBorder, } = {}) {
220
218
  // module_author
221
219
  const module_author = data.modules.module_author;
222
220
  const avatarUrl = module_author.face;
@@ -240,9 +238,7 @@ class GenerateImg extends koishi_1.Service {
240
238
  const topic = data.modules.module_dynamic.topic
241
239
  ? data.modules.module_dynamic.topic.name
242
240
  : "";
243
- const getDynamicMajor = async (
244
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
245
- dynamicMajorData, forward) => {
241
+ const getDynamicMajor = async (dynamic, forward) => {
246
242
  // 定义返回值
247
243
  let main = "";
248
244
  let link = "";
@@ -250,9 +246,9 @@ class GenerateImg extends koishi_1.Service {
250
246
  let forwardInfo;
251
247
  // 最基本的图文处理
252
248
  const basicDynamic = () => {
253
- const module_dynamic = dynamicMajorData.modules.module_dynamic;
254
- if (module_dynamic.desc) {
255
- const richText = module_dynamic.desc.rich_text_nodes.reduce((accumulator, currentValue) => {
249
+ const module_dynamic = dynamic.modules.module_dynamic;
250
+ if (module_dynamic.major.opus.summary) {
251
+ const richText = module_dynamic.major.opus.summary.rich_text_nodes.reduce((accumulator, currentValue) => {
256
252
  if (currentValue.emoji) {
257
253
  return /* html */ `${accumulator}<img style="width:28px; height:28px;" src="${currentValue.emoji.icon_url}"/>`;
258
254
  }
@@ -278,6 +274,7 @@ class GenerateImg extends koishi_1.Service {
278
274
  if (text) {
279
275
  main += /* html */ `
280
276
  <div class="card-details">
277
+ ${module_dynamic.major.opus.title ? `<h1 class="dyn-title">${module_dynamic.major.opus.title}</h1>` : ""}
281
278
  ${text}
282
279
  </div>
283
280
  `;
@@ -286,13 +283,13 @@ class GenerateImg extends koishi_1.Service {
286
283
  // 图片
287
284
  let major = "";
288
285
  const arrowImg = (0, node_url_1.pathToFileURL)((0, node_path_1.resolve)(__dirname, "img/arrow.png"));
289
- if (module_dynamic.major?.draw) {
290
- if (module_dynamic.major.draw.items.length === 1) {
291
- const height = module_dynamic.major.draw.items[0].height;
286
+ if (module_dynamic.major?.opus.pics) {
287
+ if (module_dynamic.major.opus.pics.length === 1) {
288
+ const height = module_dynamic.major.opus.pics[0].height;
292
289
  if (height > 3000) {
293
290
  major += /* html */ `
294
291
  <div class="single-photo-container">
295
- <img class="single-photo-item" src="${module_dynamic.major.draw.items[0].src}"/>
292
+ <img class="single-photo-item" src="${module_dynamic.major.opus.pics[0].url}"/>
296
293
  <div class="single-photo-mask">
297
294
  <span class="single-photo-mask-text">点击链接浏览全部</span>
298
295
  </div>
@@ -303,19 +300,19 @@ class GenerateImg extends koishi_1.Service {
303
300
  else {
304
301
  major += /* html */ `
305
302
  <div class="single-photo-container">
306
- <img class="single-photo-item" src="${module_dynamic.major.draw.items[0].src}"/>
303
+ <img class="single-photo-item" src="${module_dynamic.major.opus.pics[0].url}"/>
307
304
  </div>
308
305
  `;
309
306
  }
310
307
  }
311
- else if (module_dynamic.major.draw.items.length === 4) {
312
- major += module_dynamic.major.draw.items.reduce((acc, cV) => {
313
- return /* html */ `${acc}<img class="four-photo-item" src="${cV.src}"/>`;
308
+ else if (module_dynamic.major.opus.pics.length === 4) {
309
+ major += module_dynamic.major.opus.pics.reduce((acc, cV) => {
310
+ return /* html */ `${acc}<img class="four-photo-item" src="${cV.url}"/>`;
314
311
  }, "");
315
312
  }
316
313
  else {
317
- major += module_dynamic.major.draw.items.reduce((acc, cV) => {
318
- return /* html */ `${acc}<img class="photo-item" src="${cV.src}"/>`;
314
+ major += module_dynamic.major.opus.pics.reduce((acc, cV) => {
315
+ return /* html */ `${acc}<img class="photo-item" src="${cV.url}"/>`;
319
316
  }, "");
320
317
  }
321
318
  main += /* html */ `
@@ -326,25 +323,25 @@ class GenerateImg extends koishi_1.Service {
326
323
  }
327
324
  };
328
325
  // 判断动态类型
329
- switch (dynamicMajorData.type) {
326
+ switch (dynamic.type) {
330
327
  case DYNAMIC_TYPE_WORD:
331
328
  case DYNAMIC_TYPE_DRAW:
332
329
  case DYNAMIC_TYPE_FORWARD: {
333
330
  // DYNAMIC_TYPE_DRAW 带图动态 DYNAMIC_TYPE_WORD 文字动态 DYNAMIC_TYPE_FORWARD 转发动态
334
331
  basicDynamic();
335
332
  // 转发动态
336
- if (dynamicMajorData.type === DYNAMIC_TYPE_FORWARD) {
333
+ if (dynamic.type === DYNAMIC_TYPE_FORWARD) {
337
334
  //转发动态屏蔽
338
335
  if (this.giConfig.filter.enable && this.giConfig.filter.forward) {
339
336
  throw new Error("已屏蔽转发动态");
340
337
  }
341
338
  // User info
342
- const forward_module_author = dynamicMajorData.orig.modules.module_author;
339
+ const forward_module_author = dynamic.orig.modules.module_author;
343
340
  const forwardUserAvatarUrl = forward_module_author.face;
344
341
  const forwardUserName = forward_module_author.name;
345
342
  // 获取转发的动态
346
343
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
347
- const [forwardMain, _, forwardInfo] = await getDynamicMajor(dynamicMajorData.orig, true);
344
+ const [forwardMain, _, forwardInfo] = await getDynamicMajor(dynamic.orig, true);
348
345
  // 拼接main
349
346
  main += /* html */ `
350
347
  <div class="card-forward">
@@ -359,8 +356,8 @@ class GenerateImg extends koishi_1.Service {
359
356
  `;
360
357
  }
361
358
  // 判断是否有附加信息
362
- if (dynamicMajorData.modules.module_dynamic.additional) {
363
- const additional = dynamicMajorData.modules.module_dynamic.additional;
359
+ if (dynamic.modules.module_dynamic.additional) {
360
+ const additional = dynamic.modules.module_dynamic.additional;
364
361
  // 有附加信息,判断类型
365
362
  switch (additional.type) {
366
363
  case ADDITIONAL_TYPE_RESERVE: {
@@ -449,14 +446,14 @@ class GenerateImg extends koishi_1.Service {
449
446
  }
450
447
  }
451
448
  }
452
- link += `请将$替换为. www$bilibili$com/opus/${dynamicMajorData.id_str}`;
449
+ link += `请将$替换为. www$bilibili$com/opus/${dynamic.id_str}`;
453
450
  break;
454
451
  }
455
452
  case DYNAMIC_TYPE_AV: {
456
453
  // 投稿新视频
457
454
  // 处理文字
458
455
  basicDynamic();
459
- const archive = dynamicMajorData.modules.module_dynamic.major.archive;
456
+ const archive = dynamic.modules.module_dynamic.major.archive;
460
457
  if (archive.badge.text === "投稿视频") {
461
458
  if (forward) {
462
459
  forwardInfo = "投稿了视频";
@@ -676,6 +673,11 @@ class GenerateImg extends koishi_1.Service {
676
673
  top: 24px;
677
674
  }
678
675
 
676
+ .card .dyn-title {
677
+ font-size: 27px;
678
+ margin-bottom: 10px;
679
+ }
680
+
679
681
  .card .card-topic {
680
682
  display: flex;
681
683
  align-items: center;
@@ -1045,6 +1047,11 @@ class GenerateImg extends koishi_1.Service {
1045
1047
  top: 5px;
1046
1048
  }
1047
1049
 
1050
+ .card .dyn-title {
1051
+ font-size: 27px;
1052
+ margin-bottom: 10px;
1053
+ }
1054
+
1048
1055
  .card .card-topic {
1049
1056
  display: flex;
1050
1057
  align-items: center;
@@ -58,46 +58,110 @@ export type LiveUsers = {
58
58
  group: string;
59
59
  items: Array<LiveUsersItem>;
60
60
  };
61
- export type AllDynamicInfo = {
62
- code: number;
63
- message: string;
64
- data: {
65
- has_more: boolean;
66
- items: Array<{
67
- id_str: string;
61
+ export type Dynamic = {
62
+ basic: Object;
63
+ id_str: string;
64
+ modules: {
65
+ module_author: {
66
+ avatar: Object;
67
+ decorate: {
68
+ card_url: string;
69
+ fan: {
70
+ num_str: number;
71
+ color: string;
72
+ };
73
+ };
74
+ face: string;
75
+ face_nft: boolean;
76
+ following: boolean;
77
+ jump_url: string;
78
+ label: string;
79
+ mid: number;
80
+ name: string;
81
+ official_verify: Object;
82
+ pendant: Object;
83
+ pub_action: string;
84
+ pub_action_text: string;
85
+ pub_location_text: string;
86
+ pub_time: string;
87
+ pub_ts: number;
68
88
  type: string;
69
- modules: {
70
- module_author: {
71
- mid: number;
72
- name: string;
73
- face: string;
74
- pub_ts: number;
89
+ vip: {
90
+ type: number;
91
+ };
92
+ };
93
+ module_dynamic: {
94
+ additional: any;
95
+ desc: null;
96
+ major: {
97
+ opus: {
98
+ fold_action: Array<string>;
99
+ jump_url: string;
100
+ pics: Array<{
101
+ height: number;
102
+ live_url: string;
103
+ size: number;
104
+ url: string;
105
+ width: number;
106
+ }>;
107
+ summary: {
108
+ rich_text_nodes: Array<{
109
+ emoji?: {
110
+ icon_url: string;
111
+ size: number;
112
+ text: string;
113
+ type: number;
114
+ };
115
+ orig_text: string;
116
+ text: string;
117
+ type: string;
118
+ }>;
119
+ text: string;
120
+ };
121
+ title: string;
75
122
  };
76
- module_dynamic: {
77
- major: {
78
- draw?: {
79
- items: Array<{
80
- src: string;
81
- alt: string;
82
- }>;
83
- };
84
- archive?: {
85
- aid: string;
86
- badge: Object;
87
- bvid: string;
88
- cover: string;
89
- desc: string;
90
- disable_preview: number;
91
- duration_text: string;
92
- jump_url: string;
93
- stat: string;
94
- title: string;
95
- type: number;
96
- };
123
+ archive: {
124
+ jump_url: string;
125
+ badge: {
126
+ text: string;
127
+ };
128
+ cover: string;
129
+ duration_text: string;
130
+ title: string;
131
+ desc: string;
132
+ stat: {
133
+ play: number;
134
+ danmaku: number;
97
135
  };
136
+ bvid: string;
98
137
  };
138
+ draw: any;
139
+ type: string;
99
140
  };
100
- }>;
141
+ topic: any;
142
+ };
143
+ module_stat: {
144
+ comment: {
145
+ count: number;
146
+ };
147
+ forward: {
148
+ count: number;
149
+ };
150
+ like: {
151
+ count: number;
152
+ };
153
+ };
154
+ };
155
+ orig?: Dynamic;
156
+ type: string;
157
+ visible: boolean;
158
+ };
159
+ export type AllDynamicInfo = {
160
+ code: number;
161
+ message: string;
162
+ data: {
163
+ has_more: boolean;
164
+ items: Array<Dynamic>;
101
165
  offset: string;
102
166
  update_baseline: string;
103
167
  update_num: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-bilibili-notify",
3
3
  "description": "Koishi bilibili notify plugin",
4
- "version": "3.1.6",
4
+ "version": "3.1.7-alpha.1",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -243,6 +243,8 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
243
243
  - ver 3.1.5-alpha.3 修复:动态推送时报错:dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:Cannot read properties of undefined (reading 'card');
244
244
  - ver 3.1.5 修复:非 `debug` 模式下动态推送,如果在一个监测周期内同一个订阅的up主发送多条动态,下一个监测周期会重复推送;
245
245
  - ver 3.1.6 修复:视频类动态推送时,发送的视频链接有误;
246
+ - ver 3.1.7-alpha.0 修复:登录账号和订阅账号是同一个账号,动态不会推送,使用 `bili dyn` 指令,纯文本动态会被跳过; 新增:动态标题;
247
+ - ver 3.1.7-alpha.1 修复:启用自定义卡片样式后取消仍是自定义样式;
246
248
 
247
249
  ## 交流群
248
250