koishi-plugin-bilibili-notify 3.0.0-beta.1 → 3.0.0

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.
@@ -1,7 +1,7 @@
1
1
  import { type Bot, type Context, type FlatPick, type Logger, Schema } from "koishi";
2
2
  import type { Notifier } from "@koishijs/plugin-notifier";
3
3
  import type { LoginBili } from "./database";
4
- import { LiveType, type MasterInfo, type SubManager, type Target } from "./type";
4
+ import { LiveType, type MasterInfo, type SubItem, type SubManager, type Target } from "./type";
5
5
  declare class ComRegister {
6
6
  static inject: string[];
7
7
  qqRelatedBotList: Array<string>;
@@ -28,15 +28,9 @@ declare class ComRegister {
28
28
  sendMsg(targets: Target, content: any, live?: boolean): Promise<void>;
29
29
  dynamicDetect(): (...args: any[]) => void;
30
30
  debug_dynamicDetect(): (...args: any[]) => void;
31
- sendLiveNotifyCard(info: {
32
- username: string;
33
- userface: string;
34
- target: Target;
35
- data: any;
36
- }, liveType: LiveType, followerDisplay: string, liveNotifyMsg?: string): Promise<void>;
37
31
  useMasterInfo(uid: string, masterInfo: MasterInfo, liveType: LiveType): Promise<MasterInfo>;
38
32
  useLiveRoomInfo(roomId: string): Promise<any>;
39
- liveDetectWithListener(roomId: string, target: Target): Promise<void>;
33
+ liveDetectWithListener(roomId: string, target: Target, cardStyle: SubItem["card"]): Promise<void>;
40
34
  subShow(): string;
41
35
  updateSubNotifier(): void;
42
36
  checkIfLoginInfoIsLoaded(): Promise<unknown>;
@@ -65,6 +59,13 @@ declare namespace ComRegister {
65
59
  }>;
66
60
  platform: string;
67
61
  }>;
62
+ card: {
63
+ enable: boolean;
64
+ cardColorStart: string;
65
+ cardColorEnd: string;
66
+ cardBasePlateColor: string;
67
+ cardBasePlateBorder: string;
68
+ };
68
69
  }>;
