koishi-plugin-bilibili-notify 3.1.2-alpha.0 → 3.1.3-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 +3 -7
- package/lib/comRegister.js +90 -123
- package/lib/generateImg.d.ts +1 -0
- package/lib/generateImg.js +7 -1
- package/lib/index.js +1 -0
- package/lib/type/index.d.ts +5 -0
- 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, PushType, type SubItem, type SubManager, type Target } from "./type";
|
|
4
|
+
import { LiveType, type MasterInfo, PushType, type Result, type SubItem, type SubManager, type Target } from "./type";
|
|
5
5
|
declare class ComRegister {
|
|
6
6
|
static inject: string[];
|
|
7
7
|
qqRelatedBotList: Array<string>;
|
|
@@ -19,7 +19,6 @@ declare class ComRegister {
|
|
|
19
19
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
20
20
|
init(config: ComRegister.Config): Promise<void>;
|
|
21
21
|
getBot(pf: string): Bot<Context, any>;
|
|
22
|
-
test_wordCloud(): Promise<void>;
|
|
23
22
|
sendPrivateMsg(content: string): Promise<void>;
|
|
24
23
|
sendPrivateMsgAndRebootService(): Promise<void>;
|
|
25
24
|
sendPrivateMsgAndStopService(): Promise<void>;
|
|
@@ -34,11 +33,8 @@ declare class ComRegister {
|
|
|
34
33
|
subShow(): string;
|
|
35
34
|
updateSubNotifier(): void;
|
|
36
35
|
checkIfLoginInfoIsLoaded(): Promise<unknown>;
|
|
37
|
-
subUserInBili(mid: string): Promise<
|
|
38
|
-
|
|
39
|
-
msg: string;
|
|
40
|
-
}>;
|
|
41
|
-
loadSubFromConfig(subs: ComRegister.Config["sub"]): Promise<void>;
|
|
36
|
+
subUserInBili(mid: string): Promise<Result>;
|
|
37
|
+
loadSubFromConfig(subs: ComRegister.Config["sub"]): Promise<Result>;
|
|
42
38
|
checkIfDynamicDetectIsNeeded(): void;
|
|
43
39
|
enableDynamicDetect(): void;
|
|
44
40
|
checkIfIsLogin(): Promise<boolean>;
|
package/lib/comRegister.js
CHANGED
|
@@ -176,7 +176,10 @@ class ComRegister {
|
|
|
176
176
|
// 销毁定时器
|
|
177
177
|
this.loginTimer();
|
|
178
178
|
// 订阅手动订阅中的订阅
|
|
179
|
-
await this.loadSubFromConfig(config.sub);
|
|
179
|
+
const { code, msg } = await this.loadSubFromConfig(config.sub);
|
|
180
|
+
// 判断是否加载成功
|
|
181
|
+
if (code !== 0)
|
|
182
|
+
this.logger.error(msg);
|
|
180
183
|
// 清除控制台通知
|
|
181
184
|
ctx.ba.disposeNotifier();
|
|
182
185
|
// 发送成功登录推送
|
|
@@ -295,7 +298,17 @@ class ComRegister {
|
|
|
295
298
|
return;
|
|
296
299
|
}
|
|
297
300
|
// 从配置获取订阅
|
|
298
|
-
|
|
301
|
+
if (config.sub) {
|
|
302
|
+
const { code, msg } = await this.loadSubFromConfig(config.sub);
|
|
303
|
+
// 判断是否加载成功
|
|
304
|
+
if (code !== 0) {
|
|
305
|
+
this.logger.error(msg);
|
|
306
|
+
this.logger.error("订阅对象加载失败,插件初始化失败!");
|
|
307
|
+
// 发送私聊消息
|
|
308
|
+
await this.sendPrivateMsg("订阅对象加载失败,插件初始化失败!");
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
299
312
|
// 检查是否需要动态监测
|
|
300
313
|
this.checkIfDynamicDetectIsNeeded();
|
|
301
314
|
// 在控制台中显示订阅对象
|
|
@@ -316,42 +329,6 @@ class ComRegister {
|
|
|
316
329
|
getBot(pf) {
|
|
317
330
|
return this.ctx.bots.find((bot) => bot.platform === pf);
|
|
318
331
|
}
|
|
319
|
-
// TODO:WordCloud
|
|
320
|
-
async test_wordCloud() {
|
|
321
|
-
/* const currentLiveDanmakuArr = []
|
|
322
|
-
// 定义获取弹幕权重Record函数
|
|
323
|
-
const getDanmakuWeightRecord = (): Record<string, number> => {
|
|
324
|
-
// 创建segmentit
|
|
325
|
-
const segmentit = useDefault(new Segment());
|
|
326
|
-
// 创建Record
|
|
327
|
-
const danmakuWeightRecord: Record<string, number> = {};
|
|
328
|
-
// 循环遍历currentLiveDanmakuArr
|
|
329
|
-
for (const danmaku of currentLiveDanmakuArr) {
|
|
330
|
-
// 遍历结果
|
|
331
|
-
segmentit.doSegment(danmaku).map((word: { w: string; p: number }) => {
|
|
332
|
-
// 定义权重
|
|
333
|
-
danmakuWeightRecord[word.w] = (danmakuWeightRecord[word.w] || 0) + 1;
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
// 返回Record
|
|
337
|
-
return danmakuWeightRecord;
|
|
338
|
-
}; */
|
|
339
|
-
// Test
|
|
340
|
-
const testTarget = [
|
|
341
|
-
{
|
|
342
|
-
channelArr: [
|
|
343
|
-
{
|
|
344
|
-
channelId: "635762054",
|
|
345
|
-
dynamic: true,
|
|
346
|
-
live: false,
|
|
347
|
-
liveGuardBuy: false,
|
|
348
|
-
atAll: false,
|
|
349
|
-
},
|
|
350
|
-
],
|
|
351
|
-
platform: "qqguild",
|
|
352
|
-
},
|
|
353
|
-
];
|
|
354
|
-
}
|
|
355
332
|
async sendPrivateMsg(content) {
|
|
356
333
|
if (this.config.master.enable) {
|
|
357
334
|
if (this.config.master.masterAccountGuildId) {
|
|
@@ -648,6 +625,12 @@ class ComRegister {
|
|
|
648
625
|
}
|
|
649
626
|
return;
|
|
650
627
|
}
|
|
628
|
+
if (e.message === "已屏蔽专栏动态") {
|
|
629
|
+
if (this.config.filter.notify) {
|
|
630
|
+
await this.broadcastToTargets(sub.target, `${upName}投稿了一条专栏,已屏蔽`, type_1.PushType.Dynamic);
|
|
631
|
+
}
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
651
634
|
// 未知错误
|
|
652
635
|
this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
|
|
653
636
|
// 发送私聊消息并重启服务
|
|
@@ -851,10 +834,14 @@ class ComRegister {
|
|
|
851
834
|
const upName = item.modules.module_author.name;
|
|
852
835
|
// logger
|
|
853
836
|
this.logger.info(`当前动态UP主UID:${upUID},UP主名称:${upName}`);
|
|
837
|
+
// 定义是否是订阅的UP主flag
|
|
838
|
+
let isSubscribed = false;
|
|
854
839
|
// 寻找关注的UP主的动态
|
|
855
840
|
for (const sub of this.subManager) {
|
|
856
841
|
// 判断是否是订阅的UP主
|
|
857
842
|
if (sub.dynamic && sub.uid === upUID) {
|
|
843
|
+
// 将flag设置为true
|
|
844
|
+
isSubscribed = true;
|
|
858
845
|
// logger:订阅该UP主,推送该动态
|
|
859
846
|
this.logger.info("订阅该UP主,开始推送该动态...");
|
|
860
847
|
// logger
|
|
@@ -923,6 +910,8 @@ class ComRegister {
|
|
|
923
910
|
// logger
|
|
924
911
|
this.logger.info("动态推送完毕!");
|
|
925
912
|
}
|
|
913
|
+
}
|
|
914
|
+
if (!isSubscribed) {
|
|
926
915
|
// logger
|
|
927
916
|
this.logger.info("不是关注的UP主,跳过该动态");
|
|
928
917
|
}
|
|
@@ -1316,10 +1305,8 @@ class ComRegister {
|
|
|
1316
1305
|
// 判断分组是否准备好
|
|
1317
1306
|
const resp = await checkGroupIsReady();
|
|
1318
1307
|
// 判断是否创建成功
|
|
1319
|
-
if (resp.code !== 0)
|
|
1320
|
-
// 创建分组失败
|
|
1308
|
+
if (resp.code !== 0)
|
|
1321
1309
|
return resp;
|
|
1322
|
-
}
|
|
1323
1310
|
// 获取分组详情
|
|
1324
1311
|
const getGroupDetailData = async () => {
|
|
1325
1312
|
// 获取分组明细
|
|
@@ -1332,10 +1319,8 @@ class ComRegister {
|
|
|
1332
1319
|
// 分组不存在
|
|
1333
1320
|
const resp = await checkGroupIsReady();
|
|
1334
1321
|
// 判断是否创建成功
|
|
1335
|
-
if (resp.code !== 0)
|
|
1336
|
-
|
|
1337
|
-
return { ...resp, data: undefined };
|
|
1338
|
-
}
|
|
1322
|
+
if (resp.code !== 0)
|
|
1323
|
+
return resp;
|
|
1339
1324
|
// 再次获取分组明细
|
|
1340
1325
|
return getGroupDetailData();
|
|
1341
1326
|
}
|
|
@@ -1448,85 +1433,67 @@ class ComRegister {
|
|
|
1448
1433
|
return await func();
|
|
1449
1434
|
}
|
|
1450
1435
|
async loadSubFromConfig(subs) {
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
// 终止
|
|
1467
|
-
controller.abort(`加载订阅UID:${sub.uid}超时`);
|
|
1468
|
-
}, this.config.subLoadTimeout * 1000);
|
|
1436
|
+
for (const sub of subs) {
|
|
1437
|
+
// logger
|
|
1438
|
+
this.logger.info(`加载订阅UID:${sub.uid}中...`);
|
|
1439
|
+
// 定义Data
|
|
1440
|
+
const { code: userInfoCode, msg: userInfoMsg, data: userInfoData, } = await (0, utils_1.withRetry)(async () => {
|
|
1441
|
+
// 获取用户信息
|
|
1442
|
+
const data = await this.ctx.ba.getUserInfo(sub.uid);
|
|
1443
|
+
// 返回用户信息
|
|
1444
|
+
return { code: 0, data };
|
|
1445
|
+
})
|
|
1446
|
+
.then((content) => content.data)
|
|
1447
|
+
.catch((e) => {
|
|
1448
|
+
this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
|
|
1449
|
+
// 返回失败
|
|
1450
|
+
return { code: -1, message: `加载订阅UID:${sub.uid}失败!` };
|
|
1469
1451
|
});
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
uid: sub.uid,
|
|
1516
|
-
uname: data.name,
|
|
1517
|
-
roomId: sub.live ? data.live_room.roomid : "",
|
|
1518
|
-
target: sub.target,
|
|
1519
|
-
platform: "",
|
|
1520
|
-
live: sub.live,
|
|
1521
|
-
dynamic: sub.dynamic,
|
|
1522
|
-
card: sub.card,
|
|
1523
|
-
});
|
|
1524
|
-
// logger
|
|
1525
|
-
this.logger.info(`UID:${sub.uid}订阅加载完毕!`);
|
|
1526
|
-
})(),
|
|
1527
|
-
timeoutPromise,
|
|
1528
|
-
]);
|
|
1529
|
-
}));
|
|
1452
|
+
// 判断是否获取成功
|
|
1453
|
+
if (userInfoCode !== 0)
|
|
1454
|
+
return { code: userInfoCode, msg: userInfoMsg };
|
|
1455
|
+
// 判断是否需要订阅直播
|
|
1456
|
+
if (sub.live) {
|
|
1457
|
+
// 检查roomid是否存在
|
|
1458
|
+
if (!userInfoData.live_room) {
|
|
1459
|
+
// 用户没有开通直播间,无法订阅直播
|
|
1460
|
+
sub.live = false;
|
|
1461
|
+
// 发送提示
|
|
1462
|
+
this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
|
|
1463
|
+
}
|
|
1464
|
+
// 判断是否订阅直播
|
|
1465
|
+
if (sub.live) {
|
|
1466
|
+
// 启动直播监测
|
|
1467
|
+
await this.liveDetectWithListener(userInfoData.live_room.roomid, sub.target, sub.card);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
// 在B站中订阅该对象
|
|
1471
|
+
const subInfo = await this.subUserInBili(sub.uid);
|
|
1472
|
+
// 判断订阅是否成功
|
|
1473
|
+
if (subInfo.code !== 0)
|
|
1474
|
+
return subInfo;
|
|
1475
|
+
// 将该订阅添加到sm中
|
|
1476
|
+
this.subManager.push({
|
|
1477
|
+
id: +sub.uid,
|
|
1478
|
+
uid: sub.uid,
|
|
1479
|
+
uname: userInfoData.name,
|
|
1480
|
+
roomId: sub.live ? userInfoData.live_room.roomid : "",
|
|
1481
|
+
target: sub.target,
|
|
1482
|
+
platform: "",
|
|
1483
|
+
live: sub.live,
|
|
1484
|
+
dynamic: sub.dynamic,
|
|
1485
|
+
card: sub.card,
|
|
1486
|
+
});
|
|
1487
|
+
// logger
|
|
1488
|
+
this.logger.info(`UID:${sub.uid}订阅加载完毕!`);
|
|
1489
|
+
// 1-3秒随机延迟
|
|
1490
|
+
const randomDelay = Math.floor(Math.random() * 3) + 1;
|
|
1491
|
+
// logger
|
|
1492
|
+
this.logger.info(`随机延迟:${randomDelay}秒`);
|
|
1493
|
+
// delay
|
|
1494
|
+
await this.ctx.sleep(randomDelay * 1000);
|
|
1495
|
+
}
|
|
1496
|
+
return { code: 0, msg: "订阅加载完毕!" };
|
|
1530
1497
|
}
|
|
1531
1498
|
checkIfDynamicDetectIsNeeded() {
|
|
1532
1499
|
// 检查是否有订阅对象需要动态监测
|
package/lib/generateImg.d.ts
CHANGED
package/lib/generateImg.js
CHANGED
|
@@ -534,8 +534,13 @@ class GenerateImg extends koishi_1.Service {
|
|
|
534
534
|
`${upName}发布了剧集(番剧、电影、纪录片),我暂时无法渲染,请自行查看`,
|
|
535
535
|
link,
|
|
536
536
|
];
|
|
537
|
-
case DYNAMIC_TYPE_ARTICLE:
|
|
537
|
+
case DYNAMIC_TYPE_ARTICLE: {
|
|
538
|
+
//转发动态屏蔽
|
|
539
|
+
if (this.giConfig.filter.enable && this.giConfig.filter.article) {
|
|
540
|
+
throw new Error("已屏蔽专栏动态");
|
|
541
|
+
}
|
|
538
542
|
return [`${upName}投稿了新专栏,我暂时无法渲染,请自行查看`, link];
|
|
543
|
+
}
|
|
539
544
|
case DYNAMIC_TYPE_MUSIC:
|
|
540
545
|
return [`${upName}发行了新歌,我暂时无法渲染,请自行查看`, link];
|
|
541
546
|
case DYNAMIC_TYPE_COMMON_SQUARE:
|
|
@@ -1473,6 +1478,7 @@ class GenerateImg extends koishi_1.Service {
|
|
|
1473
1478
|
regex: koishi_1.Schema.string(),
|
|
1474
1479
|
keywords: koishi_1.Schema.array(String),
|
|
1475
1480
|
forward: koishi_1.Schema.boolean(),
|
|
1481
|
+
article: koishi_1.Schema.boolean(),
|
|
1476
1482
|
}),
|
|
1477
1483
|
removeBorder: koishi_1.Schema.boolean(),
|
|
1478
1484
|
cardColorStart: koishi_1.Schema.string(),
|
package/lib/index.js
CHANGED
|
@@ -387,6 +387,7 @@ exports.Config = koishi_1.Schema.object({
|
|
|
387
387
|
forward: koishi_1.Schema.boolean()
|
|
388
388
|
.default(false)
|
|
389
389
|
.description("是否屏蔽转发动态"),
|
|
390
|
+
article: koishi_1.Schema.boolean().default(false).description("是否屏蔽专栏"),
|
|
390
391
|
}),
|
|
391
392
|
koishi_1.Schema.object({}),
|
|
392
393
|
]),
|
package/lib/type/index.d.ts
CHANGED
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -235,6 +235,7 @@ uid为必填参数,为要推送的UP主的UID,index为可选参数,为要
|
|
|
235
235
|
- ver 3.1.0 修复:订阅某位UP主直播和动态后,某些群聊只开启推送直播也会推送动态
|
|
236
236
|
- ver 3.1.1-alpha.0 修复:稿件重投后,会将之前日期的动态一起推送; 优化:加强动态debug输出; 移除:不必要选项 `live.liveDetectMode`
|
|
237
237
|
- ver 3.1.2-alpha.0 重构:对消息发送模块进行小型重构,多群多平台推送将不再支持艾特全体成员,仅单平台单群聊支持; 移除:群聊 `all` 选项
|
|
238
|
+
- ver 3.1.3-alpha.0 移除:订阅超时; 新增:屏蔽专栏动态功能; 优化:改进了加载插件的错误提示;
|
|
238
239
|
|
|
239
240
|
## 交流群
|
|
240
241
|
|