koishi-plugin-bilibili-notify 3.0.5-alpha.1 → 3.1.0-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/comRegister.d.ts +2 -3
- package/lib/comRegister.js +42 -62
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -4
- package/package.json +1 -2
- package/readme.md +2 -0
package/lib/comRegister.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ declare class ComRegister {
|
|
|
16
16
|
loginDBData: FlatPick<LoginBili, "dynamic_group_id">;
|
|
17
17
|
privateBot: Bot<Context>;
|
|
18
18
|
dynamicDispose: () => void;
|
|
19
|
-
sendMsgFunc: (bot: Bot<Context, any>, channelId: string, content: any) => Promise<void>;
|
|
20
19
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
21
20
|
init(config: ComRegister.Config): Promise<void>;
|
|
22
21
|
getBot(pf: string): Bot<Context, any>;
|
|
@@ -24,7 +23,8 @@ declare class ComRegister {
|
|
|
24
23
|
sendPrivateMsg(content: string): Promise<void>;
|
|
25
24
|
sendPrivateMsgAndRebootService(): Promise<void>;
|
|
26
25
|
sendPrivateMsgAndStopService(): Promise<void>;
|
|
27
|
-
|
|
26
|
+
sendMessageWithRetry(broadcastTarget: string[], content: any): Promise<void>;
|
|
27
|
+
broadcastToTargets(targets: Target, content: any, live?: boolean): Promise<void>;
|
|
28
28
|
dynamicDetect(): (...args: any[]) => void;
|
|
29
29
|
debug_dynamicDetect(): (...args: any[]) => void;
|
|
30
30
|
useMasterInfo(uid: string, masterInfo: MasterInfo, liveType: LiveType): Promise<MasterInfo>;
|
|
@@ -73,7 +73,6 @@ declare namespace ComRegister {
|
|
|
73
73
|
masterAccount: string;
|
|
74
74
|
masterAccountGuildId: string;
|
|
75
75
|
};
|
|
76
|
-
automaticResend: boolean;
|
|
77
76
|
liveDetectMode: "API" | "WS";
|
|
78
77
|
restartPush: boolean;
|
|
79
78
|
pushTime: number;
|
package/lib/comRegister.js
CHANGED
|
@@ -48,8 +48,6 @@ class ComRegister {
|
|
|
48
48
|
privateBot;
|
|
49
49
|
// 动态检测销毁函数
|
|
50
50
|
dynamicDispose;
|
|
51
|
-
// 发送消息方式
|
|
52
|
-
sendMsgFunc;
|
|
53
51
|
// 构造函数
|
|
54
52
|
constructor(ctx, config) {
|
|
55
53
|
// 将ctx赋值给类属性
|
|
@@ -286,49 +284,6 @@ class ComRegister {
|
|
|
286
284
|
content: "您未配置私人机器人,将无法向您推送机器人状态!",
|
|
287
285
|
});
|
|
288
286
|
}
|
|
289
|
-
// 判断消息发送方式
|
|
290
|
-
if (config.automaticResend) {
|
|
291
|
-
this.sendMsgFunc = async (
|
|
292
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
293
|
-
bot, channelId,
|
|
294
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
295
|
-
content) => {
|
|
296
|
-
(0, utils_1.withRetry)(async () => await bot.sendMessage(channelId, content)).catch(async (e) => {
|
|
297
|
-
if (e.message === "this._request is not a function") {
|
|
298
|
-
// 2S之后重新发送消息
|
|
299
|
-
this.ctx.setTimeout(async () => {
|
|
300
|
-
await this.sendMsgFunc(bot, channelId, content);
|
|
301
|
-
}, 2000);
|
|
302
|
-
// 返回
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
// 打印错误信息
|
|
306
|
-
this.logger.error(`发送群组ID:${channelId}消息失败!原因: ${e.message}`);
|
|
307
|
-
await this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
|
|
308
|
-
});
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
this.sendMsgFunc = async (
|
|
313
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
314
|
-
bot, channelId,
|
|
315
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
316
|
-
content) => {
|
|
317
|
-
(0, utils_1.withRetry)(async () => await bot.sendMessage(channelId, content), 1).catch(async (e) => {
|
|
318
|
-
if (e.message === "this._request is not a function") {
|
|
319
|
-
// 2S之后重新发送消息
|
|
320
|
-
this.ctx.setTimeout(async () => {
|
|
321
|
-
await this.sendMsgFunc(bot, channelId, content);
|
|
322
|
-
}, 2000);
|
|
323
|
-
// 返回
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
// 打印错误信息
|
|
327
|
-
this.logger.error(`发送群组ID:${channelId}消息失败!原因: ${e.message}`);
|
|
328
|
-
await this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
|
|
329
|
-
});
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
287
|
// 检查登录数据库是否有数据
|
|
333
288
|
this.loginDBData = (await this.ctx.database.get("loginBili", 1, ["dynamic_group_id"]))[0];
|
|
334
289
|
// 判断登录信息是否已加载完毕
|
|
@@ -450,8 +405,26 @@ class ComRegister {
|
|
|
450
405
|
// 结束
|
|
451
406
|
return;
|
|
452
407
|
}
|
|
408
|
+
async sendMessageWithRetry(broadcastTarget,
|
|
453
409
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
454
|
-
|
|
410
|
+
content) {
|
|
411
|
+
(0, utils_1.withRetry)(async () => await this.ctx.broadcast(broadcastTarget, content), 1).catch(async (e) => {
|
|
412
|
+
if (e.message === "this._request is not a function") {
|
|
413
|
+
// 2S之后重新发送消息
|
|
414
|
+
this.ctx.setTimeout(async () => {
|
|
415
|
+
await this.sendMessageWithRetry(broadcastTarget, content);
|
|
416
|
+
}, 2000);
|
|
417
|
+
// 返回
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
// 打印错误信息
|
|
421
|
+
this.logger.error(`发送群组ID:${broadcastTarget[0]}消息失败!原因: ${e.message}`);
|
|
422
|
+
await this.sendPrivateMsg(`发送群组ID:${broadcastTarget[0]}消息失败,请查看日志`);
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
;
|
|
426
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
427
|
+
async broadcastToTargets(targets, content, live) {
|
|
455
428
|
for (const target of targets) {
|
|
456
429
|
// 获取机器人实例
|
|
457
430
|
const bot = this.getBot(target.platform);
|
|
@@ -477,21 +450,25 @@ class ComRegister {
|
|
|
477
450
|
if (live) {
|
|
478
451
|
// 直播开播推送,判断是否需要艾特全体成员
|
|
479
452
|
for (const channel of sendArr) {
|
|
453
|
+
// 构建广播目标
|
|
454
|
+
const broadcastTarget = [`${target.platform}:${channel.channelId}`];
|
|
480
455
|
// 判断是否需要推送直播消息
|
|
481
456
|
if (channel.live) {
|
|
482
|
-
await this.
|
|
457
|
+
await this.sendMessageWithRetry(broadcastTarget, content);
|
|
483
458
|
}
|
|
484
459
|
// 判断是否需要艾特全体成员
|
|
485
460
|
if (channel.atAll) {
|
|
486
|
-
await this.
|
|
461
|
+
await this.sendMessageWithRetry(broadcastTarget, (0, jsx_runtime_1.jsx)("at", { type: "all" }));
|
|
487
462
|
}
|
|
488
463
|
}
|
|
489
464
|
}
|
|
490
465
|
else {
|
|
491
466
|
for (const channel of sendArr) {
|
|
467
|
+
// 构建广播目标
|
|
468
|
+
const broadcastTarget = [`${target.platform}:${channel.channelId}`];
|
|
492
469
|
// 判断是否需要推送动态消息
|
|
493
470
|
if (channel.dynamic || channel.live) {
|
|
494
|
-
await this.
|
|
471
|
+
await this.sendMessageWithRetry(broadcastTarget, content);
|
|
495
472
|
}
|
|
496
473
|
}
|
|
497
474
|
}
|
|
@@ -624,13 +601,13 @@ class ComRegister {
|
|
|
624
601
|
if (e.message === "出现关键词,屏蔽该动态") {
|
|
625
602
|
// 如果需要发送才发送
|
|
626
603
|
if (this.config.filter.notify) {
|
|
627
|
-
await this.
|
|
604
|
+
await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
|
|
628
605
|
}
|
|
629
606
|
return;
|
|
630
607
|
}
|
|
631
608
|
if (e.message === "已屏蔽转发动态") {
|
|
632
609
|
if (this.config.filter.notify) {
|
|
633
|
-
await this.
|
|
610
|
+
await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`);
|
|
634
611
|
}
|
|
635
612
|
return;
|
|
636
613
|
}
|
|
@@ -649,7 +626,7 @@ class ComRegister {
|
|
|
649
626
|
// logger
|
|
650
627
|
this.logger.info("推送动态中...");
|
|
651
628
|
// 发送推送卡片
|
|
652
|
-
await this.
|
|
629
|
+
await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }));
|
|
653
630
|
// 判断是否需要发送动态中的图片
|
|
654
631
|
if (this.config.pushImgsInDynamic) {
|
|
655
632
|
// 判断是否为图文动态,且存在draw
|
|
@@ -657,7 +634,7 @@ class ComRegister {
|
|
|
657
634
|
item.modules.module_dynamic.major?.draw) {
|
|
658
635
|
for (const img of item.modules.module_dynamic.major.draw
|
|
659
636
|
.items) {
|
|
660
|
-
await this.
|
|
637
|
+
await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }));
|
|
661
638
|
}
|
|
662
639
|
}
|
|
663
640
|
}
|
|
@@ -842,13 +819,13 @@ class ComRegister {
|
|
|
842
819
|
if (e.message === "出现关键词,屏蔽该动态") {
|
|
843
820
|
// 如果需要发送才发送
|
|
844
821
|
if (this.config.filter.notify) {
|
|
845
|
-
await this.
|
|
822
|
+
await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
|
|
846
823
|
}
|
|
847
824
|
return;
|
|
848
825
|
}
|
|
849
826
|
if (e.message === "已屏蔽转发动态") {
|
|
850
827
|
if (this.config.filter.notify) {
|
|
851
|
-
await this.
|
|
828
|
+
await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`);
|
|
852
829
|
}
|
|
853
830
|
return;
|
|
854
831
|
}
|
|
@@ -876,7 +853,7 @@ class ComRegister {
|
|
|
876
853
|
// logger
|
|
877
854
|
this.logger.info("推送动态中...");
|
|
878
855
|
// 发送推送卡片
|
|
879
|
-
await this.
|
|
856
|
+
await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }));
|
|
880
857
|
// logger
|
|
881
858
|
this.logger.info("动态推送完毕!");
|
|
882
859
|
// 判断是否需要发送动态中的图片
|
|
@@ -888,7 +865,7 @@ class ComRegister {
|
|
|
888
865
|
item.modules.module_dynamic.major?.draw) {
|
|
889
866
|
for (const img of item.modules.module_dynamic.major.draw
|
|
890
867
|
.items) {
|
|
891
|
-
await this.
|
|
868
|
+
await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }));
|
|
892
869
|
}
|
|
893
870
|
}
|
|
894
871
|
// logger
|
|
@@ -997,7 +974,7 @@ class ComRegister {
|
|
|
997
974
|
// 推送直播信息
|
|
998
975
|
const msg = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), liveNotifyMsg || ""] }));
|
|
999
976
|
// 只有在开播时才艾特全体成员
|
|
1000
|
-
return await this.
|
|
977
|
+
return await this.broadcastToTargets(target, msg, liveType === type_1.LiveType.StartBroadcasting);
|
|
1001
978
|
};
|
|
1002
979
|
// 找到频道/群组对应的
|
|
1003
980
|
const liveGuardBuyPushTargetArr = target.map((channel) => {
|
|
@@ -1080,7 +1057,7 @@ class ComRegister {
|
|
|
1080
1057
|
// 定义消息
|
|
1081
1058
|
const content = `[${masterInfo.username}的直播间]「${body.user.uname}」加入了大航海(${body.gift_name})`;
|
|
1082
1059
|
// 直接发送消息
|
|
1083
|
-
channelIdArrLen > 0 && this.
|
|
1060
|
+
channelIdArrLen > 0 && this.broadcastToTargets(liveGuardBuyPushTargetArr, content);
|
|
1084
1061
|
},
|
|
1085
1062
|
onLiveStart: async () => {
|
|
1086
1063
|
// 判断是否已经开播
|
|
@@ -1257,8 +1234,12 @@ class ComRegister {
|
|
|
1257
1234
|
if (group.name === "订阅") {
|
|
1258
1235
|
// 拿到分组id
|
|
1259
1236
|
this.loginDBData.dynamic_group_id = group.tagid;
|
|
1260
|
-
//
|
|
1261
|
-
|
|
1237
|
+
// 保存到数据库
|
|
1238
|
+
this.ctx.database.set("loginBili", 1, {
|
|
1239
|
+
dynamic_group_id: this.loginDBData.dynamic_group_id,
|
|
1240
|
+
});
|
|
1241
|
+
// 返回分组已存在
|
|
1242
|
+
return { code: 0, msg: "分组已存在" };
|
|
1262
1243
|
}
|
|
1263
1244
|
}
|
|
1264
1245
|
}
|
|
@@ -1546,7 +1527,6 @@ class ComRegister {
|
|
|
1546
1527
|
masterAccount: koishi_1.Schema.string(),
|
|
1547
1528
|
masterAccountGuildId: koishi_1.Schema.string(),
|
|
1548
1529
|
}),
|
|
1549
|
-
automaticResend: koishi_1.Schema.boolean().required(),
|
|
1550
1530
|
liveDetectMode: koishi_1.Schema.union([
|
|
1551
1531
|
koishi_1.Schema.const("API"),
|
|
1552
1532
|
koishi_1.Schema.const("WS"),
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -127,7 +127,6 @@ class ServerManager extends koishi_1.Service {
|
|
|
127
127
|
subLoadTimeout: globalConfig.subLoadTimeout,
|
|
128
128
|
sub: globalConfig.sub,
|
|
129
129
|
master: globalConfig.master,
|
|
130
|
-
automaticResend: globalConfig.automaticResend,
|
|
131
130
|
liveDetectMode: globalConfig.liveDetectMode,
|
|
132
131
|
restartPush: globalConfig.restartPush,
|
|
133
132
|
pushTime: globalConfig.pushTime,
|
|
@@ -254,9 +253,6 @@ exports.Config = koishi_1.Schema.object({
|
|
|
254
253
|
]),
|
|
255
254
|
]),
|
|
256
255
|
basicSettings: koishi_1.Schema.object({}).description("基本设置"),
|
|
257
|
-
automaticResend: koishi_1.Schema.boolean()
|
|
258
|
-
.default(true)
|
|
259
|
-
.description("是否开启自动重发功能,默认开启。开启后,如果推送失败,将会自动重发,尝试三次。关闭后,推送失败将不会再重发,直到下一次推送"),
|
|
260
256
|
userAgent: koishi_1.Schema.string()
|
|
261
257
|
.required()
|
|
262
258
|
.description("设置请求头User-Agen,请求出现-352时可以尝试修改,UA获取方法可参考:https://blog.csdn.net/qq_44503987/article/details/104929111"),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-bilibili-notify",
|
|
3
3
|
"description": "Koishi bilibili notify plugin",
|
|
4
|
-
"version": "3.0
|
|
4
|
+
"version": "3.1.0-alpha.0",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Akokko <admin@akokko.com>"
|
|
7
7
|
],
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"koishi": "^4.18.7"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@napi-rs/canvas": "^0.1.69",
|
|
31
30
|
"axios": "^1.7.9",
|
|
32
31
|
"axios-cookiejar-support": "^5.0.5",
|
|
33
32
|
"blive-message-listener": "^0.5.0",
|
package/readme.md
CHANGED
|
@@ -229,6 +229,8 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
|
|
|
229
229
|
- ver 3.0.4 优化:动态监测,增加时间判断,防止出现重复推送问题; 由于 `3.0.2` 动态监测定时器更换为cron定时任务,如果需要测试动态监测功能是否正常,可以通过控制台日志输出观察,打印 `动态监测初始化完毕!` 后,可进行测试
|
|
230
230
|
- ver 3.0.5-alpha.0 优化:推送卡片渲染,压缩图片; 新增:指令 `bili dyn` 可用于推送指定UP主指定动态
|
|
231
231
|
- ver 3.0.5-alpha.1 优化:推送卡片渲染,调整渲染图片格式为 `jpeg`
|
|
232
|
+
- ver 3.0.5-alpha.2 优化:移除多余依赖
|
|
233
|
+
- ver 3.1.0-alpha.0 修复:新插件在第一次订阅时提示 `订阅失败,错误信息:该分组已经存在`; 移除:消息重发功能; 重构:将消息发送模式改为 `broadcast`
|
|
232
234
|
|
|
233
235
|
## 交流群
|
|
234
236
|
|