koishi-plugin-bilibili-notify 3.2.0-alpha.3 → 3.2.0-alpha.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.
- package/lib/comRegister.js +29 -6
- package/lib/generateImg.d.ts +2 -1
- package/lib/generateImg.js +55 -51
- package/lib/type/index.d.ts +33 -12
- package/package.json +1 -1
- package/readme.md +2 -0
package/lib/comRegister.js
CHANGED
|
@@ -273,9 +273,32 @@ class ComRegister {
|
|
|
273
273
|
// 获取动态内容
|
|
274
274
|
const item = content.data.items[i];
|
|
275
275
|
// 生成图片
|
|
276
|
-
const buffer = await
|
|
276
|
+
const buffer = await (0, utils_1.withRetry)(async () => {
|
|
277
|
+
// 渲染图片
|
|
278
|
+
return await this.ctx.gi.generateDynamicImg(item);
|
|
279
|
+
}, 1).catch(async (e) => {
|
|
280
|
+
// 直播开播动态,不做处理
|
|
281
|
+
if (e.message === "直播开播动态,不做处理") {
|
|
282
|
+
await session.send("直播开播动态,不做处理");
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (e.message === "出现关键词,屏蔽该动态") {
|
|
286
|
+
await session.send("已屏蔽该动态");
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (e.message === "已屏蔽转发动态") {
|
|
290
|
+
await session.send("已屏蔽转发动态");
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (e.message === "已屏蔽专栏动态") {
|
|
294
|
+
await session.send("已屏蔽专栏动态");
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
// 未知错误
|
|
298
|
+
this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
|
|
299
|
+
});
|
|
277
300
|
// 发送图片
|
|
278
|
-
await session.send(koishi_1.h.image(buffer, "image/jpeg"));
|
|
301
|
+
buffer && (await session.send(koishi_1.h.image(buffer, "image/jpeg")));
|
|
279
302
|
});
|
|
280
303
|
}
|
|
281
304
|
async init(config) {
|
|
@@ -1264,7 +1287,7 @@ class ComRegister {
|
|
|
1264
1287
|
? this.config.customLive
|
|
1265
1288
|
.replace("-name", liveStatus.masterInfo.username)
|
|
1266
1289
|
.replace("-time", await this.ctx.gi.getTimeDifference(liveStatus.liveStartTime))
|
|
1267
|
-
.replace("-watched", "")
|
|
1290
|
+
.replace("-watched", "API模式无法获取")
|
|
1268
1291
|
.replace("\\n", "\n")
|
|
1269
1292
|
.replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`)
|
|
1270
1293
|
: null;
|
|
@@ -1387,7 +1410,7 @@ class ComRegister {
|
|
|
1387
1410
|
}
|
|
1388
1411
|
if (liveStatus.live === true) {
|
|
1389
1412
|
// 还在直播
|
|
1390
|
-
if (liveStatus.push < (this.config.pushTime * 60 * 60) /
|
|
1413
|
+
if (liveStatus.push < (this.config.pushTime * 60 * 60) / 30) {
|
|
1391
1414
|
// push++
|
|
1392
1415
|
liveStatus.push++;
|
|
1393
1416
|
// 结束本次循环
|
|
@@ -1412,7 +1435,7 @@ class ComRegister {
|
|
|
1412
1435
|
? this.config.customLive
|
|
1413
1436
|
.replace("-name", liveStatus.masterInfo.username)
|
|
1414
1437
|
.replace("-time", await this.ctx.gi.getTimeDifference(liveStatus.liveStartTime))
|
|
1415
|
-
.replace("-watched", "")
|
|
1438
|
+
.replace("-watched", "API模式无法获取")
|
|
1416
1439
|
.replace("\\n", "\n")
|
|
1417
1440
|
.replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`)
|
|
1418
1441
|
: null;
|
|
@@ -1739,7 +1762,7 @@ class ComRegister {
|
|
|
1739
1762
|
}
|
|
1740
1763
|
async enableLiveDetect() {
|
|
1741
1764
|
// 定义Job
|
|
1742
|
-
this.liveJob = new cron_1.CronJob("*/
|
|
1765
|
+
this.liveJob = new cron_1.CronJob("*/30 * * * * *", await this.liveDetectWithAPI());
|
|
1743
1766
|
// logger
|
|
1744
1767
|
this.logger.info("直播监测已开启");
|
|
1745
1768
|
// 开始直播监测
|
package/lib/generateImg.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Context, Schema, Service } from "koishi";
|
|
2
|
-
import type { Dynamic } from "./type";
|
|
2
|
+
import type { Dynamic, RichTextNode } from "./type";
|
|
3
3
|
declare module "koishi" {
|
|
4
4
|
interface Context {
|
|
5
5
|
gi: GenerateImg;
|
|
@@ -16,6 +16,7 @@ declare class GenerateImg extends Service {
|
|
|
16
16
|
cardBasePlateColor?: string;
|
|
17
17
|
cardBasePlateBorder?: string;
|
|
18
18
|
}): Promise<Buffer<ArrayBufferLike>>;
|
|
19
|
+
richTextParser(rt: RichTextNode, title?: string): string;
|
|
19
20
|
generateDynamicImg(data: Dynamic, { cardColorStart, cardColorEnd, cardBasePlateColor, cardBasePlateBorder, }?: {
|
|
20
21
|
cardColorStart?: string;
|
|
21
22
|
cardColorEnd?: string;
|
package/lib/generateImg.js
CHANGED
|
@@ -194,7 +194,7 @@ class GenerateImg extends koishi_1.Service {
|
|
|
194
194
|
${liveStatus === 1
|
|
195
195
|
? `当前粉丝数:${followerDisplay}`
|
|
196
196
|
: liveStatus === 2
|
|
197
|
-
? `${followerDisplay !== "API" ?
|
|
197
|
+
? `${followerDisplay !== "API" ? `累计观看人数:${followerDisplay}` : ""}`
|
|
198
198
|
: liveStatus === 3
|
|
199
199
|
? `粉丝数变化:${followerDisplay}`
|
|
200
200
|
: ""}
|
|
@@ -214,6 +214,37 @@ class GenerateImg extends koishi_1.Service {
|
|
|
214
214
|
throw new Error(`生成图片失败!错误: ${e.toString()}`);
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
|
+
richTextParser(rt, title) {
|
|
218
|
+
const richText = rt.reduce((accumulator, currentValue) => {
|
|
219
|
+
if (currentValue.emoji) {
|
|
220
|
+
return /* html */ `${accumulator}<img style="width:28px; height:28px;" src="${currentValue.emoji.icon_url}"/>`;
|
|
221
|
+
}
|
|
222
|
+
return accumulator + currentValue.text;
|
|
223
|
+
}, "");
|
|
224
|
+
// 关键字和正则屏蔽
|
|
225
|
+
if (this.giConfig.filter.enable) {
|
|
226
|
+
// 开启动态屏蔽功能
|
|
227
|
+
if (this.giConfig.filter.regex) {
|
|
228
|
+
// 正则屏蔽
|
|
229
|
+
const reg = new RegExp(this.giConfig.filter.regex);
|
|
230
|
+
if (reg.test(richText))
|
|
231
|
+
throw new Error("出现关键词,屏蔽该动态");
|
|
232
|
+
}
|
|
233
|
+
if (this.giConfig.filter.keywords.length !== 0 &&
|
|
234
|
+
this.giConfig.filter.keywords.some((keyword) => richText.includes(keyword))) {
|
|
235
|
+
throw new Error("出现关键词,屏蔽该动态");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// 查找\n
|
|
239
|
+
const text = richText.replace(/\n/g, "<br>");
|
|
240
|
+
// 拼接字符串
|
|
241
|
+
return /* html */ `
|
|
242
|
+
<div class="card-details">
|
|
243
|
+
${title ? `<h1 class="dyn-title">${title}</h1>` : ""}
|
|
244
|
+
${text}
|
|
245
|
+
</div>
|
|
246
|
+
`;
|
|
247
|
+
}
|
|
217
248
|
async generateDynamicImg(data, { cardColorStart = this.giConfig.cardColorStart, cardColorEnd = this.giConfig.cardColorEnd, cardBasePlateColor = this.giConfig.cardBasePlateColor, cardBasePlateBorder = this.giConfig.cardBasePlateBorder, } = {}) {
|
|
218
249
|
// module_author
|
|
219
250
|
const module_author = data.modules.module_author;
|
|
@@ -241,44 +272,21 @@ class GenerateImg extends koishi_1.Service {
|
|
|
241
272
|
const getDynamicMajor = async (dynamic, forward) => {
|
|
242
273
|
// 定义返回值
|
|
243
274
|
let main = "";
|
|
244
|
-
let link = "";
|
|
245
275
|
// 定义forward类型返回值
|
|
246
276
|
let forwardInfo;
|
|
247
277
|
// 最基本的图文处理
|
|
248
278
|
const basicDynamic = () => {
|
|
279
|
+
// 获取动态内容
|
|
249
280
|
const module_dynamic = dynamic.modules.module_dynamic;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
// 开启动态屏蔽功能
|
|
260
|
-
if (this.giConfig.filter.regex) {
|
|
261
|
-
// 正则屏蔽
|
|
262
|
-
const reg = new RegExp(this.giConfig.filter.regex);
|
|
263
|
-
if (reg.test(richText))
|
|
264
|
-
throw new Error("出现关键词,屏蔽该动态");
|
|
265
|
-
}
|
|
266
|
-
if (this.giConfig.filter.keywords.length !== 0 &&
|
|
267
|
-
this.giConfig.filter.keywords.some((keyword) => richText.includes(keyword))) {
|
|
268
|
-
throw new Error("出现关键词,屏蔽该动态");
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
// 查找\n
|
|
272
|
-
const text = richText.replace(/\n/g, "<br>");
|
|
273
|
-
// 拼接字符串
|
|
274
|
-
if (text) {
|
|
275
|
-
main += /* html */ `
|
|
276
|
-
<div class="card-details">
|
|
277
|
-
${module_dynamic.major.opus.title ? `<h1 class="dyn-title">${module_dynamic.major.opus.title}</h1>` : ""}
|
|
278
|
-
${text}
|
|
279
|
-
</div>
|
|
280
|
-
`;
|
|
281
|
-
}
|
|
281
|
+
// 判断是否有desc
|
|
282
|
+
if (module_dynamic?.desc?.rich_text_nodes) {
|
|
283
|
+
const content = this.richTextParser(module_dynamic.desc.rich_text_nodes);
|
|
284
|
+
main += content;
|
|
285
|
+
}
|
|
286
|
+
// 判断是否有summary
|
|
287
|
+
if (module_dynamic?.major?.opus?.summary?.rich_text_nodes) {
|
|
288
|
+
const content = this.richTextParser(module_dynamic.major.opus.summary.rich_text_nodes, module_dynamic.major.opus.title);
|
|
289
|
+
main += content;
|
|
282
290
|
}
|
|
283
291
|
// 图片
|
|
284
292
|
let major = "";
|
|
@@ -341,7 +349,7 @@ class GenerateImg extends koishi_1.Service {
|
|
|
341
349
|
const forwardUserName = forward_module_author.name;
|
|
342
350
|
// 获取转发的动态
|
|
343
351
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
344
|
-
const [forwardMain,
|
|
352
|
+
const [forwardMain, forwardInfo] = await getDynamicMajor(dynamic.orig, true);
|
|
345
353
|
// 拼接main
|
|
346
354
|
main += /* html */ `
|
|
347
355
|
<div class="card-forward">
|
|
@@ -446,7 +454,6 @@ class GenerateImg extends koishi_1.Service {
|
|
|
446
454
|
}
|
|
447
455
|
}
|
|
448
456
|
}
|
|
449
|
-
link += `请将$替换为. www$bilibili$com/opus/${dynamic.id_str}`;
|
|
450
457
|
break;
|
|
451
458
|
}
|
|
452
459
|
case DYNAMIC_TYPE_AV: {
|
|
@@ -519,48 +526,45 @@ class GenerateImg extends koishi_1.Service {
|
|
|
519
526
|
</div>
|
|
520
527
|
</div>
|
|
521
528
|
`;
|
|
522
|
-
link = `请将$替换为. www$bilibili$com/video/${archive.bvid}`;
|
|
523
529
|
break;
|
|
524
530
|
}
|
|
525
531
|
case DYNAMIC_TYPE_LIVE:
|
|
526
|
-
return [`${upName}
|
|
532
|
+
return [`${upName}发起了直播预约,我暂时无法渲染,请自行查看`];
|
|
527
533
|
case DYNAMIC_TYPE_MEDIALIST:
|
|
528
|
-
return [`${upName}
|
|
534
|
+
return [`${upName}分享了收藏夹,我暂时无法渲染,请自行查看`];
|
|
529
535
|
case DYNAMIC_TYPE_PGC:
|
|
530
536
|
return [
|
|
531
537
|
`${upName}发布了剧集(番剧、电影、纪录片),我暂时无法渲染,请自行查看`,
|
|
532
|
-
link,
|
|
533
538
|
];
|
|
534
539
|
case DYNAMIC_TYPE_ARTICLE: {
|
|
535
540
|
//转发动态屏蔽
|
|
536
541
|
if (this.giConfig.filter.enable && this.giConfig.filter.article) {
|
|
537
542
|
throw new Error("已屏蔽专栏动态");
|
|
538
543
|
}
|
|
539
|
-
return [`${upName}
|
|
544
|
+
return [`${upName}投稿了新专栏,我暂时无法渲染,请自行查看`];
|
|
540
545
|
}
|
|
541
546
|
case DYNAMIC_TYPE_MUSIC:
|
|
542
|
-
return [`${upName}
|
|
547
|
+
return [`${upName}发行了新歌,我暂时无法渲染,请自行查看`];
|
|
543
548
|
case DYNAMIC_TYPE_COMMON_SQUARE:
|
|
544
549
|
return [
|
|
545
550
|
`${upName}发布了装扮|剧集|点评|普通分享,我暂时无法渲染,请自行查看`,
|
|
546
|
-
link,
|
|
547
551
|
];
|
|
548
552
|
case DYNAMIC_TYPE_COURSES_SEASON:
|
|
549
|
-
return [`${upName}
|
|
553
|
+
return [`${upName}发布了新课程,我暂时无法渲染,请自行查看`];
|
|
550
554
|
case DYNAMIC_TYPE_UGC_SEASON:
|
|
551
|
-
return [`${upName}
|
|
555
|
+
return [`${upName}更新了合集,我暂时无法渲染,请自行查看`];
|
|
552
556
|
case DYNAMIC_TYPE_NONE:
|
|
553
|
-
return [`${upName}
|
|
557
|
+
return [`${upName}发布了一条无效动态`];
|
|
554
558
|
// 直播开播,不做处理
|
|
555
559
|
case DYNAMIC_TYPE_LIVE_RCMD:
|
|
556
560
|
throw new Error("直播开播动态,不做处理");
|
|
557
561
|
default:
|
|
558
|
-
return [`${upName}
|
|
562
|
+
return [`${upName}发布了一条我无法识别的动态,请自行查看`];
|
|
559
563
|
}
|
|
560
|
-
return [main,
|
|
564
|
+
return [main, forwardInfo];
|
|
561
565
|
};
|
|
562
566
|
// 获取动态主要内容
|
|
563
|
-
const [main
|
|
567
|
+
const [main] = await getDynamicMajor(data, false);
|
|
564
568
|
// 加载字体
|
|
565
569
|
const fontURL = (0, node_url_1.pathToFileURL)((0, node_path_1.resolve)(__dirname, "font/HYZhengYuan-75W.ttf"));
|
|
566
570
|
// 判断是否开启大字体模式
|
|
@@ -674,7 +678,7 @@ class GenerateImg extends koishi_1.Service {
|
|
|
674
678
|
}
|
|
675
679
|
|
|
676
680
|
.card .dyn-title {
|
|
677
|
-
font-size:
|
|
681
|
+
font-size: 20px;
|
|
678
682
|
margin-bottom: 10px;
|
|
679
683
|
}
|
|
680
684
|
|
|
@@ -1048,7 +1052,7 @@ class GenerateImg extends koishi_1.Service {
|
|
|
1048
1052
|
}
|
|
1049
1053
|
|
|
1050
1054
|
.card .dyn-title {
|
|
1051
|
-
font-size:
|
|
1055
|
+
font-size: 20px;
|
|
1052
1056
|
margin-bottom: 10px;
|
|
1053
1057
|
}
|
|
1054
1058
|
|
package/lib/type/index.d.ts
CHANGED
|
@@ -58,6 +58,17 @@ export type LiveUsers = {
|
|
|
58
58
|
group: string;
|
|
59
59
|
items: Array<LiveUsersItem>;
|
|
60
60
|
};
|
|
61
|
+
export type RichTextNode = Array<{
|
|
62
|
+
emoji?: {
|
|
63
|
+
icon_url: string;
|
|
64
|
+
size: number;
|
|
65
|
+
text: string;
|
|
66
|
+
type: number;
|
|
67
|
+
};
|
|
68
|
+
orig_text: string;
|
|
69
|
+
text: string;
|
|
70
|
+
type: string;
|
|
71
|
+
}>;
|
|
61
72
|
export type Dynamic = {
|
|
62
73
|
basic: Object;
|
|
63
74
|
id_str: string;
|
|
@@ -92,7 +103,27 @@ export type Dynamic = {
|
|
|
92
103
|
};
|
|
93
104
|
module_dynamic: {
|
|
94
105
|
additional: any;
|
|
95
|
-
desc:
|
|
106
|
+
desc: {
|
|
107
|
+
rich_text_nodes: Array<{
|
|
108
|
+
orig_text: string;
|
|
109
|
+
text: string;
|
|
110
|
+
type: string;
|
|
111
|
+
emoji: {
|
|
112
|
+
icon_url: string;
|
|
113
|
+
size: number;
|
|
114
|
+
text: string;
|
|
115
|
+
type: number;
|
|
116
|
+
};
|
|
117
|
+
jump_url: string;
|
|
118
|
+
rid: string;
|
|
119
|
+
goods: {
|
|
120
|
+
jump_url: string;
|
|
121
|
+
type: number;
|
|
122
|
+
};
|
|
123
|
+
icon_name: string;
|
|
124
|
+
}>;
|
|
125
|
+
text: string;
|
|
126
|
+
};
|
|
96
127
|
major: {
|
|
97
128
|
opus: {
|
|
98
129
|
fold_action: Array<string>;
|
|
@@ -105,17 +136,7 @@ export type Dynamic = {
|
|
|
105
136
|
width: number;
|
|
106
137
|
}>;
|
|
107
138
|
summary: {
|
|
108
|
-
rich_text_nodes:
|
|
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
|
-
}>;
|
|
139
|
+
rich_text_nodes: RichTextNode;
|
|
119
140
|
text: string;
|
|
120
141
|
};
|
|
121
142
|
title: string;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -252,6 +252,8 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
|
|
|
252
252
|
- ver 3.2.0-alpha.1 修复:直播检测 `API` 模式,中途加入推送语无法正确显示直播时长;
|
|
253
253
|
- ver 3.2.0-alpha.2 修复:直播检测 `API` 模式,请求错误优化(防止不停向QQ发送消息);
|
|
254
254
|
- ver 3.2.0-alpha.3 优化:增加直播检测 `API` 模式轮询时间,防止被暂时风控;
|
|
255
|
+
- ver 3.2.0-alpha.4 修复:直播卡片推送时间会是设置的 `pushTime` 的两倍;
|
|
256
|
+
- ver 3.2.0-alpha.5 修复:直播检测 `WS` 模式下,直播中推送卡片 `累计观看人数` 位置错误显示为 `粉丝数变化` 、转发动态的留言文字不显示; 优化:直播检测 `API` 模式下,直播推送语 `-watched` 固定显示为 `API模式无法获取`;
|
|
255
257
|
|
|
256
258
|
## 交流群
|
|
257
259
|
|