koishi-plugin-bilibili-notify 1.0.4-rc.0 → 1.0.5-alpha.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.
- package/lib/biliAPI.js +0 -1
- package/lib/comRegister.js +78 -11
- package/lib/generateImg.js +2 -1
- package/package.json +1 -1
- package/readme.md +5 -4
package/lib/biliAPI.js
CHANGED
package/lib/comRegister.js
CHANGED
|
@@ -553,20 +553,41 @@ class ComRegister {
|
|
|
553
553
|
// 寻找发布时间比时间点更晚的动态
|
|
554
554
|
if (items[num].modules.module_author.pub_ts > timePoint) {
|
|
555
555
|
// 更新时间点为当前动态的发布时间
|
|
556
|
-
if (num === 1) { // 寻找倒数第二条动态
|
|
556
|
+
/* if (num === 1) { // 寻找倒数第二条动态
|
|
557
557
|
if (items[0].modules.module_tag) { // 存在置顶动态
|
|
558
|
-
timePoint = items[num].modules.module_author.pub_ts
|
|
558
|
+
timePoint = items[num].modules.module_author.pub_ts
|
|
559
|
+
} else {
|
|
560
|
+
timePoint = items[0].modules.module_author.pub_ts
|
|
559
561
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
+
} */
|
|
563
|
+
// 更新时间点为最新发布动态的发布时间
|
|
564
|
+
switch (num) {
|
|
565
|
+
case 1: {
|
|
566
|
+
if (items[0].modules.module_tag) { // 存在置顶动态
|
|
567
|
+
timePoint = items[num].modules.module_author.pub_ts;
|
|
568
|
+
}
|
|
569
|
+
break;
|
|
562
570
|
}
|
|
571
|
+
case 0: timePoint = items[num].modules.module_author.pub_ts;
|
|
563
572
|
}
|
|
564
573
|
// 推送该条动态
|
|
565
574
|
let attempts = 3;
|
|
566
575
|
for (let i = 0; i < attempts; i++) {
|
|
567
576
|
try {
|
|
577
|
+
// 定义变量
|
|
578
|
+
let pic;
|
|
579
|
+
let buffer;
|
|
568
580
|
// 获取动态推送图片
|
|
569
|
-
|
|
581
|
+
try {
|
|
582
|
+
const { pic: gimgPic, buffer: gimgBuffer } = await ctx.gimg.generateDynamicImg(items[num]);
|
|
583
|
+
pic = gimgPic;
|
|
584
|
+
buffer = gimgBuffer;
|
|
585
|
+
}
|
|
586
|
+
catch (e) {
|
|
587
|
+
// 直播开播动态,不做处理
|
|
588
|
+
if (e.message === '直播开播动态,不做处理')
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
570
591
|
// 如果pic存在,则直接返回pic
|
|
571
592
|
if (pic)
|
|
572
593
|
return await bot.sendMessage(guildId, pic);
|
|
@@ -621,12 +642,10 @@ class ComRegister {
|
|
|
621
642
|
}
|
|
622
643
|
return async () => {
|
|
623
644
|
try {
|
|
624
|
-
// console.log('start before' + ' ' + flag);
|
|
625
645
|
// 如果flag为false则说明前面的代码还未执行完,则直接返回
|
|
626
646
|
if (!flag)
|
|
627
647
|
return;
|
|
628
648
|
flag && (flag = false);
|
|
629
|
-
// console.log('start after' + ' ' + flag);
|
|
630
649
|
// 发送请求检测直播状态
|
|
631
650
|
let content;
|
|
632
651
|
try {
|
|
@@ -724,10 +743,8 @@ class ComRegister {
|
|
|
724
743
|
}
|
|
725
744
|
}
|
|
726
745
|
finally {
|
|
727
|
-
// console.log('end before' + ' ' + flag);
|
|
728
746
|
// 执行完方法体不论如何都把flag设置为true
|
|
729
747
|
flag = true;
|
|
730
|
-
// console.log('end after' + ' ' + flag);
|
|
731
748
|
}
|
|
732
749
|
};
|
|
733
750
|
}
|
|
@@ -776,17 +793,67 @@ class ComRegister {
|
|
|
776
793
|
this.num = subData.length;
|
|
777
794
|
// 如果订阅数量超过三个则被非法修改数据库
|
|
778
795
|
// 向管理员发送重新订阅通知
|
|
779
|
-
if (this.num > 3)
|
|
796
|
+
if (this.num > 3) {
|
|
797
|
+
ctx.notifier.create({
|
|
798
|
+
type: 'danger',
|
|
799
|
+
content: '数据库被非法修改,请你删除bilibili表的所有内容后重启插件'
|
|
800
|
+
});
|
|
780
801
|
return;
|
|
802
|
+
}
|
|
781
803
|
// 定义Bot
|
|
782
804
|
let bot;
|
|
783
805
|
// 循环遍历
|
|
784
|
-
subData.forEach(sub => {
|
|
806
|
+
subData.forEach(async (sub) => {
|
|
785
807
|
// 拿到对应bot
|
|
786
808
|
switch (sub.platform) {
|
|
787
809
|
case 'qq': bot = this.qqBot;
|
|
788
810
|
case 'qqguild': bot = this.qqguildBot;
|
|
789
811
|
}
|
|
812
|
+
// 判断数据库是否被篡改
|
|
813
|
+
// 获取用户信息
|
|
814
|
+
let content;
|
|
815
|
+
let attempts = 3;
|
|
816
|
+
for (let i = 0; i < attempts; i++) {
|
|
817
|
+
try {
|
|
818
|
+
content = await ctx.biliAPI.getUserInfo(sub.uid);
|
|
819
|
+
break;
|
|
820
|
+
}
|
|
821
|
+
catch (e) {
|
|
822
|
+
this.logger.error('getSubFromDatabase() getUserInfo() 本次网络请求失败');
|
|
823
|
+
if (i === attempts - 1) { // 已尝试三次
|
|
824
|
+
return bot.sendMessage(sub.targetId, '你的网络可能出现了某些问题,请检查后重启插件');
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
// 获取data
|
|
829
|
+
const { data } = content;
|
|
830
|
+
// 定义函数删除数据和发送提示
|
|
831
|
+
const deleteSub = async () => {
|
|
832
|
+
// 从数据库删除该条数据
|
|
833
|
+
await ctx.database.remove('bilibili', { id: sub.id });
|
|
834
|
+
// 给用户发送提示
|
|
835
|
+
bot.sendMessage(sub.targetId, `UID:${sub.uid} 数据库内容被篡改,已取消对该UP主的订阅`);
|
|
836
|
+
};
|
|
837
|
+
// 判断是否有其他问题
|
|
838
|
+
if (content.code !== 0) {
|
|
839
|
+
switch (content.code) {
|
|
840
|
+
case -352:
|
|
841
|
+
case -403:
|
|
842
|
+
bot.sendMessage(sub.targetId, '你的登录信息已过期,请重新登录Bilibili');
|
|
843
|
+
return;
|
|
844
|
+
case -400:
|
|
845
|
+
case -404:
|
|
846
|
+
default:
|
|
847
|
+
deleteSub();
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
// 检测房间号是否被篡改
|
|
852
|
+
if (sub.live && (!data.live_room || data.live_room.roomid.toString() !== sub.room_id)) {
|
|
853
|
+
// 房间号被篡改,删除该订阅
|
|
854
|
+
deleteSub();
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
790
857
|
// 构建订阅对象
|
|
791
858
|
let subManagerItem = {
|
|
792
859
|
id: sub.id,
|
package/lib/generateImg.js
CHANGED
|
@@ -481,7 +481,7 @@ class GenerateImg extends koishi_1.Service {
|
|
|
481
481
|
case DYNAMIC_TYPE_UGC_SEASON: return [`${upName}更新了合集,我暂时无法渲染,请自行查看`, link];
|
|
482
482
|
case DYNAMIC_TYPE_NONE: return [`${upName}发布了一条无效动态`, link];
|
|
483
483
|
// 直播开播,不做处理
|
|
484
|
-
case DYNAMIC_TYPE_LIVE_RCMD:
|
|
484
|
+
case DYNAMIC_TYPE_LIVE_RCMD: throw new Error('直播开播动态,不做处理');
|
|
485
485
|
case DYNAMIC_TYPE_SUBSCRIPTION_NEW:
|
|
486
486
|
case DYNAMIC_TYPE_BANNER:
|
|
487
487
|
case DYNAMIC_TYPE_SUBSCRIPTION:
|
|
@@ -494,6 +494,7 @@ class GenerateImg extends koishi_1.Service {
|
|
|
494
494
|
}
|
|
495
495
|
return [main, link, forwardInfo];
|
|
496
496
|
}
|
|
497
|
+
// 获取动态主要内容
|
|
497
498
|
const [main, link] = await getDynamicMajor(data, false);
|
|
498
499
|
// 加载字体
|
|
499
500
|
const fontURL = (0, url_1.pathToFileURL)((0, path_1.resolve)(__dirname, './HYZhengYuan-55W.ttf'));
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -76,10 +76,11 @@
|
|
|
76
76
|
|
|
77
77
|
## 更新日志
|
|
78
78
|
|
|
79
|
-
ver 1.0.1 修复了一些bug,提供用户自己选择动态检测时间的选项
|
|
80
|
-
ver 1.0.2 修复时间bug和字体乱码问题
|
|
81
|
-
ver 1.0.3 修复了一些bug,提供用户自己选择推送卡片字体样式的选项
|
|
82
|
-
ver 1.0.4 修复了重复推送的bug,提供用户选择推送卡片渲染方式的选项
|
|
79
|
+
- ver 1.0.1 修复了一些bug,提供用户自己选择动态检测时间的选项
|
|
80
|
+
- ver 1.0.2 修复时间bug和字体乱码问题
|
|
81
|
+
- ver 1.0.3 修复了一些bug,提供用户自己选择推送卡片字体样式的选项
|
|
82
|
+
- ver 1.0.4 修复了重复推送的bug,提供用户选择推送卡片渲染方式的选项
|
|
83
|
+
- ver 1.0.5 修复了用户非法篡改数据库内容可能导致程序异常运行的bug,修复了UP主开播动态推送空白卡片的bug
|
|
83
84
|
|
|
84
85
|
## 感谢
|
|
85
86
|
|