koishi-plugin-bilibili-notify 3.0.0-alpha.24 → 3.0.0-alpha.25
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 +106 -143
- package/lib/generateImg.js +1 -1
- package/package.json +1 -1
- package/readme.md +1 -0
package/lib/comRegister.js
CHANGED
|
@@ -226,14 +226,17 @@ class ComRegister {
|
|
|
226
226
|
for (const sub of this.subManager) {
|
|
227
227
|
// 定义开播标志位
|
|
228
228
|
let onLive = false;
|
|
229
|
-
//
|
|
230
|
-
|
|
231
|
-
//
|
|
232
|
-
|
|
233
|
-
//
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
229
|
+
// 判断items是否存在
|
|
230
|
+
if (live_users.items) {
|
|
231
|
+
// 遍历liveUsers
|
|
232
|
+
for (const user of live_users.items) {
|
|
233
|
+
// 判断是否是订阅直播的UP
|
|
234
|
+
if (user.mid.toString() === sub.uid && sub.live) {
|
|
235
|
+
// 设置标志位为true
|
|
236
|
+
onLive = true;
|
|
237
|
+
// break
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
237
240
|
}
|
|
238
241
|
}
|
|
239
242
|
// 判断是否未开播
|
|
@@ -256,7 +259,7 @@ class ComRegister {
|
|
|
256
259
|
// 设置logger
|
|
257
260
|
this.logger = this.ctx.logger("cr");
|
|
258
261
|
// logger
|
|
259
|
-
this.logger.info("
|
|
262
|
+
this.logger.info("初始化插件中...");
|
|
260
263
|
// 将config设置给类属性
|
|
261
264
|
this.config = config;
|
|
262
265
|
// 拿到私人机器人实例
|
|
@@ -326,7 +329,7 @@ class ComRegister {
|
|
|
326
329
|
// 在控制台中显示订阅对象
|
|
327
330
|
this.updateSubNotifier();
|
|
328
331
|
// logger
|
|
329
|
-
this.logger.info("
|
|
332
|
+
this.logger.info("插件初始化完毕!");
|
|
330
333
|
}
|
|
331
334
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
332
335
|
getBot(pf) {
|
|
@@ -588,43 +591,37 @@ class ComRegister {
|
|
|
588
591
|
const upName = items[num].modules.module_author.name;
|
|
589
592
|
const dynamicId = items[num].id_str;
|
|
590
593
|
// 推送该条动态
|
|
591
|
-
const
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
//
|
|
605
|
-
if (
|
|
606
|
-
|
|
607
|
-
if (e.message === "出现关键词,屏蔽该动态") {
|
|
608
|
-
// 如果需要发送才发送
|
|
609
|
-
if (this.config.filter.notify) {
|
|
610
|
-
await this.sendMsg(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
|
|
611
|
-
}
|
|
612
|
-
return;
|
|
613
|
-
}
|
|
614
|
-
if (e.message === "已屏蔽转发动态") {
|
|
615
|
-
if (this.config.filter.notify) {
|
|
616
|
-
await this.sendMsg(sub.target, `${upName}发布了一条转发动态,已屏蔽`);
|
|
617
|
-
}
|
|
618
|
-
return;
|
|
594
|
+
const flag = await (0, utils_1.withRetry)(async () => {
|
|
595
|
+
// 渲染图片
|
|
596
|
+
const { pic: gimgPic, buffer: gimgBuffer } = await this.ctx.gi.generateDynamicImg(items[num]);
|
|
597
|
+
// 赋值
|
|
598
|
+
pic = gimgPic;
|
|
599
|
+
buffer = gimgBuffer;
|
|
600
|
+
})
|
|
601
|
+
.then(() => true)
|
|
602
|
+
.catch(async (e) => {
|
|
603
|
+
// 直播开播动态,不做处理
|
|
604
|
+
if (e.message === "直播开播动态,不做处理")
|
|
605
|
+
return;
|
|
606
|
+
if (e.message === "出现关键词,屏蔽该动态") {
|
|
607
|
+
// 如果需要发送才发送
|
|
608
|
+
if (this.config.filter.notify) {
|
|
609
|
+
await this.sendMsg(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
|
|
619
610
|
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
if (e.message === "已屏蔽转发动态") {
|
|
614
|
+
if (this.config.filter.notify) {
|
|
615
|
+
await this.sendMsg(sub.target, `${upName}发布了一条转发动态,已屏蔽`);
|
|
625
616
|
}
|
|
617
|
+
return;
|
|
626
618
|
}
|
|
627
|
-
|
|
619
|
+
// 未知错误
|
|
620
|
+
this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
|
|
621
|
+
});
|
|
622
|
+
// 判断是否执行成功,未执行成功直接返回
|
|
623
|
+
if (!flag)
|
|
624
|
+
return;
|
|
628
625
|
// 判断是否需要发送URL
|
|
629
626
|
const dUrl = this.config.dynamicUrl
|
|
630
627
|
? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}`
|
|
@@ -785,43 +782,37 @@ class ComRegister {
|
|
|
785
782
|
const dynamicId = items[num].id_str;
|
|
786
783
|
console.log(`UP主名称:${upName},动态ID:${dynamicId}`);
|
|
787
784
|
// 推送该条动态
|
|
788
|
-
const
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
//
|
|
802
|
-
if (
|
|
803
|
-
|
|
804
|
-
if (e.message === "出现关键词,屏蔽该动态") {
|
|
805
|
-
// 如果需要发送才发送
|
|
806
|
-
if (this.config.filter.notify) {
|
|
807
|
-
await this.sendMsg(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
|
|
808
|
-
}
|
|
809
|
-
return;
|
|
810
|
-
}
|
|
811
|
-
if (e.message === "已屏蔽转发动态") {
|
|
812
|
-
if (this.config.filter.notify) {
|
|
813
|
-
await this.sendMsg(sub.target, `${upName}发布了一条转发动态,已屏蔽`);
|
|
814
|
-
}
|
|
815
|
-
return;
|
|
785
|
+
const flag = await (0, utils_1.withRetry)(async () => {
|
|
786
|
+
// 渲染图片
|
|
787
|
+
const { pic: gimgPic, buffer: gimgBuffer } = await this.ctx.gi.generateDynamicImg(items[num]);
|
|
788
|
+
// 赋值
|
|
789
|
+
pic = gimgPic;
|
|
790
|
+
buffer = gimgBuffer;
|
|
791
|
+
})
|
|
792
|
+
.then(() => true)
|
|
793
|
+
.catch(async (e) => {
|
|
794
|
+
// 直播开播动态,不做处理
|
|
795
|
+
if (e.message === "直播开播动态,不做处理")
|
|
796
|
+
return;
|
|
797
|
+
if (e.message === "出现关键词,屏蔽该动态") {
|
|
798
|
+
// 如果需要发送才发送
|
|
799
|
+
if (this.config.filter.notify) {
|
|
800
|
+
await this.sendMsg(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
|
|
816
801
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
if (e.message === "已屏蔽转发动态") {
|
|
805
|
+
if (this.config.filter.notify) {
|
|
806
|
+
await this.sendMsg(sub.target, `${upName}发布了一条转发动态,已屏蔽`);
|
|
822
807
|
}
|
|
808
|
+
return;
|
|
823
809
|
}
|
|
824
|
-
|
|
810
|
+
// 未知错误
|
|
811
|
+
this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
|
|
812
|
+
});
|
|
813
|
+
// 发送私聊消息并重启服务
|
|
814
|
+
if (!flag)
|
|
815
|
+
return await this.sendPrivateMsgAndStopService();
|
|
825
816
|
// 判断是否需要发送URL
|
|
826
817
|
const dUrl = this.config.dynamicUrl
|
|
827
818
|
? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}`
|
|
@@ -853,26 +844,21 @@ class ComRegister {
|
|
|
853
844
|
let pic;
|
|
854
845
|
let buffer;
|
|
855
846
|
// 多次尝试生成图片
|
|
856
|
-
const
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
// 发送私聊消息并重启服务
|
|
872
|
-
return await this.sendPrivateMsgAndStopService();
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
}
|
|
847
|
+
const flag = await (0, utils_1.withRetry)(async () => {
|
|
848
|
+
// 获取直播通知卡片
|
|
849
|
+
const { pic: picv, buffer: bufferv } = await this.ctx.gi.generateLiveImg(info.data, info.username, info.userface, followerDisplay, liveType);
|
|
850
|
+
// 赋值
|
|
851
|
+
pic = picv;
|
|
852
|
+
buffer = bufferv;
|
|
853
|
+
})
|
|
854
|
+
.then(() => true)
|
|
855
|
+
.catch((e) => {
|
|
856
|
+
this.logger.error(`liveDetect generateLiveImg() 推送卡片生成失败,原因:${e.message}`);
|
|
857
|
+
return false;
|
|
858
|
+
});
|
|
859
|
+
// 发送私聊消息并重启服务
|
|
860
|
+
if (!flag)
|
|
861
|
+
return await this.sendPrivateMsgAndStopService();
|
|
876
862
|
// 推送直播信息
|
|
877
863
|
// pic 存在,使用的是render模式
|
|
878
864
|
if (pic) {
|
|
@@ -931,26 +917,18 @@ class ComRegister {
|
|
|
931
917
|
}
|
|
932
918
|
async useLiveRoomInfo(roomId) {
|
|
933
919
|
// 发送请求获取直播间信息
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
if (i === attempts - 1) {
|
|
947
|
-
// 已尝试三次
|
|
948
|
-
// 发送私聊消息并重启服务
|
|
949
|
-
return await this.sendPrivateMsgAndStopService();
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
return content.data;
|
|
920
|
+
const data = await (0, utils_1.withRetry)(async () => await this.ctx.ba.getLiveRoomInfo(roomId))
|
|
921
|
+
.then((content) => content.data)
|
|
922
|
+
.catch((e) => {
|
|
923
|
+
this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
|
|
924
|
+
// 返回错误
|
|
925
|
+
return false;
|
|
926
|
+
});
|
|
927
|
+
// 发送私聊消息并重启服务
|
|
928
|
+
if (!data)
|
|
929
|
+
return await this.sendPrivateMsgAndStopService();
|
|
930
|
+
// 返回
|
|
931
|
+
return data;
|
|
954
932
|
}
|
|
955
933
|
async liveDetectWithListener(roomId, target) {
|
|
956
934
|
// 定义开播时间
|
|
@@ -1336,34 +1314,18 @@ class ComRegister {
|
|
|
1336
1314
|
}
|
|
1337
1315
|
async loadSubFromConfig(subs) {
|
|
1338
1316
|
for (const sub of subs) {
|
|
1317
|
+
// logger
|
|
1318
|
+
this.logger.info(`加载订阅UID:${sub.uid}中...`);
|
|
1339
1319
|
// 定义Data
|
|
1340
|
-
|
|
1341
|
-
|
|
1320
|
+
const data = await (0, utils_1.withRetry)(async () => await this.ctx.ba.getUserInfo(sub.uid))
|
|
1321
|
+
.then((content) => content.data)
|
|
1322
|
+
.catch((e) => {
|
|
1323
|
+
this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
|
|
1324
|
+
// logger
|
|
1325
|
+
this.logger.info(`加载订阅UID:${sub.uid}失败!`);
|
|
1326
|
+
});
|
|
1342
1327
|
// 判断是否需要订阅直播
|
|
1343
1328
|
if (sub.live) {
|
|
1344
|
-
// 获取用户信息
|
|
1345
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
1346
|
-
let content;
|
|
1347
|
-
// 设置重试次数
|
|
1348
|
-
const attempts = 3;
|
|
1349
|
-
for (let i = 0; i < attempts; i++) {
|
|
1350
|
-
try {
|
|
1351
|
-
// 获取用户信息
|
|
1352
|
-
content = await this.ctx.ba.getUserInfo(sub.uid);
|
|
1353
|
-
// 成功则跳出循环
|
|
1354
|
-
break;
|
|
1355
|
-
}
|
|
1356
|
-
catch (e) {
|
|
1357
|
-
this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
|
|
1358
|
-
if (i === attempts - 1) {
|
|
1359
|
-
// 已尝试三次
|
|
1360
|
-
// 发送私聊消息并重启服务
|
|
1361
|
-
return await this.sendPrivateMsgAndStopService();
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
// 获取data
|
|
1366
|
-
data = content.data;
|
|
1367
1329
|
// 检查roomid是否存在
|
|
1368
1330
|
if (!data.live_room) {
|
|
1369
1331
|
// 用户没有开通直播间,无法订阅直播
|
|
@@ -1393,6 +1355,7 @@ class ComRegister {
|
|
|
1393
1355
|
live: sub.live,
|
|
1394
1356
|
dynamic: sub.dynamic,
|
|
1395
1357
|
});
|
|
1358
|
+
this.logger.info(`UID:${sub.uid}订阅加载完毕!`);
|
|
1396
1359
|
}
|
|
1397
1360
|
}
|
|
1398
1361
|
checkIfDynamicDetectIsNeeded() {
|
package/lib/generateImg.js
CHANGED
|
@@ -160,7 +160,7 @@ class GenerateImg extends koishi_1.Service {
|
|
|
160
160
|
<span class="broadcast-message">${username}${titleStatus}</span>
|
|
161
161
|
</div>
|
|
162
162
|
</div>
|
|
163
|
-
${this.giConfig.hideDesc ? "" : `<p class="card-text">${data.description ? data.description : "
|
|
163
|
+
${this.giConfig.hideDesc ? "" : `<p class="card-text">${data.description ? data.description : "这个主播很懒,什么简介都没写"}</p>`}
|
|
164
164
|
<p class="card-link">
|
|
165
165
|
<span>人气:${data.online > 10000 ? `${(data.online / 10000).toFixed(1)}万` : data.online}</span>
|
|
166
166
|
<span>分区名称:${data.area_name}</span>
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -208,6 +208,7 @@
|
|
|
208
208
|
- ver 3.0.0-alpha.22 优化:订阅配置展示优化
|
|
209
209
|
- ver 3.0.0-alpha.23 新增:指令 `bili ll` 可以查看当前订阅直播的UP主们的开播情况
|
|
210
210
|
- ver 3.0.0-alpha.24 新增:配置项,`cardBasePlateColor` 和 `cardBasePlateBorder`,分别设置卡片底板颜色和底板边框宽度; 优化:部分代码结构
|
|
211
|
+
- ver 3.0.0-alpha.25 修复:输入指令 `bili ll` 时报错 `TypeError: Cannot read properties of null (reading 'items')`,当某个订阅只订阅动态时无法成功订阅且后续订阅都无法加载; 优化:部分代码结构
|
|
211
212
|
|
|
212
213
|
## 交流群
|
|
213
214
|
|