koishi-plugin-bilibili-notify 1.2.3-rc.4 → 1.2.3-rc.6
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 +4 -1
- package/lib/comRegister.d.ts +2 -2
- package/lib/comRegister.js +24 -22
- package/package.json +1 -1
- package/readme.md +2 -0
package/lib/biliAPI.js
CHANGED
|
@@ -216,8 +216,11 @@ class BiliAPI extends koishi_1.Service {
|
|
|
216
216
|
// Get login info from db
|
|
217
217
|
const { cookies, refresh_token } = await this.getLoginInfoFromDB();
|
|
218
218
|
// 判断是否有值
|
|
219
|
-
if (!cookies || !refresh_token)
|
|
219
|
+
if (!cookies || !refresh_token) {
|
|
220
|
+
// Login info is loaded
|
|
221
|
+
this.loginInfoIsLoaded = true;
|
|
220
222
|
return;
|
|
223
|
+
}
|
|
221
224
|
// 定义CSRF Token
|
|
222
225
|
let csrf;
|
|
223
226
|
cookies.forEach(cookieData => {
|
package/lib/comRegister.d.ts
CHANGED
|
@@ -28,9 +28,9 @@ declare class ComRegister {
|
|
|
28
28
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
29
29
|
getTheCorrespondingBotBasedOnTheSession(session: Session): Bot<Context, any>;
|
|
30
30
|
sendPrivateMsg(bot: Bot<Context>, content: string): Promise<void>;
|
|
31
|
-
sendPrivateMsgAndRebootService(bot: Bot<Context>,
|
|
31
|
+
sendPrivateMsgAndRebootService(ctx: Context, bot: Bot<Context>, content: string): Promise<void>;
|
|
32
32
|
dynamicDetect(ctx: Context, bot: Bot<Context>, uid: string, guildId: Array<string>): () => Promise<void>;
|
|
33
|
-
sendMsg(targets: Array<string>, bot: Bot<Context>, content: any): Promise<string[]>;
|
|
33
|
+
sendMsg(ctx: Context, targets: Array<string>, bot: Bot<Context>, content: any): Promise<string[]>;
|
|
34
34
|
liveDetect(ctx: Context, bot: Bot<Context>, roomId: string, guildId: Array<string>): () => Promise<void>;
|
|
35
35
|
subShow(): string;
|
|
36
36
|
checkIfNeedSub(comNeed: boolean, subType: string, session: Session, data?: any): Promise<boolean>;
|
package/lib/comRegister.js
CHANGED
|
@@ -636,7 +636,7 @@ class ComRegister {
|
|
|
636
636
|
// 获得对应bot
|
|
637
637
|
const bot = this.getTheCorrespondingBotBasedOnTheSession(session);
|
|
638
638
|
// 发送提示消息,重启服务
|
|
639
|
-
await this.sendPrivateMsgAndRebootService(
|
|
639
|
+
await this.sendPrivateMsgAndRebootService(ctx, bot, '测试biliAPI等服务自动重启功能');
|
|
640
640
|
});
|
|
641
641
|
biliCom
|
|
642
642
|
.subcommand('.sendall', '测试给机器人加入的所有群发送消息', { hidden: true })
|
|
@@ -646,7 +646,7 @@ class ComRegister {
|
|
|
646
646
|
// 获得对应bot
|
|
647
647
|
const bot = this.getTheCorrespondingBotBasedOnTheSession(session);
|
|
648
648
|
// 发送消息
|
|
649
|
-
await this.sendMsg(['all'], bot, 'Hello World');
|
|
649
|
+
await this.sendMsg(ctx, ['all'], bot, 'Hello World');
|
|
650
650
|
// 发送提示
|
|
651
651
|
await session.send('已向机器人加入的所有群发送了消息');
|
|
652
652
|
});
|
|
@@ -706,7 +706,7 @@ class ComRegister {
|
|
|
706
706
|
}
|
|
707
707
|
}
|
|
708
708
|
}
|
|
709
|
-
async sendPrivateMsgAndRebootService(
|
|
709
|
+
async sendPrivateMsgAndRebootService(ctx, bot, content) {
|
|
710
710
|
await this.sendPrivateMsg(bot, content);
|
|
711
711
|
// 停用插件
|
|
712
712
|
ctx.sm.disposePlugin();
|
|
@@ -782,22 +782,22 @@ class ComRegister {
|
|
|
782
782
|
break;
|
|
783
783
|
if (e.message === '出现关键词,屏蔽该动态') {
|
|
784
784
|
// 如果需要发送才发送
|
|
785
|
-
this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
|
|
785
|
+
this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
|
|
786
786
|
break;
|
|
787
787
|
}
|
|
788
788
|
if (e.message === '已屏蔽转发动态') {
|
|
789
|
-
this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
|
|
789
|
+
this.config.filter.notify && await this.sendMsg(ctx, guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
|
|
790
790
|
break;
|
|
791
791
|
}
|
|
792
792
|
}
|
|
793
793
|
// 如果pic存在,则直接返回pic
|
|
794
794
|
if (pic) {
|
|
795
795
|
// pic存在,使用的是render模式
|
|
796
|
-
await this.sendMsg(guildId, bot, pic + dUrl);
|
|
796
|
+
await this.sendMsg(ctx, guildId, bot, pic + dUrl);
|
|
797
797
|
}
|
|
798
798
|
else {
|
|
799
799
|
// pic不存在,说明使用的是page模式
|
|
800
|
-
await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png' + dUrl));
|
|
800
|
+
await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + dUrl));
|
|
801
801
|
}
|
|
802
802
|
// 如果成功,那么跳出循环
|
|
803
803
|
break;
|
|
@@ -805,7 +805,7 @@ class ComRegister {
|
|
|
805
805
|
catch (e) {
|
|
806
806
|
this.logger.error('dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:' + e.toString());
|
|
807
807
|
if (i === attempts - 1) { // 如果已经尝试了三次,那么抛出错误
|
|
808
|
-
return await this.sendPrivateMsgAndRebootService(
|
|
808
|
+
return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
|
|
809
809
|
}
|
|
810
810
|
}
|
|
811
811
|
}
|
|
@@ -823,7 +823,7 @@ class ComRegister {
|
|
|
823
823
|
}
|
|
824
824
|
};
|
|
825
825
|
}
|
|
826
|
-
async sendMsg(targets, bot, content) {
|
|
826
|
+
async sendMsg(ctx, targets, bot, content) {
|
|
827
827
|
// 定义需要发送的数组
|
|
828
828
|
let sendArr = [];
|
|
829
829
|
// 判断是否需要推送所有机器人加入的群
|
|
@@ -838,7 +838,7 @@ class ComRegister {
|
|
|
838
838
|
}
|
|
839
839
|
// 循环给每个群组发送
|
|
840
840
|
for (let guildId of sendArr) {
|
|
841
|
-
//
|
|
841
|
+
// 多次尝试发送消息
|
|
842
842
|
let attempts = 3;
|
|
843
843
|
for (let i = 0; i < attempts; i++) {
|
|
844
844
|
try {
|
|
@@ -850,6 +850,8 @@ class ComRegister {
|
|
|
850
850
|
}
|
|
851
851
|
}
|
|
852
852
|
}
|
|
853
|
+
// 防止消息发送速度过快被忽略
|
|
854
|
+
await ctx.sleep(500);
|
|
853
855
|
}
|
|
854
856
|
}
|
|
855
857
|
liveDetect(ctx, bot, roomId, guildId) {
|
|
@@ -870,23 +872,23 @@ class ComRegister {
|
|
|
870
872
|
if (!liveStartMsg) {
|
|
871
873
|
// pic 存在,使用的是render模式
|
|
872
874
|
if (pic)
|
|
873
|
-
return await this.sendMsg(guildId, bot, pic);
|
|
875
|
+
return await this.sendMsg(ctx, guildId, bot, pic);
|
|
874
876
|
// pic不存在,说明使用的是page模式
|
|
875
|
-
await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png'));
|
|
877
|
+
await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png'));
|
|
876
878
|
}
|
|
877
879
|
else if (liveStartMsg && atAll) {
|
|
878
880
|
// pic 存在,使用的是render模式
|
|
879
881
|
if (pic)
|
|
880
|
-
return await this.sendMsg(guildId, bot, pic + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg, " "] }));
|
|
882
|
+
return await this.sendMsg(ctx, guildId, bot, pic + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg, " "] }));
|
|
881
883
|
// pic不存在,说明使用的是page模式
|
|
882
|
-
await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png' + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg] })));
|
|
884
|
+
await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg] })));
|
|
883
885
|
}
|
|
884
886
|
else {
|
|
885
887
|
// pic 存在,使用的是render模式
|
|
886
888
|
if (pic)
|
|
887
|
-
return await this.sendMsg(guildId, bot, pic + liveStartMsg);
|
|
889
|
+
return await this.sendMsg(ctx, guildId, bot, pic + liveStartMsg);
|
|
888
890
|
// pic不存在,说明使用的是page模式
|
|
889
|
-
await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png' + liveStartMsg));
|
|
891
|
+
await this.sendMsg(ctx, guildId, bot, koishi_1.h.image(buffer, 'image/png' + liveStartMsg));
|
|
890
892
|
}
|
|
891
893
|
// 成功则跳出循环
|
|
892
894
|
break;
|
|
@@ -894,7 +896,7 @@ class ComRegister {
|
|
|
894
896
|
catch (e) {
|
|
895
897
|
this.logger.error('liveDetect generateLiveImg() 推送卡片发送失败,原因:' + e.toString());
|
|
896
898
|
if (i === attempts - 1) { // 已尝试三次
|
|
897
|
-
return await this.sendPrivateMsgAndRebootService(
|
|
899
|
+
return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
|
|
898
900
|
}
|
|
899
901
|
}
|
|
900
902
|
}
|
|
@@ -918,7 +920,7 @@ class ComRegister {
|
|
|
918
920
|
catch (e) {
|
|
919
921
|
this.logger.error('liveDetect getLiveRoomInfo 网络请求失败');
|
|
920
922
|
if (i === attempts - 1) { // 已尝试三次
|
|
921
|
-
return await this.sendPrivateMsgAndRebootService(
|
|
923
|
+
return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
|
|
922
924
|
}
|
|
923
925
|
}
|
|
924
926
|
}
|
|
@@ -940,7 +942,7 @@ class ComRegister {
|
|
|
940
942
|
catch (e) {
|
|
941
943
|
this.logger.error('liveDetect getMasterInfo() 本次网络请求失败');
|
|
942
944
|
if (i === attempts - 1) { // 已尝试三次
|
|
943
|
-
return await this.sendPrivateMsgAndRebootService(
|
|
945
|
+
return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
|
|
944
946
|
}
|
|
945
947
|
}
|
|
946
948
|
}
|
|
@@ -971,7 +973,7 @@ class ComRegister {
|
|
|
971
973
|
.replace('-name', uData.info.uname)
|
|
972
974
|
.replace('-time', await ctx.gimg.getTimeDifference(liveTime));
|
|
973
975
|
// 发送下播通知
|
|
974
|
-
await this.sendMsg(guildId, bot, liveEndMsg);
|
|
976
|
+
await this.sendMsg(ctx, guildId, bot, liveEndMsg);
|
|
975
977
|
}
|
|
976
978
|
// 未进循环,还未开播,继续循环
|
|
977
979
|
break;
|
|
@@ -996,7 +998,7 @@ class ComRegister {
|
|
|
996
998
|
catch (e) {
|
|
997
999
|
this.logger.error('liveDetect open getMasterInfo() 网络请求错误');
|
|
998
1000
|
if (i === attempts - 1) { // 已尝试三次
|
|
999
|
-
return await this.sendPrivateMsgAndRebootService(
|
|
1001
|
+
return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
|
|
1000
1002
|
}
|
|
1001
1003
|
}
|
|
1002
1004
|
}
|
|
@@ -1203,7 +1205,7 @@ class ComRegister {
|
|
|
1203
1205
|
catch (e) {
|
|
1204
1206
|
this.logger.error('getSubFromDatabase() getUserInfo() 本次网络请求失败');
|
|
1205
1207
|
if (i === attempts - 1) { // 已尝试三次
|
|
1206
|
-
return await this.sendPrivateMsgAndRebootService(
|
|
1208
|
+
return await this.sendPrivateMsgAndRebootService(ctx, bot, '你的网络可能出现了某些问题,请检查后重启插件');
|
|
1207
1209
|
}
|
|
1208
1210
|
}
|
|
1209
1211
|
}
|
package/package.json
CHANGED