69
70
  master: {
70
71
  enable: boolean;
@@ -590,7 +590,7 @@ class ComRegister {
590
590
  // 推送该条动态
591
591
  const buffer = await (0, utils_1.withRetry)(async () => {
592
592
  // 渲染图片
593
- return await this.ctx.gi.generateDynamicImg(items[num]);
593
+ return await this.ctx.gi.generateDynamicImg(items[num], sub.card);
594
594
  }, 1).catch(async (e) => {
595
595
  // 直播开播动态,不做处理
596
596
  if (e.message === "直播开播动态,不做处理")
@@ -778,7 +778,7 @@ class ComRegister {
778
778
  // 推送该条动态
779
779
  const buffer = await (0, utils_1.withRetry)(async () => {
780
780
  // 渲染图片
781
- return await this.ctx.gi.generateDynamicImg(items[num]);
781
+ return await this.ctx.gi.generateDynamicImg(items[num], sub.card);
782
782
  }, 1).catch(async (e) => {
783
783
  // 直播开播动态,不做处理
784
784
  if (e.message === "直播开播动态,不做处理")
@@ -837,23 +837,6 @@ class ComRegister {
837
837
  // 加工handler并返回
838
838
  return (0, utils_1.withLock)(handler);
839
839
  }
840
- // 定义发送直播通知卡片方法
841
- async sendLiveNotifyCard(info, liveType, followerDisplay, liveNotifyMsg) {
842
- // 生成图片
843
- const buffer = await (0, utils_1.withRetry)(async () => {
844
- // 获取直播通知卡片
845
- return await this.ctx.gi.generateLiveImg(info.data, info.username, info.userface, followerDisplay, liveType);
846
- }, 1).catch((e) => {
847
- this.logger.error(`liveDetect generateLiveImg() 推送卡片生成失败,原因:${e.message}`);
848
- });
849
- // 发送私聊消息并重启服务
850
- if (!buffer)
851
- return await this.sendPrivateMsgAndStopService();
852
- // 推送直播信息
853
- const msg = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/png"), liveNotifyMsg || ""] }));
854
- // 只有在开播时才艾特全体成员
855
- return await this.sendMsg(info.target, msg, liveType === type_1.LiveType.StartBroadcasting);
856
- }
857
840
  // 定义获取主播信息方法
858
841
  async useMasterInfo(uid, masterInfo, liveType) {
859
842
  // 获取主播信息
@@ -906,7 +889,7 @@ class ComRegister {
906
889
  // 返回
907
890
  return data;
908
891
  }
909
- async liveDetectWithListener(roomId, target) {
892
+ async liveDetectWithListener(roomId, target, cardStyle) {
910
893
  // 定义开播时间
911
894
  let liveTime;
912
895
  // 定义定时推送定时器
@@ -923,6 +906,23 @@ class ComRegister {
923
906
  let liveRoomInfo;
924
907
  let masterInfo;
925
908
  let watchedNum;
909
+ // 定义发送直播通知卡片方法
910
+ const sendLiveNotifyCard = async (liveType, followerDisplay, liveNotifyMsg) => {
911
+ // 生成图片
912
+ const buffer = await (0, utils_1.withRetry)(async () => {
913
+ // 获取直播通知卡片
914
+ return await this.ctx.gi.generateLiveImg(liveRoomInfo, masterInfo.username, masterInfo.userface, followerDisplay, liveType, cardStyle);
915
+ }, 1).catch((e) => {
916
+ this.logger.error(`liveDetect generateLiveImg() 推送卡片生成失败,原因:${e.message}`);
917
+ });
918
+ // 发送私聊消息并重启服务
919
+ if (!buffer)
920
+ return await this.sendPrivateMsgAndStopService();
921
+ // 推送直播信息
922
+ const msg = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/png"), liveNotifyMsg || ""] }));
923
+ // 只有在开播时才艾特全体成员
924
+ return await this.sendMsg(target, msg, liveType === type_1.LiveType.StartBroadcasting);
925
+ };
926
926
  // 找到频道/群组对应的
927
927
  const liveGuardBuyPushTargetArr = target.map((channel) => {
928
928
  // 获取符合条件的target
@@ -955,12 +955,7 @@ class ComRegister {
955
955
  .replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
956
956
  : null;
957
957
  // 发送直播通知卡片
958
- await this.sendLiveNotifyCard({
959
- username: masterInfo.username,
960
- userface: masterInfo.userface,
961
- target,
962
- data: liveRoomInfo,
963
- }, type_1.LiveType.LiveBroadcast, watched, liveMsg);
958
+ await sendLiveNotifyCard(type_1.LiveType.LiveBroadcast, watched, liveMsg);
964
959
  };
965
960
  // 定义直播间信息获取函数
966
961
  const useMasterAndLiveRoomInfo = async (liveType) => {
@@ -1038,12 +1033,7 @@ class ComRegister {
1038
1033
  .replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
1039
1034
  : null;
1040
1035
  // 推送开播通知
1041
- await this.sendLiveNotifyCard({
1042
- username: masterInfo.username,
1043
- userface: masterInfo.userface,
1044
- target,
1045
- data: liveRoomInfo,
1046
- }, type_1.LiveType.StartBroadcasting, follower, liveStartMsg);
1036
+ await sendLiveNotifyCard(type_1.LiveType.StartBroadcasting, follower, liveStartMsg);
1047
1037
  // 判断定时器是否已开启
1048
1038
  if (!pushAtTimeTimer) {
1049
1039
  // 开始直播,开启定时器
@@ -1084,12 +1074,7 @@ class ComRegister {
1084
1074
  .replace("-follower_change", followerChange)
1085
1075
  : null;
1086
1076
  // 推送通知卡片
1087
- await this.sendLiveNotifyCard({
1088
- username: masterInfo.username,
1089
- userface: masterInfo.userface,
1090
- target,
1091
- data: liveRoomInfo,
1092
- }, type_1.LiveType.StopBroadcast, followerChange, liveEndMsg);
1077
+ await sendLiveNotifyCard(type_1.LiveType.StopBroadcast, followerChange, liveEndMsg);
1093
1078
  // 关闭定时推送定时器
1094
1079
  pushAtTimeTimer();
1095
1080
  // 将推送定时器变量置空
@@ -1119,12 +1104,7 @@ class ComRegister {
1119
1104
  : null;
1120
1105
  // 发送直播通知卡片
1121
1106
  if (this.config.restartPush) {
1122
- await this.sendLiveNotifyCard({
1123
- username: masterInfo.username,
1124
- userface: masterInfo.userface,
1125
- target,
1126
- data: liveRoomInfo,
1127
- }, type_1.LiveType.LiveBroadcast, watched, liveMsg);
1107
+ await sendLiveNotifyCard(type_1.LiveType.LiveBroadcast, watched, liveMsg);
1128
1108
  }
1129
1109
  // 正在直播,开启定时器,判断定时器是否已开启
1130
1110
  if (!pushAtTimeTimer) {
@@ -1311,7 +1291,7 @@ class ComRegister {
1311
1291
  // 判断是否订阅直播
1312
1292
  if (sub.live) {
1313
1293
  // 启动直播监测
1314
- await this.liveDetectWithListener(data.live_room.roomid, sub.target);
1294
+ await this.liveDetectWithListener(data.live_room.roomid, sub.target, sub.card);
1315
1295
  }
1316
1296
  }
1317
1297
  // 在B站中订阅该对象
@@ -1329,6 +1309,7 @@ class ComRegister {
1329
1309
  platform: "",
1330
1310
  live: sub.live,
1331
1311
  dynamic: sub.dynamic,
1312
+ card: sub.card,
1332
1313
  });
1333
1314
  this.logger.info(`UID:${sub.uid}订阅加载完毕!`);
1334
1315
  }
@@ -1375,6 +1356,13 @@ class ComRegister {
1375
1356
  })).description("频道/群组信息"),
1376
1357
  platform: koishi_1.Schema.string().description("推送平台"),
1377
1358
  })).description("订阅用户需要发送的频道/群组信息"),
1359
+ card: koishi_1.Schema.object({
1360
+ enable: koishi_1.Schema.boolean(),
1361
+ cardColorStart: koishi_1.Schema.string(),
1362
+ cardColorEnd: koishi_1.Schema.string(),
1363
+ cardBasePlateColor: koishi_1.Schema.string(),
1364
+ cardBasePlateBorder: koishi_1.Schema.string(),
1365
+ }).description("自定义推送卡片颜色,默认使用插件内置的颜色,设置后会覆盖插件内置的颜色"),
1378
1366
  }))
1379
1367
  .role("table")
1380
1368
  .description("手动输入订阅信息,方便自定义订阅内容,这里的订阅内容不会存入数据库。uid: 订阅用户UID,dynamic: 是否需要订阅动态,live: 是否需要订阅直播"),
@@ -9,8 +9,18 @@ declare class GenerateImg extends Service {
9
9
  giConfig: GenerateImg.Config;
10
10
  constructor(ctx: Context, config: GenerateImg.Config);
11
11
  imgHandler(html: string): Promise<Buffer<ArrayBufferLike>>;
12
- generateLiveImg(data: any, username: string, userface: string, followerDisplay: string, liveStatus: number): Promise<Buffer<ArrayBufferLike>>;
13
- generateDynamicImg(data: any): Promise<Buffer<ArrayBufferLike>>;
12
+ generateLiveImg(data: any, username: string, userface: string, followerDisplay: string, liveStatus: number, { cardColorStart, cardColorEnd, cardBasePlateColor, cardBasePlateBorder, }: {
13
+ cardColorStart?: string;
14
+ cardColorEnd?: string;
15
+ cardBasePlateColor?: string;
16
+ cardBasePlateBorder?: string;
17
+ }): Promise<Buffer<ArrayBufferLike>>;
18
+ generateDynamicImg(data: any, { cardColorStart, cardColorEnd, cardBasePlateColor, cardBasePlateBorder, }: {
19
+ cardColorStart?: string;
20
+ cardColorEnd?: string;
21
+ cardBasePlateColor?: string;
22
+ cardBasePlateBorder?: string;
23
+ }): Promise<Buffer<ArrayBufferLike>>;
14
24
  getLiveStatus(time: string, liveStatus: number): Promise<[string, string, boolean]>;
15
25
  getTimeDifference(dateString: string): Promise<string>;
16
26
  unixTimestampToString(timestamp: number): string;
@@ -51,7 +51,7 @@ class GenerateImg extends koishi_1.Service {
51
51
  }
52
52
  async generateLiveImg(
53
53
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
54
- data, username, userface, followerDisplay, liveStatus /*0未开播 1刚开播 2已开播 3停止直播*/) {
54
+ data, username, userface, followerDisplay, liveStatus /*0未开播 1刚开播 2已开播 3停止直播*/, { cardColorStart = this.giConfig.cardColorStart, cardColorEnd = this.giConfig.cardColorEnd, cardBasePlateColor = this.giConfig.cardBasePlateColor, cardBasePlateBorder = this.giConfig.cardBasePlateBorder, }) {
55
55
  const [titleStatus, liveTime, cover] = await this.getLiveStatus(data.live_time, liveStatus);
56
56
  // 加载字体
57
57
  const fontURL = (0, node_url_1.pathToFileURL)((0, node_path_1.resolve)(__dirname, "font/HYZhengYuan-75W.ttf"));
@@ -83,7 +83,7 @@ class GenerateImg extends koishi_1.Service {
83
83
  width: 100%;
84
84
  height: auto;
85
85
  padding: 15px;
86
- background: linear-gradient(to right bottom, ${this.giConfig.cardColorStart}, ${this.giConfig.cardColorEnd});
86
+ background: linear-gradient(to right bottom, ${cardColorStart}, ${cardColorEnd});
87
87
  overflow: hidden;
88
88
  }
89
89
 
@@ -91,11 +91,11 @@ class GenerateImg extends koishi_1.Service {
91
91
  width: 100%;
92
92
  height: auto;
93
93
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
94
- padding: ${this.giConfig.cardBasePlateBorder};
94
+ padding: ${cardBasePlateBorder};
95
95
  border-radius: 10px;
96
- background-color: ${this.giConfig.cardBasePlateColor};
96
+ background-color: ${cardBasePlateColor};
97
97
  }
98
-
98
+
99
99
  .card {
100
100
  width: 100%;
101
101
  height: auto;
@@ -214,8 +214,9 @@ class GenerateImg extends koishi_1.Service {
214
214
  throw new Error(`生成图片失败!错误: ${e.toString()}`);
215
215
  });
216
216
  }
217
+ async generateDynamicImg(
217
218
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
218
- async generateDynamicImg(data) {
219
+ data, { cardColorStart = this.giConfig.cardColorStart, cardColorEnd = this.giConfig.cardColorEnd, cardBasePlateColor = this.giConfig.cardBasePlateColor, cardBasePlateBorder = this.giConfig.cardBasePlateBorder, }) {
219
220
  // module_author
220
221
  const module_author = data.modules.module_author;
221
222
  const avatarUrl = module_author.face;
@@ -288,7 +289,6 @@ class GenerateImg extends koishi_1.Service {
288
289
  if (module_dynamic.major?.draw) {
289
290
  if (module_dynamic.major.draw.items.length === 1) {
290
291
  const height = module_dynamic.major.draw.items[0].height;
291
- console.log(height);
292
292
  if (height > 3000) {
293
293
  major += /* html */ `
294
294
  <div class="single-photo-container">
@@ -586,7 +586,7 @@ class GenerateImg extends koishi_1.Service {
586
586
  width: 100%;
587
587
  height: auto;
588
588
  padding: 15px;
589
- background: linear-gradient(to right bottom, ${this.giConfig.cardColorStart}, ${this.giConfig.cardColorEnd});
589
+ background: linear-gradient(to right bottom, ${cardColorStart}, ${cardColorEnd});
590
590
  overflow: hidden;
591
591
  }
592
592
 
@@ -594,9 +594,9 @@ class GenerateImg extends koishi_1.Service {
594
594
  width: 100%;
595
595
  height: auto;
596
596
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
597
- padding: ${this.giConfig.cardBasePlateBorder};
597
+ padding: ${cardBasePlateBorder};
598
598
  border-radius: 10px;
599
- background-color: ${this.giConfig.cardBasePlateColor};
599
+ background-color: ${cardBasePlateColor};
600
600
  }
601
601
 
602
602
  .card {
@@ -951,7 +951,7 @@ class GenerateImg extends koishi_1.Service {
951
951
  width: 100%;
952
952
  height: auto;
953
953
  padding: 15px;
954
- background: linear-gradient(to right bottom, ${this.giConfig.cardColorStart}, ${this.giConfig.cardColorEnd});
954
+ background: linear-gradient(to right bottom, ${cardColorStart}, ${cardColorEnd});
955
955
  overflow: hidden;
956
956
  }
957
957
 
@@ -959,9 +959,9 @@ class GenerateImg extends koishi_1.Service {
959
959
  width: 100%;
960
960
  height: auto;
961
961
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
962
- padding: ${this.giConfig.cardBasePlateBorder};
962
+ padding: ${cardBasePlateBorder};
963
963
  border-radius: 10px;
964
- background-color: ${this.giConfig.cardBasePlateColor};
964
+ background-color: ${cardBasePlateColor};
965
965
  }
966
966
 
967
967
  .card {
package/lib/index.d.ts CHANGED
@@ -36,6 +36,7 @@ export interface Config {
36
36
  uid: string;
37
37
  dynamic: boolean;
38
38
  live: boolean;
39
+ card: {};
39
40
  target: Array<{
40
41
  channelIdArr: Array<{
41
42
  channelId: string;
package/lib/index.js CHANGED
@@ -303,6 +303,32 @@ exports.Config = koishi_1.Schema.object({
303
303
  .required()
304
304
  .description("需推送的频道/群组详细设置"),
305
305
  })).description("订阅用户需要发送的平台和频道/群组信息(一个平台下可以推送多个频道/群组)"),
306
+ card: koishi_1.Schema.intersect([
307
+ koishi_1.Schema.object({
308
+ enable: koishi_1.Schema.boolean()
309
+ .default(false)
310
+ .description("是否开启自定义卡片颜色")
311
+ .experimental(),
312
+ }),
313
+ koishi_1.Schema.union([
314
+ koishi_1.Schema.object({
315
+ enable: koishi_1.Schema.const(true).required(),
316
+ cardColorStart: koishi_1.Schema.string()
317
+ .pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
318
+ .description("推送卡片的开始渐变背景色,请填入16进制颜色代码,参考网站:https://webkul.github.io/coolhue/"),
319
+ cardColorEnd: koishi_1.Schema.string()
320
+ .pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
321
+ .description("推送卡片的结束渐变背景色,请填入16进制颜色代码,参考网站:https://colorate.azurewebsites.net/"),
322
+ cardBasePlateColor: koishi_1.Schema.string()
323
+ .pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
324
+ .description("推送卡片底板颜色,请填入16进制颜色代码"),
325
+ cardBasePlateBorder: koishi_1.Schema.string()
326
+ .pattern(/\d*\.?\d+(?:px|em|rem|%|vh|vw|vmin|vmax)/)
327
+ .description("推送卡片底板边框宽度,请填入css单位,例如1px,12.5rem,100%"),
328
+ }),
329
+ koishi_1.Schema.object({}),
330
+ ]),
331
+ ]),
306
332
  }).collapse())
307
333
  .collapse()
308
334
  .description("输入订阅信息,自定义订阅内容; uid: 订阅用户UID,dynamic: 是否需要订阅动态,live: 是否需要订阅直播"),
@@ -26,6 +26,13 @@ export type SubItem = {
26
26
  platform: string;
27
27
  live: boolean;
28
28
  dynamic: boolean;
29
+ card: {
30
+ enable: boolean;
31
+ cardColorStart: string;
32
+ cardColorEnd: string;
33
+ cardBasePlateColor: string;
34
+ cardBasePlateBorder: string;
35
+ };
29
36
  };
30
37
  export type SubManager = Array<SubItem>;
31
38
  export type MasterInfo = {
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.0.0-beta.1",
4
+ "version": "3.0.0",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -211,6 +211,8 @@
211
211
  - ver 3.0.0-alpha.25 修复:输入指令 `bili ll` 时报错 `TypeError: Cannot read properties of null (reading 'items')`,当某个订阅只订阅动态时无法成功订阅且后续订阅都无法加载; 优化:部分代码结构
212
212
  - ver 3.0.0-beta.0 移除:配置项 `renderType`,推送卡片渲染模式 `render`,现默认为 `page` 渲染模式; 优化:部分代码结构
213
213
  - ver 3.0.0-beta.1 修复:使用动态屏蔽时,同时开启动态debug模式,当检测到屏蔽动态时会直接报错关闭插件; 新增:配置项 `pushImgsInDynamic` 是否推送动态中的图片,默认不开启。开启后会单独推送动态中的图片,上舰信息直播间提示
214
+ - ver 3.0.0-beta.2 新增:配置项 `sub.card`,能更改每个订阅的推送卡片样式,未更改的样式与全局样式保持一致
215
+ - ver 3.0.0 优化:配置项 `sub.card` 添加实验性标识
214
216
 
215
217
  ## 交流群
216
218