koishi-plugin-bilibili-notify 3.1.0-alpha.1 → 3.1.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 -2
- package/lib/comRegister.js +59 -35
- package/lib/index.js +1 -1
- package/lib/type/index.d.ts +6 -0
- package/lib/type/index.js +8 -1
- package/package.json +1 -1
- package/readme.md +1 -0
package/lib/comRegister.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Bot, type Context, type FlatPick, type Logger, Schema } from "koishi";
|
|
2
2
|
import type { Notifier } from "@koishijs/plugin-notifier";
|
|
3
3
|
import type { LoginBili } from "./database";
|
|
4
|
-
import { LiveType, type MasterInfo, type SubItem, type SubManager, type Target } from "./type";
|
|
4
|
+
import { LiveType, type MasterInfo, PushType, type SubItem, type SubManager, type Target } from "./type";
|
|
5
5
|
declare class ComRegister {
|
|
6
6
|
static inject: string[];
|
|
7
7
|
qqRelatedBotList: Array<string>;
|
|
@@ -24,7 +24,7 @@ declare class ComRegister {
|
|
|
24
24
|
sendPrivateMsgAndRebootService(): Promise<void>;
|
|
25
25
|
sendPrivateMsgAndStopService(): Promise<void>;
|
|
26
26
|
sendMessageWithRetry(bot: Bot<Context>, channelId: string, content: any): Promise<void>;
|
|
27
|
-
broadcastToTargets(targets: Target, content: any,
|
|
27
|
+
broadcastToTargets(targets: Target, content: any, type: PushType): 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>;
|
package/lib/comRegister.js
CHANGED
|
@@ -423,7 +423,7 @@ class ComRegister {
|
|
|
423
423
|
});
|
|
424
424
|
}
|
|
425
425
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
426
|
-
async broadcastToTargets(targets, content,
|
|
426
|
+
async broadcastToTargets(targets, content, type) {
|
|
427
427
|
for (const target of targets) {
|
|
428
428
|
// 获取机器人实例
|
|
429
429
|
const bot = this.getBot(target.platform);
|
|
@@ -445,33 +445,57 @@ class ComRegister {
|
|
|
445
445
|
else {
|
|
446
446
|
channelArr = target.channelArr;
|
|
447
447
|
}
|
|
448
|
-
//
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
448
|
+
// 模式匹配
|
|
449
|
+
const pushTypePatternMatching = {
|
|
450
|
+
[type_1.PushType.Live]: async () => {
|
|
451
|
+
for (const channel of channelArr) {
|
|
452
|
+
// 判断是否需要推送动态消息
|
|
453
|
+
if (channel.live) {
|
|
454
|
+
await this.sendMessageWithRetry(bot, channel.channelId, content);
|
|
455
|
+
}
|
|
456
|
+
// 延迟发送
|
|
457
|
+
await this.ctx.sleep(500);
|
|
455
458
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
+
},
|
|
460
|
+
[type_1.PushType.Dynamic]: async () => {
|
|
461
|
+
for (const channel of channelArr) {
|
|
462
|
+
// 判断是否需要推送动态消息
|
|
463
|
+
if (channel.live) {
|
|
464
|
+
await this.sendMessageWithRetry(bot, channel.channelId, content);
|
|
465
|
+
}
|
|
466
|
+
// 延迟发送
|
|
467
|
+
await this.ctx.sleep(500);
|
|
459
468
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
469
|
+
},
|
|
470
|
+
[type_1.PushType.StartBroadcasting]: async () => {
|
|
471
|
+
// 直播开播推送,判断是否需要艾特全体成员
|
|
472
|
+
for (const channel of channelArr) {
|
|
473
|
+
// 判断是否需要推送直播消息
|
|
474
|
+
if (channel.live) {
|
|
475
|
+
await this.sendMessageWithRetry(bot, channel.channelId, content);
|
|
476
|
+
}
|
|
477
|
+
// 判断是否需要艾特全体成员
|
|
478
|
+
if (channel.atAll) {
|
|
479
|
+
await this.sendMessageWithRetry(bot, channel.channelId, (0, jsx_runtime_1.jsx)("at", { type: "all" }));
|
|
480
|
+
}
|
|
481
|
+
// 延迟发送
|
|
482
|
+
await this.ctx.sleep(500);
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
[type_1.PushType.LiveGuardBuy]: async () => {
|
|
486
|
+
// 直播守护购买推送,判断是否需要艾特全体成员
|
|
487
|
+
for (const channel of channelArr) {
|
|
488
|
+
// 判断是否需要推送直播消息
|
|
489
|
+
if (channel.liveGuardBuy) {
|
|
490
|
+
await this.sendMessageWithRetry(bot, channel.channelId, content);
|
|
491
|
+
}
|
|
492
|
+
// 延迟发送
|
|
493
|
+
await this.ctx.sleep(500);
|
|
470
494
|
}
|
|
471
|
-
// 延迟发送
|
|
472
|
-
await this.ctx.sleep(500);
|
|
473
495
|
}
|
|
474
|
-
}
|
|
496
|
+
};
|
|
497
|
+
// 推送
|
|
498
|
+
await pushTypePatternMatching[type]();
|
|
475
499
|
}
|
|
476
500
|
}
|
|
477
501
|
dynamicDetect() {
|
|
@@ -588,7 +612,7 @@ class ComRegister {
|
|
|
588
612
|
// 寻找关注的UP主的动态
|
|
589
613
|
for (const sub of this.subManager) {
|
|
590
614
|
// 判断是否是订阅的UP主
|
|
591
|
-
if (sub.
|
|
615
|
+
if (sub.uid === upUID && sub.dynamic) {
|
|
592
616
|
// 订阅该UP主,推送该动态
|
|
593
617
|
// 推送该条动态
|
|
594
618
|
const buffer = await (0, utils_1.withRetry)(async () => {
|
|
@@ -601,13 +625,13 @@ class ComRegister {
|
|
|
601
625
|
if (e.message === "出现关键词,屏蔽该动态") {
|
|
602
626
|
// 如果需要发送才发送
|
|
603
627
|
if (this.config.filter.notify) {
|
|
604
|
-
await this.broadcastToTargets(sub.target, `${upName}
|
|
628
|
+
await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`, type_1.PushType.Dynamic);
|
|
605
629
|
}
|
|
606
630
|
return;
|
|
607
631
|
}
|
|
608
632
|
if (e.message === "已屏蔽转发动态") {
|
|
609
633
|
if (this.config.filter.notify) {
|
|
610
|
-
await this.broadcastToTargets(sub.target, `${upName}
|
|
634
|
+
await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`, type_1.PushType.Dynamic);
|
|
611
635
|
}
|
|
612
636
|
return;
|
|
613
637
|
}
|
|
@@ -626,7 +650,7 @@ class ComRegister {
|
|
|
626
650
|
// logger
|
|
627
651
|
this.logger.info("推送动态中...");
|
|
628
652
|
// 发送推送卡片
|
|
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
|
+
await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }), type_1.PushType.Dynamic);
|
|
630
654
|
// 判断是否需要发送动态中的图片
|
|
631
655
|
if (this.config.pushImgsInDynamic) {
|
|
632
656
|
// 判断是否为图文动态,且存在draw
|
|
@@ -634,7 +658,7 @@ class ComRegister {
|
|
|
634
658
|
item.modules.module_dynamic.major?.draw) {
|
|
635
659
|
for (const img of item.modules.module_dynamic.major.draw
|
|
636
660
|
.items) {
|
|
637
|
-
await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }));
|
|
661
|
+
await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }), type_1.PushType.Dynamic);
|
|
638
662
|
}
|
|
639
663
|
}
|
|
640
664
|
}
|
|
@@ -819,13 +843,13 @@ class ComRegister {
|
|
|
819
843
|
if (e.message === "出现关键词,屏蔽该动态") {
|
|
820
844
|
// 如果需要发送才发送
|
|
821
845
|
if (this.config.filter.notify) {
|
|
822
|
-
await this.broadcastToTargets(sub.target, `${upName}
|
|
846
|
+
await this.broadcastToTargets(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`, type_1.PushType.Dynamic);
|
|
823
847
|
}
|
|
824
848
|
return;
|
|
825
849
|
}
|
|
826
850
|
if (e.message === "已屏蔽转发动态") {
|
|
827
851
|
if (this.config.filter.notify) {
|
|
828
|
-
await this.broadcastToTargets(sub.target, `${upName}
|
|
852
|
+
await this.broadcastToTargets(sub.target, `${upName}转发了一条动态,已屏蔽`, type_1.PushType.Dynamic);
|
|
829
853
|
}
|
|
830
854
|
return;
|
|
831
855
|
}
|
|
@@ -853,7 +877,7 @@ class ComRegister {
|
|
|
853
877
|
// logger
|
|
854
878
|
this.logger.info("推送动态中...");
|
|
855
879
|
// 发送推送卡片
|
|
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
|
+
await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), dUrl] }), type_1.PushType.Dynamic);
|
|
857
881
|
// logger
|
|
858
882
|
this.logger.info("动态推送完毕!");
|
|
859
883
|
// 判断是否需要发送动态中的图片
|
|
@@ -865,7 +889,7 @@ class ComRegister {
|
|
|
865
889
|
item.modules.module_dynamic.major?.draw) {
|
|
866
890
|
for (const img of item.modules.module_dynamic.major.draw
|
|
867
891
|
.items) {
|
|
868
|
-
await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }));
|
|
892
|
+
await this.broadcastToTargets(sub.target, (0, jsx_runtime_1.jsx)("img", { src: img.src, alt: "\u52A8\u6001\u56FE\u7247" }), type_1.PushType.Dynamic);
|
|
869
893
|
}
|
|
870
894
|
}
|
|
871
895
|
// logger
|
|
@@ -974,7 +998,7 @@ class ComRegister {
|
|
|
974
998
|
// 推送直播信息
|
|
975
999
|
const msg = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/jpeg"), liveNotifyMsg || ""] }));
|
|
976
1000
|
// 只有在开播时才艾特全体成员
|
|
977
|
-
return await this.broadcastToTargets(target, msg, liveType === type_1.LiveType.StartBroadcasting);
|
|
1001
|
+
return await this.broadcastToTargets(target, msg, liveType === type_1.LiveType.StartBroadcasting ? type_1.PushType.StartBroadcasting : type_1.PushType.Live);
|
|
978
1002
|
};
|
|
979
1003
|
// 找到频道/群组对应的
|
|
980
1004
|
const liveGuardBuyPushTargetArr = target.map((channel) => {
|
|
@@ -1058,7 +1082,7 @@ class ComRegister {
|
|
|
1058
1082
|
const content = `[${masterInfo.username}的直播间]「${body.user.uname}」加入了大航海(${body.gift_name})`;
|
|
1059
1083
|
// 直接发送消息
|
|
1060
1084
|
channelArrLen > 0 &&
|
|
1061
|
-
this.broadcastToTargets(liveGuardBuyPushTargetArr, content);
|
|
1085
|
+
this.broadcastToTargets(liveGuardBuyPushTargetArr, content, type_1.PushType.LiveGuardBuy);
|
|
1062
1086
|
},
|
|
1063
1087
|
onLiveStart: async () => {
|
|
1064
1088
|
// 判断是否已经开播
|
package/lib/index.js
CHANGED
|
@@ -196,7 +196,7 @@ function apply(ctx, config) {
|
|
|
196
196
|
// 设置提示
|
|
197
197
|
ctx.notifier.create({
|
|
198
198
|
type: "danger",
|
|
199
|
-
content: "从3.1.0-alpha.0及以前版本升级到3.1.0-alpha.1
|
|
199
|
+
content: "从3.1.0-alpha.0及以前版本升级到3.1.0-alpha.1及以后版本必定报错,请重新填写订阅配置中sub.target.channelArr的内容",
|
|
200
200
|
});
|
|
201
201
|
ctx.notifier.create({
|
|
202
202
|
type: "warning",
|
package/lib/type/index.d.ts
CHANGED
package/lib/type/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LiveType = void 0;
|
|
3
|
+
exports.PushType = exports.LiveType = void 0;
|
|
4
4
|
var LiveType;
|
|
5
5
|
(function (LiveType) {
|
|
6
6
|
LiveType[LiveType["NotLiveBroadcast"] = 0] = "NotLiveBroadcast";
|
|
@@ -9,3 +9,10 @@ var LiveType;
|
|
|
9
9
|
LiveType[LiveType["StopBroadcast"] = 3] = "StopBroadcast";
|
|
10
10
|
LiveType[LiveType["FirstLiveBroadcast"] = 4] = "FirstLiveBroadcast";
|
|
11
11
|
})(LiveType || (exports.LiveType = LiveType = {}));
|
|
12
|
+
var PushType;
|
|
13
|
+
(function (PushType) {
|
|
14
|
+
PushType[PushType["Live"] = 0] = "Live";
|
|
15
|
+
PushType[PushType["Dynamic"] = 1] = "Dynamic";
|
|
16
|
+
PushType[PushType["StartBroadcasting"] = 2] = "StartBroadcasting";
|
|
17
|
+
PushType[PushType["LiveGuardBuy"] = 3] = "LiveGuardBuy";
|
|
18
|
+
})(PushType || (exports.PushType = PushType = {}));
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -232,6 +232,7 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
|
|
|
232
232
|
- ver 3.0.5-alpha.2 优化:移除多余依赖
|
|
233
233
|
- ver 3.1.0-alpha.0 修复:新插件在第一次订阅时提示 `订阅失败,错误信息:该分组已经存在`; 移除:消息重发功能; 重构:将消息发送模式改为 `broadcast`
|
|
234
234
|
- ver 3.1.0-alpha.1 修复:无法发送 `@全体成员` 消息,将消息发送模式改回
|
|
235
|
+
- ver 3.1.0 修复:订阅某位UP主直播和动态后,某些群聊只开启推送直播也会推送动态
|
|
235
236
|
|
|
236
237
|
## 交流群
|
|
237
238
|
|