koishi-plugin-bilibili-notify 3.3.3 → 3.3.4-alpha.2
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/index.js +54 -36
- package/lib/index.mjs +54 -36
- package/package.json +1 -1
- package/readme.md +3 -0
package/lib/index.js
CHANGED
|
@@ -778,8 +778,14 @@ var ComRegister = class {
|
|
|
778
778
|
return this.ctx.bots.find((bot) => bot.platform === pf && bot.selfId === selfId);
|
|
779
779
|
}
|
|
780
780
|
async sendPrivateMsg(content) {
|
|
781
|
-
if (this.config.master.enable)
|
|
782
|
-
|
|
781
|
+
if (this.config.master.enable) {
|
|
782
|
+
if (this.privateBot.status !== koishi.Universal.Status.ONLINE) {
|
|
783
|
+
this.logger.error(`${this.privateBot.platform} 机器人未初始化完毕,无法进行推送`);
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
if (this.config.master.masterAccountGuildId) await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content, this.config.master.masterAccountGuildId);
|
|
787
|
+
else await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content);
|
|
788
|
+
}
|
|
783
789
|
}
|
|
784
790
|
async sendPrivateMsgAndRebootService() {
|
|
785
791
|
if (this.rebootCount >= 3) {
|
|
@@ -861,59 +867,74 @@ var ComRegister = class {
|
|
|
861
867
|
this.logger.info("初始化推送群组/频道信息:");
|
|
862
868
|
this.logger.info(this.pushArrMap);
|
|
863
869
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
this.ctx.setTimeout(() => {
|
|
871
|
-
this.broadcastToTargets(uid, content, type, retry * 2);
|
|
872
|
-
}, retry);
|
|
873
|
-
return;
|
|
870
|
+
async pushMessage(targets, content, retry = 3e3) {
|
|
871
|
+
const t = {};
|
|
872
|
+
for (const target of targets) {
|
|
873
|
+
const [platform, channleId] = target.split(":");
|
|
874
|
+
if (!t[platform]) t[platform] = [channleId];
|
|
875
|
+
else t[platform].push(channleId);
|
|
874
876
|
}
|
|
877
|
+
for (const platform of Object.keys(t)) {
|
|
878
|
+
const bots = [];
|
|
879
|
+
for (const bot of this.ctx.bots) if (bot.platform === platform) bots.push(bot);
|
|
880
|
+
botloop: for (const bot of bots) {
|
|
881
|
+
if (bot.status !== koishi.Universal.Status.ONLINE) {
|
|
882
|
+
this.logger.error(`${platform} 机器人未初始化完毕,无法进行推送,${retry / 1e3}秒后重试`);
|
|
883
|
+
this.ctx.setTimeout(async () => {
|
|
884
|
+
await this.pushMessage(targets, content, retry * 2);
|
|
885
|
+
}, retry);
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
let num = 0;
|
|
889
|
+
for (const channelId of t[platform]) try {
|
|
890
|
+
await bot.sendMessage(channelId, content);
|
|
891
|
+
num++;
|
|
892
|
+
} catch (e) {
|
|
893
|
+
this.logger.error(e);
|
|
894
|
+
if (bots.length > 1) continue botloop;
|
|
895
|
+
}
|
|
896
|
+
this.logger.info(`成功推送消息 ${num} 条`);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
async broadcastToTargets(uid, content, type) {
|
|
875
901
|
this.logger.info(`本次推送对象:${uid},推送类型:${PushTypeMsg[type]}`);
|
|
876
902
|
const record = this.pushArrMap.get(uid);
|
|
877
903
|
this.logger.info("本次推送目标:");
|
|
878
904
|
if (type === PushType.StartBroadcasting && record.liveAtAllArr?.length >= 1) {
|
|
879
905
|
this.logger.info(record.liveAtAllArr);
|
|
880
906
|
const atAllArr = structuredClone(record.liveAtAllArr);
|
|
881
|
-
|
|
882
|
-
return await this.
|
|
907
|
+
await withRetry(async () => {
|
|
908
|
+
return await this.pushMessage(atAllArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("at", { type: "all" }) }));
|
|
883
909
|
}, 1);
|
|
884
|
-
this.logger.info(`成功推送全体成员消息:${success.length}条`);
|
|
885
910
|
}
|
|
886
911
|
if (type === PushType.Dynamic && record.dynamicArr?.length >= 1) {
|
|
887
912
|
if (record.dynamicAtAllArr?.length >= 1) {
|
|
888
913
|
this.logger.info(record.dynamicAtAllArr);
|
|
889
914
|
const dynamicAtAllArr = structuredClone(record.dynamicAtAllArr);
|
|
890
|
-
|
|
891
|
-
return await this.
|
|
915
|
+
await withRetry(async () => {
|
|
916
|
+
return await this.pushMessage(dynamicAtAllArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("at", { type: "all" }) }));
|
|
892
917
|
}, 1);
|
|
893
|
-
this.logger.info(`成功推送全体成员消息:${success$1.length}条`);
|
|
894
918
|
}
|
|
895
919
|
this.logger.info(record.dynamicArr);
|
|
896
920
|
const dynamicArr = structuredClone(record.dynamicArr);
|
|
897
|
-
|
|
898
|
-
return await this.
|
|
921
|
+
await withRetry(async () => {
|
|
922
|
+
return await this.pushMessage(dynamicArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
|
|
899
923
|
}, 1);
|
|
900
|
-
this.logger.info(`成功推送动态消息:${success.length}条`);
|
|
901
924
|
}
|
|
902
925
|
if ((type === PushType.Live || type === PushType.StartBroadcasting) && record.liveArr?.length >= 1) {
|
|
903
926
|
this.logger.info(record.liveArr);
|
|
904
927
|
const liveArr = structuredClone(record.liveArr);
|
|
905
|
-
|
|
906
|
-
return await this.
|
|
928
|
+
await withRetry(async () => {
|
|
929
|
+
return await this.pushMessage(liveArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
|
|
907
930
|
}, 1);
|
|
908
|
-
this.logger.info(`成功推送直播消息:${success.length}条`);
|
|
909
931
|
}
|
|
910
932
|
if (type === PushType.LiveGuardBuy && record.liveGuardBuyArr?.length >= 1) {
|
|
911
933
|
this.logger.info(record.liveGuardBuyArr);
|
|
912
934
|
const liveGuardBuyArr = structuredClone(record.liveGuardBuyArr);
|
|
913
|
-
|
|
914
|
-
return await this.
|
|
935
|
+
await withRetry(async () => {
|
|
936
|
+
return await this.pushMessage(liveGuardBuyArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content }));
|
|
915
937
|
}, 1);
|
|
916
|
-
this.logger.info(`成功推送上舰消息:${success.length}条`);
|
|
917
938
|
}
|
|
918
939
|
if (type === PushType.WordCloudAndLiveSummary) {
|
|
919
940
|
const wordcloudArr = structuredClone(record.wordcloudArr);
|
|
@@ -924,26 +945,23 @@ var ComRegister = class {
|
|
|
924
945
|
if (wordcloudAndLiveSummaryArr.length > 0) {
|
|
925
946
|
this.logger.info("词云和直播总结");
|
|
926
947
|
this.logger.info(wordcloudAndLiveSummaryArr);
|
|
927
|
-
|
|
928
|
-
return await this.
|
|
948
|
+
await withRetry(async () => {
|
|
949
|
+
return await this.pushMessage(wordcloudAndLiveSummaryArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)("message", { children: [content[0], content[1]] }));
|
|
929
950
|
}, 1);
|
|
930
|
-
this.logger.info(`成功推送词云和直播总结消息:${success.length}条`);
|
|
931
951
|
}
|
|
932
952
|
if (wordcloudOnlyArr.length > 0) {
|
|
933
953
|
this.logger.info("词云");
|
|
934
954
|
this.logger.info(wordcloudOnlyArr);
|
|
935
|
-
|
|
936
|
-
return await this.
|
|
955
|
+
await withRetry(async () => {
|
|
956
|
+
return await this.pushMessage(wordcloudOnlyArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content[0] }));
|
|
937
957
|
}, 1);
|
|
938
|
-
this.logger.info(`成功推送词云消息:${success.length}条`);
|
|
939
958
|
}
|
|
940
959
|
if (liveSummaryOnlyArr.length > 0) {
|
|
941
960
|
this.logger.info("直播总结");
|
|
942
961
|
this.logger.info(liveSummaryOnlyArr);
|
|
943
|
-
|
|
944
|
-
return await this.
|
|
962
|
+
await withRetry(async () => {
|
|
963
|
+
return await this.pushMessage(liveSummaryOnlyArr, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", { children: content[1] }));
|
|
945
964
|
}, 1);
|
|
946
|
-
this.logger.info(`成功推送直播总结消息:${success.length}条`);
|
|
947
965
|
}
|
|
948
966
|
}
|
|
949
967
|
}
|
package/lib/index.mjs
CHANGED
|
@@ -759,8 +759,14 @@ var ComRegister = class {
|
|
|
759
759
|
return this.ctx.bots.find((bot) => bot.platform === pf && bot.selfId === selfId);
|
|
760
760
|
}
|
|
761
761
|
async sendPrivateMsg(content) {
|
|
762
|
-
if (this.config.master.enable)
|
|
763
|
-
|
|
762
|
+
if (this.config.master.enable) {
|
|
763
|
+
if (this.privateBot.status !== Universal.Status.ONLINE) {
|
|
764
|
+
this.logger.error(`${this.privateBot.platform} 机器人未初始化完毕,无法进行推送`);
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
if (this.config.master.masterAccountGuildId) await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content, this.config.master.masterAccountGuildId);
|
|
768
|
+
else await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content);
|
|
769
|
+
}
|
|
764
770
|
}
|
|
765
771
|
async sendPrivateMsgAndRebootService() {
|
|
766
772
|
if (this.rebootCount >= 3) {
|
|
@@ -842,59 +848,74 @@ var ComRegister = class {
|
|
|
842
848
|
this.logger.info("初始化推送群组/频道信息:");
|
|
843
849
|
this.logger.info(this.pushArrMap);
|
|
844
850
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
this.ctx.setTimeout(() => {
|
|
852
|
-
this.broadcastToTargets(uid, content, type, retry * 2);
|
|
853
|
-
}, retry);
|
|
854
|
-
return;
|
|
851
|
+
async pushMessage(targets, content, retry = 3e3) {
|
|
852
|
+
const t = {};
|
|
853
|
+
for (const target of targets) {
|
|
854
|
+
const [platform, channleId] = target.split(":");
|
|
855
|
+
if (!t[platform]) t[platform] = [channleId];
|
|
856
|
+
else t[platform].push(channleId);
|
|
855
857
|
}
|
|
858
|
+
for (const platform of Object.keys(t)) {
|
|
859
|
+
const bots = [];
|
|
860
|
+
for (const bot of this.ctx.bots) if (bot.platform === platform) bots.push(bot);
|
|
861
|
+
botloop: for (const bot of bots) {
|
|
862
|
+
if (bot.status !== Universal.Status.ONLINE) {
|
|
863
|
+
this.logger.error(`${platform} 机器人未初始化完毕,无法进行推送,${retry / 1e3}秒后重试`);
|
|
864
|
+
this.ctx.setTimeout(async () => {
|
|
865
|
+
await this.pushMessage(targets, content, retry * 2);
|
|
866
|
+
}, retry);
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
let num = 0;
|
|
870
|
+
for (const channelId of t[platform]) try {
|
|
871
|
+
await bot.sendMessage(channelId, content);
|
|
872
|
+
num++;
|
|
873
|
+
} catch (e) {
|
|
874
|
+
this.logger.error(e);
|
|
875
|
+
if (bots.length > 1) continue botloop;
|
|
876
|
+
}
|
|
877
|
+
this.logger.info(`成功推送消息 ${num} 条`);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
async broadcastToTargets(uid, content, type) {
|
|
856
882
|
this.logger.info(`本次推送对象:${uid},推送类型:${PushTypeMsg[type]}`);
|
|
857
883
|
const record = this.pushArrMap.get(uid);
|
|
858
884
|
this.logger.info("本次推送目标:");
|
|
859
885
|
if (type === PushType.StartBroadcasting && record.liveAtAllArr?.length >= 1) {
|
|
860
886
|
this.logger.info(record.liveAtAllArr);
|
|
861
887
|
const atAllArr = structuredClone(record.liveAtAllArr);
|
|
862
|
-
|
|
863
|
-
return await this.
|
|
888
|
+
await withRetry(async () => {
|
|
889
|
+
return await this.pushMessage(atAllArr, /* @__PURE__ */ jsx("message", { children: /* @__PURE__ */ jsx("at", { type: "all" }) }));
|
|
864
890
|
}, 1);
|
|
865
|
-
this.logger.info(`成功推送全体成员消息:${success.length}条`);
|
|
866
891
|
}
|
|
867
892
|
if (type === PushType.Dynamic && record.dynamicArr?.length >= 1) {
|
|
868
893
|
if (record.dynamicAtAllArr?.length >= 1) {
|
|
869
894
|
this.logger.info(record.dynamicAtAllArr);
|
|
870
895
|
const dynamicAtAllArr = structuredClone(record.dynamicAtAllArr);
|
|
871
|
-
|
|
872
|
-
return await this.
|
|
896
|
+
await withRetry(async () => {
|
|
897
|
+
return await this.pushMessage(dynamicAtAllArr, /* @__PURE__ */ jsx("message", { children: /* @__PURE__ */ jsx("at", { type: "all" }) }));
|
|
873
898
|
}, 1);
|
|
874
|
-
this.logger.info(`成功推送全体成员消息:${success$1.length}条`);
|
|
875
899
|
}
|
|
876
900
|
this.logger.info(record.dynamicArr);
|
|
877
901
|
const dynamicArr = structuredClone(record.dynamicArr);
|
|
878
|
-
|
|
879
|
-
return await this.
|
|
902
|
+
await withRetry(async () => {
|
|
903
|
+
return await this.pushMessage(dynamicArr, /* @__PURE__ */ jsx("message", { children: content }));
|
|
880
904
|
}, 1);
|
|
881
|
-
this.logger.info(`成功推送动态消息:${success.length}条`);
|
|
882
905
|
}
|
|
883
906
|
if ((type === PushType.Live || type === PushType.StartBroadcasting) && record.liveArr?.length >= 1) {
|
|
884
907
|
this.logger.info(record.liveArr);
|
|
885
908
|
const liveArr = structuredClone(record.liveArr);
|
|
886
|
-
|
|
887
|
-
return await this.
|
|
909
|
+
await withRetry(async () => {
|
|
910
|
+
return await this.pushMessage(liveArr, /* @__PURE__ */ jsx("message", { children: content }));
|
|
888
911
|
}, 1);
|
|
889
|
-
this.logger.info(`成功推送直播消息:${success.length}条`);
|
|
890
912
|
}
|
|
891
913
|
if (type === PushType.LiveGuardBuy && record.liveGuardBuyArr?.length >= 1) {
|
|
892
914
|
this.logger.info(record.liveGuardBuyArr);
|
|
893
915
|
const liveGuardBuyArr = structuredClone(record.liveGuardBuyArr);
|
|
894
|
-
|
|
895
|
-
return await this.
|
|
916
|
+
await withRetry(async () => {
|
|
917
|
+
return await this.pushMessage(liveGuardBuyArr, /* @__PURE__ */ jsx("message", { children: content }));
|
|
896
918
|
}, 1);
|
|
897
|
-
this.logger.info(`成功推送上舰消息:${success.length}条`);
|
|
898
919
|
}
|
|
899
920
|
if (type === PushType.WordCloudAndLiveSummary) {
|
|
900
921
|
const wordcloudArr = structuredClone(record.wordcloudArr);
|
|
@@ -905,26 +926,23 @@ var ComRegister = class {
|
|
|
905
926
|
if (wordcloudAndLiveSummaryArr.length > 0) {
|
|
906
927
|
this.logger.info("词云和直播总结");
|
|
907
928
|
this.logger.info(wordcloudAndLiveSummaryArr);
|
|
908
|
-
|
|
909
|
-
return await this.
|
|
929
|
+
await withRetry(async () => {
|
|
930
|
+
return await this.pushMessage(wordcloudAndLiveSummaryArr, /* @__PURE__ */ jsxs("message", { children: [content[0], content[1]] }));
|
|
910
931
|
}, 1);
|
|
911
|
-
this.logger.info(`成功推送词云和直播总结消息:${success.length}条`);
|
|
912
932
|
}
|
|
913
933
|
if (wordcloudOnlyArr.length > 0) {
|
|
914
934
|
this.logger.info("词云");
|
|
915
935
|
this.logger.info(wordcloudOnlyArr);
|
|
916
|
-
|
|
917
|
-
return await this.
|
|
936
|
+
await withRetry(async () => {
|
|
937
|
+
return await this.pushMessage(wordcloudOnlyArr, /* @__PURE__ */ jsx("message", { children: content[0] }));
|
|
918
938
|
}, 1);
|
|
919
|
-
this.logger.info(`成功推送词云消息:${success.length}条`);
|
|
920
939
|
}
|
|
921
940
|
if (liveSummaryOnlyArr.length > 0) {
|
|
922
941
|
this.logger.info("直播总结");
|
|
923
942
|
this.logger.info(liveSummaryOnlyArr);
|
|
924
|
-
|
|
925
|
-
return await this.
|
|
943
|
+
await withRetry(async () => {
|
|
944
|
+
return await this.pushMessage(liveSummaryOnlyArr, /* @__PURE__ */ jsx("message", { children: content[1] }));
|
|
926
945
|
}, 1);
|
|
927
|
-
this.logger.info(`成功推送直播总结消息:${success.length}条`);
|
|
928
946
|
}
|
|
929
947
|
}
|
|
930
948
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -334,6 +334,9 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
|
|
|
334
334
|
> - ver 3.3.1 优化:如果不订阅UP主直播且未填写房间号不再请求用户接口;
|
|
335
335
|
> - ver 3.3.2 修复:当插件因动态报错停止后,应使用指令 `bn start` 启动插件,而不是 `bn restart`;
|
|
336
336
|
> - ver 3.3.3 优化:初始化logger输出; 修复:B站订阅操作bug;
|
|
337
|
+
> - ver 3.3.4-alpha.0 优化:在错误消息向主人帐号推送前会先进行机器人状态判断; 重构:部分重构消息发送逻辑;
|
|
338
|
+
> - ver 3.3.4-alpha.1 修复: CI错误;
|
|
339
|
+
> - ver 3.3.4-alpha.2 修复: 推送消息时发送6000的bug;
|
|
337
340
|
|
|
338
341
|
## 交流群
|
|
339
342
|
|