koishi-plugin-bilibili-notify 3.0.0-alpha.11 → 3.0.0-alpha.13
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.d.ts +5 -5
- package/lib/biliAPI.js +151 -128
- package/lib/comRegister.d.ts +7 -7
- package/lib/comRegister.js +619 -448
- package/lib/generateImg.d.ts +3 -2
- package/lib/generateImg.js +178 -133
- package/lib/index.d.ts +5 -5
- package/lib/index.js +146 -133
- package/package.json +3 -8
- package/readme.md +2 -0
package/lib/comRegister.js
CHANGED
|
@@ -4,16 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const jsx_runtime_1 = require("@satorijs/element/jsx-runtime");
|
|
7
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
8
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
|
9
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
10
7
|
const koishi_1 = require("koishi");
|
|
11
8
|
// 导入qrcode
|
|
12
9
|
const qrcode_1 = __importDefault(require("qrcode"));
|
|
13
|
-
// 弹幕词云
|
|
14
|
-
const segmentit_1 = require("segmentit");
|
|
15
|
-
const canvas_1 = require("canvas");
|
|
16
|
-
const d3_cloud_1 = __importDefault(require("d3-cloud"));
|
|
17
10
|
var LiveType;
|
|
18
11
|
(function (LiveType) {
|
|
19
12
|
LiveType[LiveType["NotLiveBroadcast"] = 0] = "NotLiveBroadcast";
|
|
@@ -23,9 +16,15 @@ var LiveType;
|
|
|
23
16
|
})(LiveType || (LiveType = {}));
|
|
24
17
|
class ComRegister {
|
|
25
18
|
// 必须服务
|
|
26
|
-
static inject = [
|
|
19
|
+
static inject = ["ba", "gi", "database", "canvas", "bl", "sm"];
|
|
27
20
|
// 定义数组:QQ相关bot
|
|
28
|
-
qqRelatedBotList = [
|
|
21
|
+
qqRelatedBotList = [
|
|
22
|
+
"qq",
|
|
23
|
+
"onebot",
|
|
24
|
+
"red",
|
|
25
|
+
"satori",
|
|
26
|
+
"chronocat",
|
|
27
|
+
];
|
|
29
28
|
// logger
|
|
30
29
|
logger;
|
|
31
30
|
// config
|
|
@@ -59,76 +58,82 @@ class ComRegister {
|
|
|
59
58
|
// 初始化
|
|
60
59
|
this.init(config);
|
|
61
60
|
// 注册指令
|
|
62
|
-
const statusCom = ctx.command(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
const statusCom = ctx.command("status", "插件状态相关指令", {
|
|
62
|
+
permissions: ["authority:5"],
|
|
63
|
+
});
|
|
64
|
+
statusCom
|
|
65
|
+
.subcommand(".dyn", "查看动态监测运行状态")
|
|
66
|
+
.usage("查看动态监测运行状态")
|
|
67
|
+
.example("status dyn")
|
|
66
68
|
.action(() => {
|
|
67
69
|
if (this.dynamicDispose) {
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
return '动态监测未运行';
|
|
70
|
+
return "动态监测正在运行";
|
|
72
71
|
}
|
|
72
|
+
return "动态监测未运行";
|
|
73
73
|
});
|
|
74
|
-
statusCom
|
|
75
|
-
.
|
|
76
|
-
.
|
|
74
|
+
statusCom
|
|
75
|
+
.subcommand(".sm", "查看订阅管理对象")
|
|
76
|
+
.usage("查看订阅管理对象")
|
|
77
|
+
.example("status sm")
|
|
77
78
|
.action(async () => {
|
|
78
79
|
this.logger.info(this.subManager);
|
|
79
|
-
return
|
|
80
|
+
return "查看控制台";
|
|
80
81
|
});
|
|
81
82
|
statusCom
|
|
82
|
-
.subcommand(
|
|
83
|
-
.usage(
|
|
84
|
-
.example(
|
|
83
|
+
.subcommand(".bot", "查询当前拥有的机器人信息", { hidden: true })
|
|
84
|
+
.usage("查询当前拥有的机器人信息")
|
|
85
|
+
.example("status bot 查询当前拥有的机器人信息")
|
|
85
86
|
.action(() => {
|
|
86
|
-
this.logger.info(
|
|
87
|
-
ctx.bots
|
|
88
|
-
this.logger.info(
|
|
89
|
-
this.logger.info(
|
|
90
|
-
this.logger.info(
|
|
91
|
-
this.logger.info(
|
|
92
|
-
}
|
|
87
|
+
this.logger.info("开始输出BOT信息");
|
|
88
|
+
for (const bot of ctx.bots) {
|
|
89
|
+
this.logger.info("--------------------------------");
|
|
90
|
+
this.logger.info(`平台:${bot.platform}`);
|
|
91
|
+
this.logger.info(`名称:${bot.user.name}`);
|
|
92
|
+
this.logger.info("--------------------------------");
|
|
93
|
+
}
|
|
93
94
|
});
|
|
94
95
|
statusCom
|
|
95
|
-
.subcommand(
|
|
96
|
-
.usage(
|
|
97
|
-
.example(
|
|
96
|
+
.subcommand(".env", "查询当前环境的信息", { hidden: true })
|
|
97
|
+
.usage("查询当前环境的信息")
|
|
98
|
+
.example("status env 查询当前环境的信息")
|
|
98
99
|
.action(async ({ session }) => {
|
|
99
100
|
await session.send(`Guild ID:${session.event.guild.id}`);
|
|
100
101
|
await session.send(`Channel ID: ${session.event.channel.id}`);
|
|
101
102
|
});
|
|
102
|
-
const biliCom = ctx.command(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
const biliCom = ctx.command("bili", "bili-notify插件相关指令", {
|
|
104
|
+
permissions: ["authority:3"],
|
|
105
|
+
});
|
|
106
|
+
biliCom
|
|
107
|
+
.subcommand(".login", "登录B站之后才可以进行之后的操作")
|
|
108
|
+
.usage("使用二维码登录,登录B站之后才可以进行之后的操作")
|
|
109
|
+
.example("bili login")
|
|
106
110
|
.action(async ({ session }) => {
|
|
107
|
-
this.logger.info(
|
|
111
|
+
this.logger.info("调用bili login指令");
|
|
108
112
|
// 获取二维码
|
|
113
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
109
114
|
let content;
|
|
110
115
|
try {
|
|
111
116
|
content = await ctx.ba.getLoginQRCode();
|
|
112
117
|
}
|
|
113
118
|
catch (e) {
|
|
114
|
-
return
|
|
119
|
+
return "bili login getLoginQRCode() 本次网络请求失败";
|
|
115
120
|
}
|
|
116
121
|
// 判断是否出问题
|
|
117
122
|
if (content.code !== 0)
|
|
118
|
-
return await session.send(
|
|
123
|
+
return await session.send("出问题咯,请联系管理员解决");
|
|
119
124
|
// 生成二维码
|
|
120
125
|
qrcode_1.default.toBuffer(content.data.url, {
|
|
121
|
-
errorCorrectionLevel:
|
|
122
|
-
type:
|
|
126
|
+
errorCorrectionLevel: "H", // 错误更正水平
|
|
127
|
+
type: "png", // 输出类型
|
|
123
128
|
margin: 1, // 边距大小
|
|
124
129
|
color: {
|
|
125
|
-
dark:
|
|
126
|
-
light:
|
|
127
|
-
}
|
|
130
|
+
dark: "#000000", // 二维码颜色
|
|
131
|
+
light: "#FFFFFF", // 背景颜色
|
|
132
|
+
},
|
|
128
133
|
}, async (err, buffer) => {
|
|
129
134
|
if (err)
|
|
130
|
-
return await session.send(
|
|
131
|
-
await session.send(koishi_1.h.image(buffer,
|
|
135
|
+
return await session.send("二维码生成出错,请重新尝试");
|
|
136
|
+
await session.send(koishi_1.h.image(buffer, "image/png"));
|
|
132
137
|
});
|
|
133
138
|
// 检查之前是否存在登录定时器
|
|
134
139
|
if (this.loginTimer)
|
|
@@ -143,6 +148,7 @@ class ComRegister {
|
|
|
143
148
|
return;
|
|
144
149
|
flag = false;
|
|
145
150
|
// 获取登录信息
|
|
151
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
146
152
|
let loginContent;
|
|
147
153
|
try {
|
|
148
154
|
loginContent = await ctx.ba.getLoginStatus(content.data.qrcode_key);
|
|
@@ -153,20 +159,23 @@ class ComRegister {
|
|
|
153
159
|
}
|
|
154
160
|
if (loginContent.code !== 0) {
|
|
155
161
|
this.loginTimer();
|
|
156
|
-
return await session.send(
|
|
162
|
+
return await session.send("登录失败请重试");
|
|
157
163
|
}
|
|
158
164
|
if (loginContent.data.code === 86038) {
|
|
159
165
|
this.loginTimer();
|
|
160
|
-
return await session.send(
|
|
166
|
+
return await session.send("二维码已失效,请重新登录");
|
|
161
167
|
}
|
|
162
|
-
if (loginContent.data.code === 0) {
|
|
168
|
+
if (loginContent.data.code === 0) {
|
|
169
|
+
// 登录成功
|
|
163
170
|
const encryptedCookies = ctx.ba.encrypt(ctx.ba.getCookies());
|
|
164
171
|
const encryptedRefreshToken = ctx.ba.encrypt(loginContent.data.refresh_token);
|
|
165
|
-
await ctx.database.upsert(
|
|
172
|
+
await ctx.database.upsert("loginBili", [
|
|
173
|
+
{
|
|
166
174
|
id: 1,
|
|
167
175
|
bili_cookies: encryptedCookies,
|
|
168
|
-
bili_refresh_token: encryptedRefreshToken
|
|
169
|
-
}
|
|
176
|
+
bili_refresh_token: encryptedRefreshToken,
|
|
177
|
+
},
|
|
178
|
+
]);
|
|
170
179
|
// 销毁定时器
|
|
171
180
|
this.loginTimer();
|
|
172
181
|
// 订阅手动订阅中的订阅
|
|
@@ -176,9 +185,9 @@ class ComRegister {
|
|
|
176
185
|
// 清除控制台通知
|
|
177
186
|
ctx.ba.disposeNotifier();
|
|
178
187
|
// 发送成功登录推送
|
|
179
|
-
await session.send(
|
|
188
|
+
await session.send("登录成功");
|
|
180
189
|
// bili show
|
|
181
|
-
await session.execute(
|
|
190
|
+
await session.execute("bili show");
|
|
182
191
|
// 开启cookies刷新检测
|
|
183
192
|
ctx.ba.enableRefreshCookiesDetect();
|
|
184
193
|
}
|
|
@@ -189,19 +198,19 @@ class ComRegister {
|
|
|
189
198
|
}, 1000);
|
|
190
199
|
});
|
|
191
200
|
biliCom
|
|
192
|
-
.subcommand(
|
|
193
|
-
.usage(
|
|
194
|
-
.option(
|
|
195
|
-
.option(
|
|
196
|
-
.example(
|
|
201
|
+
.subcommand(".unsub <uid:string>", "取消订阅UP主动态、直播或全部")
|
|
202
|
+
.usage("取消订阅,加-l为取消直播订阅,加-d为取消动态订阅,什么都不加则为全部取消")
|
|
203
|
+
.option("live", "-l")
|
|
204
|
+
.option("dynamic", "-d")
|
|
205
|
+
.example("bili unsub 用户UID -ld")
|
|
197
206
|
.action(async ({ session, options }, uid) => {
|
|
198
|
-
this.logger.info(
|
|
207
|
+
this.logger.info("调用bili.unsub指令");
|
|
199
208
|
// 若用户UID为空则直接返回
|
|
200
209
|
if (!uid)
|
|
201
|
-
return
|
|
210
|
+
return "用户UID不能为空";
|
|
202
211
|
// -d -l两个选项不能同时存在
|
|
203
212
|
if (options.dynamic && options.live)
|
|
204
|
-
return
|
|
213
|
+
return "需要取消订阅该UP主请直接使用指令bili unsub 用户UID";
|
|
205
214
|
// 定义是否存在
|
|
206
215
|
let exist;
|
|
207
216
|
await Promise.all(this.subManager.map(async (sub, i) => {
|
|
@@ -218,15 +227,18 @@ class ComRegister {
|
|
|
218
227
|
return;
|
|
219
228
|
}
|
|
220
229
|
// 从数据库中删除订阅
|
|
221
|
-
await ctx.database.remove(
|
|
230
|
+
await ctx.database.remove("bilibili", {
|
|
231
|
+
uid: this.subManager[i].uid,
|
|
232
|
+
});
|
|
222
233
|
// 将该订阅对象从订阅管理对象中移除
|
|
223
234
|
this.subManager.splice(i, 1);
|
|
224
235
|
// 将订阅对象移出订阅关注组
|
|
225
236
|
const removeUserFromGroupData = await ctx.ba.removeUserFromGroup(sub.uid);
|
|
226
237
|
// 判断是否移出成功 22105关注对象为自己
|
|
227
|
-
if (removeUserFromGroupData.code !== 0 &&
|
|
238
|
+
if (removeUserFromGroupData.code !== 0 &&
|
|
239
|
+
removeUserFromGroupData.code !== 22105) {
|
|
228
240
|
// 移出失败
|
|
229
|
-
await session.send(
|
|
241
|
+
await session.send("取消订阅对象失败,请稍后重试");
|
|
230
242
|
// 将存在flag设置为true
|
|
231
243
|
exist = true;
|
|
232
244
|
// 结束循环
|
|
@@ -237,7 +249,7 @@ class ComRegister {
|
|
|
237
249
|
// 判断是否还有动态订阅
|
|
238
250
|
this.checkIfUserIsTheLastOneWhoSubDyn();
|
|
239
251
|
// 发送成功通知
|
|
240
|
-
await session.send(
|
|
252
|
+
await session.send("已取消订阅该用户");
|
|
241
253
|
// 更新控制台提示
|
|
242
254
|
this.updateSubNotifier();
|
|
243
255
|
// 将存在flag设置为true
|
|
@@ -246,43 +258,47 @@ class ComRegister {
|
|
|
246
258
|
}));
|
|
247
259
|
// 未订阅该用户,无需取消订阅
|
|
248
260
|
if (!exist)
|
|
249
|
-
await session.send(
|
|
261
|
+
await session.send("未订阅该用户,无需取消订阅");
|
|
250
262
|
});
|
|
251
263
|
biliCom
|
|
252
|
-
.subcommand(
|
|
253
|
-
.usage(
|
|
254
|
-
.example(
|
|
264
|
+
.subcommand(".show", "展示订阅对象")
|
|
265
|
+
.usage("展示订阅对象")
|
|
266
|
+
.example("bili show")
|
|
255
267
|
.action(() => {
|
|
256
268
|
const subTable = this.subShow();
|
|
257
269
|
return subTable;
|
|
258
270
|
});
|
|
259
271
|
biliCom
|
|
260
|
-
.subcommand(
|
|
261
|
-
.option(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
.option(
|
|
265
|
-
.
|
|
266
|
-
.
|
|
272
|
+
.subcommand(".sub <mid:string> [...groupId:string]", "订阅用户动态和直播通知")
|
|
273
|
+
.option("multiplatform", "-m <value:string>", {
|
|
274
|
+
type: /^(?:-?[A-Za-z0-9]+@?(?:,-?[A-Za-z0-9]+@?)*\.[A-Za-z0-9]+)(?:;(?:-?[A-Za-z0-9]+@?(?:,-?[A-Za-z0-9]+@?)*\.[A-Za-z0-9]+))*$/,
|
|
275
|
+
})
|
|
276
|
+
.option("live", "-l")
|
|
277
|
+
.option("dynamic", "-d")
|
|
278
|
+
.option("atAll", "-a")
|
|
279
|
+
.usage("订阅用户动态和直播通知,若需要订阅直播请加上-l,需要订阅动态则加上-d")
|
|
280
|
+
.example("bili sub 1194210119 目标群号或频道号 -l -d 订阅UID为1194210119的UP主的动态和直播")
|
|
267
281
|
.action(async ({ session, options }, mid, ...groupId) => {
|
|
268
|
-
this.logger.info(
|
|
282
|
+
this.logger.info("调用bili.sub指令");
|
|
269
283
|
// 先判断是否订阅直播,再判断是否解锁订阅限制,最后判断直播订阅是否已超三个
|
|
270
|
-
if (options.live &&
|
|
271
|
-
|
|
284
|
+
if (options.live &&
|
|
285
|
+
!this.config.unlockSubLimits &&
|
|
286
|
+
this.subManager.reduce((acc, cur) => acc + (cur.live ? 1 : 0), 0) >= 3) {
|
|
287
|
+
return "直播订阅已达上限,请取消部分直播订阅后再进行订阅";
|
|
272
288
|
}
|
|
273
289
|
// 检查是否登录
|
|
274
290
|
if (!(await this.checkIfIsLogin())) {
|
|
275
291
|
// 未登录直接返回
|
|
276
|
-
return
|
|
292
|
+
return "请使用指令bili login登录后再进行订阅操作";
|
|
277
293
|
}
|
|
278
294
|
// 检查必选参数是否已填
|
|
279
295
|
if (!mid)
|
|
280
|
-
return
|
|
296
|
+
return "请输入用户uid";
|
|
281
297
|
// 订阅对象
|
|
282
298
|
const subUserData = await this.subUserInBili(mid);
|
|
283
299
|
// 判断是否订阅对象存在
|
|
284
300
|
if (!subUserData.flag)
|
|
285
|
-
return
|
|
301
|
+
return "订阅对象失败,请稍后重试!";
|
|
286
302
|
// 定义目标变量
|
|
287
303
|
let target = [];
|
|
288
304
|
// 判断是否使用了多群组推送
|
|
@@ -290,18 +306,18 @@ class ComRegister {
|
|
|
290
306
|
// 定义channelIdArr
|
|
291
307
|
const channelIdArr = [];
|
|
292
308
|
// 遍历输入的群组
|
|
293
|
-
|
|
309
|
+
for (const group of groupId) {
|
|
294
310
|
channelIdArr.push({
|
|
295
311
|
channelId: group,
|
|
296
312
|
dynamic: true,
|
|
297
313
|
live: true,
|
|
298
314
|
liveGuardBuy: false,
|
|
299
|
-
atAll: options.atAll
|
|
315
|
+
atAll: options.atAll,
|
|
300
316
|
});
|
|
301
|
-
}
|
|
317
|
+
}
|
|
302
318
|
target.push({
|
|
303
319
|
channelIdArr,
|
|
304
|
-
platform: session.event.platform
|
|
320
|
+
platform: session.event.platform,
|
|
305
321
|
});
|
|
306
322
|
}
|
|
307
323
|
else {
|
|
@@ -312,19 +328,20 @@ class ComRegister {
|
|
|
312
328
|
}
|
|
313
329
|
// 判断是否使用了多平台
|
|
314
330
|
if (target.length > 0) {
|
|
315
|
-
for (const [index, { channelIdArr, platform }] of target.entries()) {
|
|
316
|
-
if (channelIdArr.length > 0) {
|
|
331
|
+
for (const [index, { channelIdArr, platform },] of target.entries()) {
|
|
332
|
+
if (channelIdArr.length > 0) {
|
|
333
|
+
// 输入了推送群号或频道号
|
|
317
334
|
// 拿到对应的bot
|
|
318
335
|
const bot = this.getBot(platform);
|
|
319
336
|
// 判断是否配置了对应平台的机器人
|
|
320
|
-
if (!ctx.bots.some(bot => bot.platform === platform)) {
|
|
337
|
+
if (!ctx.bots.some((bot) => bot.platform === platform)) {
|
|
321
338
|
// 发送提示消息
|
|
322
|
-
await session.send(
|
|
339
|
+
await session.send("您未配置对应平台的机器人,不能在该平台进行订阅操作");
|
|
323
340
|
// 直接返回
|
|
324
341
|
return;
|
|
325
342
|
}
|
|
326
343
|
// 判断是否需要加入的群全部推送
|
|
327
|
-
if (channelIdArr[0].channelId !==
|
|
344
|
+
if (channelIdArr[0].channelId !== "all") {
|
|
328
345
|
// 定义满足条件的群组数组
|
|
329
346
|
const targetArr = [];
|
|
330
347
|
// 获取机器人加入的群组
|
|
@@ -338,7 +355,7 @@ class ComRegister {
|
|
|
338
355
|
// 获取频道列表
|
|
339
356
|
const channelList = await bot.getChannelList(guild.id);
|
|
340
357
|
// 判断机器人是否加入群聊或频道
|
|
341
|
-
if (channelList.data.some(channel => channel.id === channelId.channelId)) {
|
|
358
|
+
if (channelList.data.some((channel) => channel.id === channelId.channelId)) {
|
|
342
359
|
// 加入群聊或频道
|
|
343
360
|
targetArr.push(channelId);
|
|
344
361
|
// 设置标志位为true
|
|
@@ -355,9 +372,22 @@ class ComRegister {
|
|
|
355
372
|
// 判断targetArr是否为空
|
|
356
373
|
if (target.length === 0) {
|
|
357
374
|
// 为空则默认为当前环境
|
|
358
|
-
target = [
|
|
375
|
+
target = [
|
|
376
|
+
{
|
|
377
|
+
channelIdArr: [
|
|
378
|
+
{
|
|
379
|
+
channelId: session.event.channel.id,
|
|
380
|
+
dynamic: true,
|
|
381
|
+
live: true,
|
|
382
|
+
liveGuardBuy: false,
|
|
383
|
+
atAll: options.atAll ? options.atAll : false,
|
|
384
|
+
},
|
|
385
|
+
],
|
|
386
|
+
platform: session.event.platform,
|
|
387
|
+
},
|
|
388
|
+
];
|
|
359
389
|
// 没有满足条件的群组或频道
|
|
360
|
-
await session.send(
|
|
390
|
+
await session.send("没有满足条件的群组或频道,默认订阅到当前聊天环境");
|
|
361
391
|
}
|
|
362
392
|
// 将符合条件的群组添加到target中
|
|
363
393
|
target[index].channelIdArr = targetArr;
|
|
@@ -366,18 +396,45 @@ class ComRegister {
|
|
|
366
396
|
}
|
|
367
397
|
else {
|
|
368
398
|
// 未填写群号或频道号,默认为当前环境
|
|
369
|
-
target = [
|
|
399
|
+
target = [
|
|
400
|
+
{
|
|
401
|
+
channelIdArr: [
|
|
402
|
+
{
|
|
403
|
+
channelId: session.event.channel.id,
|
|
404
|
+
dynamic: true,
|
|
405
|
+
live: true,
|
|
406
|
+
liveGuardBuy: false,
|
|
407
|
+
atAll: options.atAll ? options.atAll : false,
|
|
408
|
+
},
|
|
409
|
+
],
|
|
410
|
+
platform: session.event.platform,
|
|
411
|
+
},
|
|
412
|
+
];
|
|
370
413
|
// 发送提示消息
|
|
371
|
-
await session.send(
|
|
414
|
+
await session.send("没有填写群号或频道号,默认订阅到当前聊天环境");
|
|
372
415
|
}
|
|
373
416
|
}
|
|
374
417
|
}
|
|
375
418
|
else {
|
|
376
419
|
// 用户直接订阅,将当前环境赋值给target
|
|
377
|
-
target = [
|
|
420
|
+
target = [
|
|
421
|
+
{
|
|
422
|
+
channelIdArr: [
|
|
423
|
+
{
|
|
424
|
+
channelId: session.event.channel.id,
|
|
425
|
+
dynamic: true,
|
|
426
|
+
live: true,
|
|
427
|
+
liveGuardBuy: false,
|
|
428
|
+
atAll: options.atAll ? options.atAll : false,
|
|
429
|
+
},
|
|
430
|
+
],
|
|
431
|
+
platform: session.event.platform,
|
|
432
|
+
},
|
|
433
|
+
];
|
|
378
434
|
}
|
|
379
435
|
}
|
|
380
|
-
// 定义外围变量
|
|
436
|
+
// 定义外围变量
|
|
437
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
381
438
|
let content;
|
|
382
439
|
try {
|
|
383
440
|
// 获取用户信息
|
|
@@ -385,7 +442,7 @@ class ComRegister {
|
|
|
385
442
|
}
|
|
386
443
|
catch (e) {
|
|
387
444
|
// 返回错误信息
|
|
388
|
-
return
|
|
445
|
+
return `bili sub getUserInfo() 发生了错误,错误为:${e.message}`;
|
|
389
446
|
}
|
|
390
447
|
// 判断是否成功获取用户信息
|
|
391
448
|
if (content.code !== 0) {
|
|
@@ -394,19 +451,19 @@ class ComRegister {
|
|
|
394
451
|
// 判断错误代码
|
|
395
452
|
switch (content.code) {
|
|
396
453
|
case -400:
|
|
397
|
-
msg =
|
|
454
|
+
msg = "请求错误";
|
|
398
455
|
break;
|
|
399
456
|
case -403:
|
|
400
|
-
msg =
|
|
457
|
+
msg = "访问权限不足,请尝试重新登录";
|
|
401
458
|
break;
|
|
402
459
|
case -404:
|
|
403
|
-
msg =
|
|
460
|
+
msg = "用户不存在";
|
|
404
461
|
break;
|
|
405
462
|
case -352:
|
|
406
|
-
msg =
|
|
463
|
+
msg = "风控校验失败,请尝试更换UA";
|
|
407
464
|
break;
|
|
408
465
|
default:
|
|
409
|
-
msg =
|
|
466
|
+
msg = `未知错误,错误信息:${content.message}`;
|
|
410
467
|
break;
|
|
411
468
|
}
|
|
412
469
|
// 返回错误信息
|
|
@@ -418,36 +475,38 @@ class ComRegister {
|
|
|
418
475
|
const [liveMsg, dynamicMsg] = await this.checkIfNeedSub(options.live, options.dynamic, session, data.live_room);
|
|
419
476
|
// 判断是否未订阅任何消息
|
|
420
477
|
if (!liveMsg && !dynamicMsg)
|
|
421
|
-
return
|
|
478
|
+
return "您未订阅该UP的任何消息";
|
|
422
479
|
// 获取到对应的订阅对象
|
|
423
|
-
const subUser = this.subManager.find(sub => sub.uid === mid);
|
|
480
|
+
const subUser = this.subManager.find((sub) => sub.uid === mid);
|
|
424
481
|
// 判断要订阅的用户是否已经存在于订阅管理对象中
|
|
425
482
|
if (subUser) {
|
|
426
483
|
// 已存在,判断是否重复订阅直播通知
|
|
427
484
|
if (liveMsg && subUser.live) {
|
|
428
|
-
return
|
|
485
|
+
return "已订阅该用户直播通知,请勿重复订阅";
|
|
429
486
|
}
|
|
430
487
|
// 已存在,判断是否重复订阅动态通知
|
|
431
488
|
if (dynamicMsg && subUser.dynamic) {
|
|
432
|
-
return
|
|
489
|
+
return "已订阅该用户动态通知,请勿重复订阅";
|
|
433
490
|
}
|
|
434
491
|
}
|
|
435
492
|
// 获取直播房间号
|
|
436
493
|
const roomId = data.live_room?.roomid.toString();
|
|
437
494
|
// 获取用户信息
|
|
495
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
438
496
|
let userData;
|
|
439
497
|
try {
|
|
440
498
|
const { data } = await ctx.ba.getMasterInfo(mid);
|
|
441
499
|
userData = data;
|
|
442
500
|
}
|
|
443
501
|
catch (e) {
|
|
444
|
-
this.logger.error(
|
|
445
|
-
return
|
|
502
|
+
this.logger.error(`bili sub指令 getMasterInfo() 发生了错误,错误为:${e.message}`);
|
|
503
|
+
return "订阅出错啦,请重试";
|
|
446
504
|
}
|
|
447
505
|
const liveDetectModeSelector = {
|
|
448
506
|
API: async () => {
|
|
449
507
|
// 判断是否已开启直播检测
|
|
450
|
-
if (!this.liveDispose) {
|
|
508
|
+
if (!this.liveDispose) {
|
|
509
|
+
// 未开启直播检测
|
|
451
510
|
// 开启直播检测并保存销毁函数
|
|
452
511
|
this.liveDispose = await this.liveDetectWithAPI();
|
|
453
512
|
}
|
|
@@ -455,7 +514,7 @@ class ComRegister {
|
|
|
455
514
|
WS: async () => {
|
|
456
515
|
// 连接到服务器
|
|
457
516
|
await this.liveDetectWithListener(roomId, target);
|
|
458
|
-
}
|
|
517
|
+
},
|
|
459
518
|
};
|
|
460
519
|
// 订阅直播
|
|
461
520
|
if (liveMsg) {
|
|
@@ -475,14 +534,14 @@ class ComRegister {
|
|
|
475
534
|
await session.send(`订阅${userData.info.uname}动态通知`);
|
|
476
535
|
}
|
|
477
536
|
// 保存到数据库中
|
|
478
|
-
const sub = await ctx.database.create(
|
|
537
|
+
const sub = await ctx.database.create("bilibili", {
|
|
479
538
|
uid: mid,
|
|
480
539
|
room_id: roomId,
|
|
481
540
|
dynamic: dynamicMsg ? 1 : 0,
|
|
482
541
|
live: liveMsg ? 1 : 0,
|
|
483
542
|
target: JSON.stringify(target),
|
|
484
543
|
platform: session.event.platform,
|
|
485
|
-
time: new Date()
|
|
544
|
+
time: new Date(),
|
|
486
545
|
});
|
|
487
546
|
// 订阅数+1
|
|
488
547
|
this.num++;
|
|
@@ -500,75 +559,83 @@ class ComRegister {
|
|
|
500
559
|
this.updateSubNotifier();
|
|
501
560
|
});
|
|
502
561
|
biliCom
|
|
503
|
-
.subcommand(
|
|
504
|
-
|
|
505
|
-
|
|
562
|
+
.subcommand(".status <roomId:string>", "查询主播当前直播状态", {
|
|
563
|
+
hidden: true,
|
|
564
|
+
})
|
|
565
|
+
.usage("查询主播当前直播状态")
|
|
566
|
+
.example("bili status 732")
|
|
506
567
|
.action(async ({ session }, roomId) => {
|
|
507
|
-
this.logger.info(
|
|
568
|
+
this.logger.info("调用bili.status指令");
|
|
508
569
|
if (!roomId)
|
|
509
|
-
return session.send(
|
|
570
|
+
return session.send("请输入房间号!");
|
|
571
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
510
572
|
let content;
|
|
511
573
|
try {
|
|
512
574
|
content = await ctx.ba.getLiveRoomInfo(roomId);
|
|
513
575
|
}
|
|
514
576
|
catch (e) {
|
|
515
|
-
return
|
|
577
|
+
return `bili status指令 getLiveRoomInfo() 发生了错误,错误为:${e.message}`;
|
|
516
578
|
}
|
|
517
579
|
const { data } = content;
|
|
580
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
518
581
|
let userData;
|
|
519
582
|
try {
|
|
520
583
|
const { data: userInfo } = await ctx.ba.getMasterInfo(data.uid);
|
|
521
584
|
userData = userInfo;
|
|
522
585
|
}
|
|
523
586
|
catch (e) {
|
|
524
|
-
return
|
|
587
|
+
return `bili status指令 getMasterInfo() 发生了错误,错误为:${e.message}`;
|
|
525
588
|
}
|
|
526
589
|
// B站出问题了
|
|
527
590
|
if (content.code !== 0) {
|
|
528
|
-
if (content.msg ===
|
|
529
|
-
session.send(
|
|
591
|
+
if (content.msg === "未找到该房间") {
|
|
592
|
+
session.send("未找到该房间");
|
|
530
593
|
}
|
|
531
594
|
else {
|
|
532
|
-
session.send(
|
|
595
|
+
session.send(`未知错误,错误信息为:${content.message}`);
|
|
533
596
|
}
|
|
534
597
|
return;
|
|
535
598
|
}
|
|
536
|
-
const { pic, buffer } = await ctx.gi.generateLiveImg(data, userData.info.uname, userData.info.face, data.live_status !== 1
|
|
537
|
-
LiveType.NotLiveBroadcast
|
|
538
|
-
LiveType.LiveBroadcast);
|
|
599
|
+
const { pic, buffer } = await ctx.gi.generateLiveImg(data, userData.info.uname, userData.info.face, data.live_status !== 1
|
|
600
|
+
? LiveType.NotLiveBroadcast
|
|
601
|
+
: LiveType.LiveBroadcast);
|
|
539
602
|
// pic 存在,使用的是render模式
|
|
540
603
|
if (pic)
|
|
541
604
|
return pic;
|
|
542
605
|
// pic不存在,说明使用的是page模式
|
|
543
|
-
await session.send(koishi_1.h.image(buffer,
|
|
606
|
+
await session.send(koishi_1.h.image(buffer, "image/png"));
|
|
544
607
|
});
|
|
545
608
|
biliCom
|
|
546
|
-
.subcommand(
|
|
547
|
-
.usage(
|
|
548
|
-
.example(
|
|
609
|
+
.subcommand(".private", "向主人账号发送一条测试消息", { hidden: true })
|
|
610
|
+
.usage("向主人账号发送一条测试消息")
|
|
611
|
+
.example("bili private 向主人账号发送一条测试消息")
|
|
549
612
|
.action(async ({ session }) => {
|
|
550
613
|
// 发送消息
|
|
551
|
-
await this.sendPrivateMsg(
|
|
614
|
+
await this.sendPrivateMsg("Hello World");
|
|
552
615
|
// 发送提示
|
|
553
|
-
await session.send(
|
|
616
|
+
await session.send("已发送消息,如未收到则说明您的机器人不支持发送私聊消息或您的信息填写有误");
|
|
554
617
|
});
|
|
555
618
|
}
|
|
556
619
|
async init(config) {
|
|
557
620
|
// 设置logger
|
|
558
|
-
this.logger = this.ctx.logger(
|
|
621
|
+
this.logger = this.ctx.logger("cr");
|
|
559
622
|
// 将config设置给类属性
|
|
560
623
|
this.config = config;
|
|
561
624
|
// 拿到私人机器人实例
|
|
562
|
-
this.privateBot = this.ctx.bots.find(bot => bot.platform === config.master.platform);
|
|
625
|
+
this.privateBot = this.ctx.bots.find((bot) => bot.platform === config.master.platform);
|
|
563
626
|
if (!this.privateBot) {
|
|
564
627
|
this.ctx.notifier.create({
|
|
565
|
-
content:
|
|
628
|
+
content: "您未配置私人机器人,将无法向您推送机器人状态!",
|
|
566
629
|
});
|
|
567
|
-
this.logger.error(
|
|
630
|
+
this.logger.error("您未配置私人机器人,将无法向您推送机器人状态!");
|
|
568
631
|
}
|
|
569
632
|
// 判断消息发送方式
|
|
570
633
|
if (config.automaticResend) {
|
|
571
|
-
this.sendMsgFunc = async (
|
|
634
|
+
this.sendMsgFunc = async (
|
|
635
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
636
|
+
bot, channelId,
|
|
637
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
638
|
+
content) => {
|
|
572
639
|
// 多次尝试发送消息
|
|
573
640
|
const attempts = 3;
|
|
574
641
|
for (let i = 0; i < attempts; i++) {
|
|
@@ -581,8 +648,9 @@ class ComRegister {
|
|
|
581
648
|
break;
|
|
582
649
|
}
|
|
583
650
|
catch (e) {
|
|
584
|
-
if (i === attempts - 1) {
|
|
585
|
-
|
|
651
|
+
if (i === attempts - 1) {
|
|
652
|
+
// 已尝试三次
|
|
653
|
+
this.logger.error(`发送群组ID:${channelId}消息失败!原因: ${e.message}`);
|
|
586
654
|
console.log(e);
|
|
587
655
|
this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
|
|
588
656
|
}
|
|
@@ -591,48 +659,79 @@ class ComRegister {
|
|
|
591
659
|
};
|
|
592
660
|
}
|
|
593
661
|
else {
|
|
594
|
-
this.sendMsgFunc = async (
|
|
662
|
+
this.sendMsgFunc = async (
|
|
663
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
664
|
+
bot, guild,
|
|
665
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
666
|
+
content) => {
|
|
595
667
|
try {
|
|
596
668
|
// 发送消息
|
|
597
669
|
await bot.sendMessage(guild, content);
|
|
598
670
|
}
|
|
599
671
|
catch (e) {
|
|
600
|
-
this.logger.error(`发送群组ID:${guild}消息失败!原因:
|
|
672
|
+
this.logger.error(`发送群组ID:${guild}消息失败!原因: ${e.message}`);
|
|
601
673
|
await this.sendPrivateMsg(`发送群组ID:${guild}消息失败,请查看日志`);
|
|
602
674
|
}
|
|
603
675
|
};
|
|
604
676
|
}
|
|
605
677
|
// 检查登录数据库是否有数据
|
|
606
|
-
this.loginDBData = (await this.ctx.database.get(
|
|
678
|
+
this.loginDBData = (await this.ctx.database.get("loginBili", 1, ["dynamic_group_id"]))[0];
|
|
607
679
|
// 判断登录信息是否已加载完毕
|
|
608
680
|
await this.checkIfLoginInfoIsLoaded();
|
|
609
681
|
// 如果未登录,则直接返回
|
|
610
682
|
if (!(await this.checkIfIsLogin())) {
|
|
611
683
|
// log
|
|
612
|
-
this.logger.info(
|
|
684
|
+
this.logger.info("账号未登录,请登录");
|
|
613
685
|
return;
|
|
614
686
|
}
|
|
615
687
|
// 从配置获取订阅
|
|
616
|
-
config.sub && await this.loadSubFromConfig(config.sub);
|
|
688
|
+
config.sub && (await this.loadSubFromConfig(config.sub));
|
|
617
689
|
// 从数据库获取订阅
|
|
618
690
|
await this.loadSubFromDatabase();
|
|
619
691
|
// 检查是否需要动态监测
|
|
620
692
|
this.checkIfDynamicDetectIsNeeded();
|
|
621
693
|
// 在控制台中显示订阅对象
|
|
622
694
|
this.updateSubNotifier();
|
|
695
|
+
// Test
|
|
696
|
+
const testTarget = [
|
|
697
|
+
{
|
|
698
|
+
channelIdArr: [
|
|
699
|
+
{
|
|
700
|
+
channelId: "635762054",
|
|
701
|
+
dynamic: true,
|
|
702
|
+
live: false,
|
|
703
|
+
liveGuardBuy: false,
|
|
704
|
+
atAll: false,
|
|
705
|
+
},
|
|
706
|
+
],
|
|
707
|
+
platform: "qqguild",
|
|
708
|
+
},
|
|
709
|
+
];
|
|
710
|
+
const buffer = await this.ctx.gi.generateWordCloudImg();
|
|
711
|
+
this.sendMsg(testTarget, koishi_1.h.image(buffer, "image/png"));
|
|
623
712
|
}
|
|
624
713
|
splitMultiPlatformStr(str) {
|
|
625
|
-
return str
|
|
626
|
-
|
|
714
|
+
return str
|
|
715
|
+
.split(";")
|
|
716
|
+
.map((cv) => cv.split("."))
|
|
717
|
+
.map(([idStr, platform]) => {
|
|
718
|
+
const channelIdArr = idStr.split(",").map((id) => {
|
|
627
719
|
const atAll = /@$/.test(id); // 使用正则表达式检查 id 是否以 @ 结尾
|
|
628
720
|
const channelId = atAll ? id.slice(0, -1) : id; // 去除末尾的 @
|
|
629
|
-
return {
|
|
721
|
+
return {
|
|
722
|
+
channelId,
|
|
723
|
+
dynamic: true,
|
|
724
|
+
live: true,
|
|
725
|
+
liveGuardBuy: false,
|
|
726
|
+
atAll,
|
|
727
|
+
};
|
|
630
728
|
});
|
|
631
729
|
return { channelIdArr, platform };
|
|
632
730
|
});
|
|
633
731
|
}
|
|
732
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
634
733
|
getBot(pf) {
|
|
635
|
-
return this.ctx.bots.find(bot => bot.platform === pf);
|
|
734
|
+
return this.ctx.bots.find((bot) => bot.platform === pf);
|
|
636
735
|
}
|
|
637
736
|
async sendPrivateMsg(content) {
|
|
638
737
|
if (this.config.master.enable) {
|
|
@@ -650,9 +749,9 @@ class ComRegister {
|
|
|
650
749
|
// 判断重启次数是否超过三次
|
|
651
750
|
if (this.rebootCount >= 3) {
|
|
652
751
|
// logger
|
|
653
|
-
this.logger.error(
|
|
752
|
+
this.logger.error("已重启插件三次,请检查机器人状态后使用指令 sys start 启动插件");
|
|
654
753
|
// 重启失败,发送消息
|
|
655
|
-
await this.sendPrivateMsg(
|
|
754
|
+
await this.sendPrivateMsg("已重启插件三次,请检查机器人状态后使用指令 sys start 启动插件");
|
|
656
755
|
// 关闭插件
|
|
657
756
|
await this.ctx.sm.disposePlugin();
|
|
658
757
|
// 结束
|
|
@@ -661,32 +760,33 @@ class ComRegister {
|
|
|
661
760
|
// 重启次数+1
|
|
662
761
|
this.rebootCount++;
|
|
663
762
|
// logger
|
|
664
|
-
this.logger.info(
|
|
763
|
+
this.logger.info("插件出现未知错误,正在重启插件");
|
|
665
764
|
// 重启插件
|
|
666
765
|
const flag = await this.ctx.sm.restartPlugin();
|
|
667
766
|
// 判断是否重启成功
|
|
668
767
|
if (flag) {
|
|
669
|
-
this.logger.info(
|
|
768
|
+
this.logger.info("重启插件成功");
|
|
670
769
|
}
|
|
671
770
|
else {
|
|
672
771
|
// logger
|
|
673
|
-
this.logger.error(
|
|
772
|
+
this.logger.error("重启插件失败,请检查机器人状态后使用指令 sys start 启动插件");
|
|
674
773
|
// 重启失败,发送消息
|
|
675
|
-
await this.sendPrivateMsg(
|
|
774
|
+
await this.sendPrivateMsg("重启插件失败,请检查机器人状态后使用指令 sys start 启动插件");
|
|
676
775
|
// 关闭插件
|
|
677
776
|
await this.ctx.sm.disposePlugin();
|
|
678
777
|
}
|
|
679
778
|
}
|
|
680
779
|
async sendPrivateMsgAndStopService() {
|
|
681
780
|
// 发送消息
|
|
682
|
-
await this.sendPrivateMsg(
|
|
781
|
+
await this.sendPrivateMsg("插件发生未知错误,请检查机器人状态后使用指令 sys start 启动插件");
|
|
683
782
|
// logger
|
|
684
|
-
this.logger.error(
|
|
783
|
+
this.logger.error("插件发生未知错误,请检查机器人状态后使用指令 sys start 启动插件");
|
|
685
784
|
// 关闭插件
|
|
686
785
|
await this.ctx.sm.disposePlugin();
|
|
687
786
|
// 结束
|
|
688
787
|
return;
|
|
689
788
|
}
|
|
789
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
690
790
|
async sendMsg(targets, content, live) {
|
|
691
791
|
for (const target of targets) {
|
|
692
792
|
// 获取机器人实例
|
|
@@ -694,7 +794,7 @@ class ComRegister {
|
|
|
694
794
|
// 定义需要发送的数组
|
|
695
795
|
let sendArr = [];
|
|
696
796
|
// 判断是否需要推送所有机器人加入的群
|
|
697
|
-
if (target.channelIdArr[0].channelId ===
|
|
797
|
+
if (target.channelIdArr[0].channelId === "all") {
|
|
698
798
|
// 获取所有guild
|
|
699
799
|
for (const guild of (await bot.getGuildList()).data) {
|
|
700
800
|
sendArr.push({
|
|
@@ -702,7 +802,7 @@ class ComRegister {
|
|
|
702
802
|
dynamic: target.channelIdArr[0].dynamic,
|
|
703
803
|
live: target.channelIdArr[0].live,
|
|
704
804
|
liveGuardBuy: target.channelIdArr[0].liveGuardBuy,
|
|
705
|
-
atAll: target.channelIdArr[0].atAll
|
|
805
|
+
atAll: target.channelIdArr[0].atAll,
|
|
706
806
|
});
|
|
707
807
|
}
|
|
708
808
|
}
|
|
@@ -753,7 +853,7 @@ class ComRegister {
|
|
|
753
853
|
// 检测启动初始化
|
|
754
854
|
if (detectSetup) {
|
|
755
855
|
// 获取动态信息
|
|
756
|
-
const data = await this.ctx.ba.getAllDynamic();
|
|
856
|
+
const data = (await this.ctx.ba.getAllDynamic());
|
|
757
857
|
// 判断获取动态信息是否成功
|
|
758
858
|
if (data.code !== 0)
|
|
759
859
|
return;
|
|
@@ -766,6 +866,7 @@ class ComRegister {
|
|
|
766
866
|
}
|
|
767
867
|
// 获取用户所有动态数据
|
|
768
868
|
let updateNum;
|
|
869
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
769
870
|
let content;
|
|
770
871
|
try {
|
|
771
872
|
// 查询是否有新动态
|
|
@@ -775,46 +876,50 @@ class ComRegister {
|
|
|
775
876
|
if (updateNum <= 0 || data.code !== 0)
|
|
776
877
|
return;
|
|
777
878
|
// 获取动态内容
|
|
778
|
-
content = await this.ctx.ba.getAllDynamic(updateBaseline);
|
|
879
|
+
content = (await this.ctx.ba.getAllDynamic(updateBaseline));
|
|
779
880
|
}
|
|
780
881
|
catch (e) {
|
|
781
|
-
return this.logger.error(
|
|
882
|
+
return this.logger.error(`dynamicDetect getUserSpaceDynamic() 发生了错误,错误为:${e.message}`);
|
|
782
883
|
}
|
|
783
884
|
// 判断获取动态内容是否成功
|
|
784
885
|
if (content.code !== 0) {
|
|
785
886
|
switch (content.code) {
|
|
786
|
-
case -101: {
|
|
887
|
+
case -101: {
|
|
888
|
+
// 账号未登录
|
|
787
889
|
// 输出日志
|
|
788
|
-
this.logger.error(
|
|
890
|
+
this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件");
|
|
789
891
|
// 发送私聊消息
|
|
790
|
-
await this.sendPrivateMsg(
|
|
892
|
+
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件");
|
|
791
893
|
// 停止服务
|
|
792
894
|
await this.ctx.sm.disposePlugin();
|
|
793
895
|
// 结束循环
|
|
794
896
|
break;
|
|
795
897
|
}
|
|
796
|
-
case -352: {
|
|
898
|
+
case -352: {
|
|
899
|
+
// 风控
|
|
797
900
|
// 输出日志
|
|
798
|
-
this.logger.error(
|
|
901
|
+
this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件");
|
|
799
902
|
// 发送私聊消息
|
|
800
|
-
await this.sendPrivateMsg(
|
|
903
|
+
await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件");
|
|
801
904
|
// 停止服务
|
|
802
905
|
await this.ctx.sm.disposePlugin();
|
|
803
906
|
// 结束循环
|
|
804
907
|
break;
|
|
805
908
|
}
|
|
806
909
|
case 4101128:
|
|
807
|
-
case 4101129: {
|
|
910
|
+
case 4101129: {
|
|
911
|
+
// 获取动态信息错误
|
|
808
912
|
// 输出日志
|
|
809
|
-
this.logger.error(
|
|
913
|
+
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
|
|
810
914
|
// 发送私聊消息
|
|
811
|
-
await this.sendPrivateMsg(
|
|
915
|
+
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`); // 未知错误
|
|
812
916
|
// 结束循环
|
|
813
917
|
break;
|
|
814
918
|
}
|
|
815
|
-
default: {
|
|
919
|
+
default: {
|
|
920
|
+
// 未知错误
|
|
816
921
|
// 发送私聊消息
|
|
817
|
-
await this.sendPrivateMsg(
|
|
922
|
+
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`); // 未知错误
|
|
818
923
|
// 结束循环
|
|
819
924
|
break;
|
|
820
925
|
}
|
|
@@ -834,9 +939,11 @@ class ComRegister {
|
|
|
834
939
|
// 从动态数据中取出UP主名称、UID和动态ID
|
|
835
940
|
const upUID = items[num].modules.module_author.mid;
|
|
836
941
|
// 寻找关注的UP主的动态
|
|
837
|
-
this.subManager
|
|
942
|
+
for (const sub of this.subManager) {
|
|
838
943
|
// 判断是否是订阅的UP主
|
|
839
|
-
|
|
944
|
+
// biome-ignore lint/suspicious/noDoubleEquals: <explanation>
|
|
945
|
+
if (sub.dynamic && sub.uid == upUID) {
|
|
946
|
+
// 订阅该UP主,推送该动态
|
|
840
947
|
// 判断更新动态是否为1条
|
|
841
948
|
if (updateNum === 1) {
|
|
842
949
|
// 判断dynamicIdStr是否有值,是否与当前动态ID一致
|
|
@@ -868,16 +975,16 @@ class ComRegister {
|
|
|
868
975
|
}
|
|
869
976
|
catch (e) {
|
|
870
977
|
// 直播开播动态,不做处理
|
|
871
|
-
if (e.message ===
|
|
978
|
+
if (e.message === "直播开播动态,不做处理")
|
|
872
979
|
return;
|
|
873
|
-
if (e.message ===
|
|
980
|
+
if (e.message === "出现关键词,屏蔽该动态") {
|
|
874
981
|
// 如果需要发送才发送
|
|
875
982
|
if (this.config.filter.notify) {
|
|
876
983
|
await this.sendMsg(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
|
|
877
984
|
}
|
|
878
985
|
return;
|
|
879
986
|
}
|
|
880
|
-
if (e.message ===
|
|
987
|
+
if (e.message === "已屏蔽转发动态") {
|
|
881
988
|
if (this.config.filter.notify) {
|
|
882
989
|
await this.sendMsg(sub.target, `${upName}发布了一条转发动态,已屏蔽`);
|
|
883
990
|
}
|
|
@@ -885,30 +992,32 @@ class ComRegister {
|
|
|
885
992
|
}
|
|
886
993
|
// 未知错误
|
|
887
994
|
if (i === attempts - 1) {
|
|
888
|
-
this.logger.error(
|
|
995
|
+
this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
|
|
889
996
|
// 发送私聊消息并重启服务
|
|
890
997
|
return await this.sendPrivateMsgAndStopService();
|
|
891
998
|
}
|
|
892
999
|
}
|
|
893
1000
|
}
|
|
894
1001
|
// 判断是否需要发送URL
|
|
895
|
-
const dUrl = this.config.dynamicUrl
|
|
1002
|
+
const dUrl = this.config.dynamicUrl
|
|
1003
|
+
? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}`
|
|
1004
|
+
: "";
|
|
896
1005
|
// 如果pic存在,则直接返回pic
|
|
897
1006
|
if (pic) {
|
|
898
|
-
this.logger.info(
|
|
1007
|
+
this.logger.info("推送动态中,使用render模式");
|
|
899
1008
|
// pic存在,使用的是render模式
|
|
900
|
-
await this.sendMsg(sub.target, pic +
|
|
1009
|
+
await this.sendMsg(sub.target, pic + dUrl);
|
|
901
1010
|
}
|
|
902
1011
|
else if (buffer) {
|
|
903
|
-
this.logger.info(
|
|
1012
|
+
this.logger.info("推送动态中,使用page模式");
|
|
904
1013
|
// pic不存在,说明使用的是page模式
|
|
905
|
-
await this.sendMsg(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer,
|
|
1014
|
+
await this.sendMsg(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/png"), dUrl] }));
|
|
906
1015
|
}
|
|
907
1016
|
else {
|
|
908
|
-
this.logger.info(items[num].modules.module_author.name
|
|
1017
|
+
this.logger.info(`${items[num].modules.module_author.name}发布了一条动态,但是推送失败`);
|
|
909
1018
|
}
|
|
910
1019
|
}
|
|
911
|
-
}
|
|
1020
|
+
}
|
|
912
1021
|
}
|
|
913
1022
|
}
|
|
914
1023
|
finally {
|
|
@@ -937,7 +1046,7 @@ class ComRegister {
|
|
|
937
1046
|
// 检测启动初始化
|
|
938
1047
|
if (detectSetup) {
|
|
939
1048
|
// 获取动态信息
|
|
940
|
-
const data = await this.ctx.ba.getAllDynamic();
|
|
1049
|
+
const data = (await this.ctx.ba.getAllDynamic());
|
|
941
1050
|
// 判断获取动态信息是否成功
|
|
942
1051
|
if (data.code !== 0)
|
|
943
1052
|
return;
|
|
@@ -951,59 +1060,65 @@ class ComRegister {
|
|
|
951
1060
|
}
|
|
952
1061
|
// 获取用户所有动态数据
|
|
953
1062
|
let updateNum;
|
|
1063
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
954
1064
|
let content;
|
|
955
1065
|
try {
|
|
956
1066
|
// 查询是否有新动态
|
|
957
1067
|
const data = await this.ctx.ba.hasNewDynamic(updateBaseline);
|
|
958
1068
|
updateNum = data.data.update_num;
|
|
1069
|
+
// biome-ignore lint/style/noUnusedTemplateLiteral: <explanation>
|
|
959
1070
|
console.log(`获取是否有新动态:`);
|
|
960
1071
|
console.log(data);
|
|
961
1072
|
// 没有新动态或获取动态信息失败直接返回
|
|
962
1073
|
if (updateNum <= 0 || data.code !== 0)
|
|
963
1074
|
return;
|
|
964
1075
|
// 获取动态内容
|
|
965
|
-
content = await this.ctx.ba.getAllDynamic(updateBaseline);
|
|
966
|
-
console.log(
|
|
1076
|
+
content = (await this.ctx.ba.getAllDynamic(updateBaseline));
|
|
1077
|
+
console.log("获取动态内容:");
|
|
967
1078
|
console.log(content.data.items[0]);
|
|
968
1079
|
}
|
|
969
1080
|
catch (e) {
|
|
970
|
-
return this.logger.error(
|
|
1081
|
+
return this.logger.error(`dynamicDetect getUserSpaceDynamic() 发生了错误,错误为:${e.message}`);
|
|
971
1082
|
}
|
|
972
1083
|
// 判断获取动态内容是否成功
|
|
973
1084
|
if (content.code !== 0) {
|
|
974
1085
|
switch (content.code) {
|
|
975
|
-
case -101: {
|
|
1086
|
+
case -101: {
|
|
1087
|
+
// 账号未登录
|
|
976
1088
|
// 输出日志
|
|
977
|
-
this.logger.error(
|
|
1089
|
+
this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件");
|
|
978
1090
|
// 发送私聊消息
|
|
979
|
-
await this.sendPrivateMsg(
|
|
1091
|
+
await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件");
|
|
980
1092
|
// 停止服务
|
|
981
1093
|
await this.ctx.sm.disposePlugin();
|
|
982
1094
|
// 结束循环
|
|
983
1095
|
break;
|
|
984
1096
|
}
|
|
985
|
-
case -352: {
|
|
1097
|
+
case -352: {
|
|
1098
|
+
// 风控
|
|
986
1099
|
// 输出日志
|
|
987
|
-
this.logger.error(
|
|
1100
|
+
this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件");
|
|
988
1101
|
// 发送私聊消息
|
|
989
|
-
await this.sendPrivateMsg(
|
|
1102
|
+
await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件");
|
|
990
1103
|
// 停止服务
|
|
991
1104
|
await this.ctx.sm.disposePlugin();
|
|
992
1105
|
// 结束循环
|
|
993
1106
|
break;
|
|
994
1107
|
}
|
|
995
1108
|
case 4101128:
|
|
996
|
-
case 4101129: {
|
|
1109
|
+
case 4101129: {
|
|
1110
|
+
// 获取动态信息错误
|
|
997
1111
|
// 输出日志
|
|
998
|
-
this.logger.error(
|
|
1112
|
+
this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
|
|
999
1113
|
// 发送私聊消息
|
|
1000
|
-
await this.sendPrivateMsg(
|
|
1114
|
+
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`); // 未知错误
|
|
1001
1115
|
// 结束循环
|
|
1002
1116
|
break;
|
|
1003
1117
|
}
|
|
1004
|
-
default: {
|
|
1118
|
+
default: {
|
|
1119
|
+
// 未知错误
|
|
1005
1120
|
// 发送私聊消息
|
|
1006
|
-
await this.sendPrivateMsg(
|
|
1121
|
+
await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`); // 未知错误
|
|
1007
1122
|
// 结束循环
|
|
1008
1123
|
break;
|
|
1009
1124
|
}
|
|
@@ -1019,7 +1134,7 @@ class ComRegister {
|
|
|
1019
1134
|
// 检查更新的动态
|
|
1020
1135
|
for (let num = updateNum - 1; num >= 0; num--) {
|
|
1021
1136
|
// 有更新动态
|
|
1022
|
-
console.log(
|
|
1137
|
+
console.log("有更新动态");
|
|
1023
1138
|
// 没有动态内容则直接跳过
|
|
1024
1139
|
if (!items[num])
|
|
1025
1140
|
continue;
|
|
@@ -1029,10 +1144,12 @@ class ComRegister {
|
|
|
1029
1144
|
const dynamicId = content.data.items[num].id_str;
|
|
1030
1145
|
console.log(`寻找关注的UP主,当前动态UP主:${upName},UID:${upUID},动态ID:${dynamicId}`);
|
|
1031
1146
|
// 寻找关注的UP主的动态
|
|
1032
|
-
this.subManager
|
|
1147
|
+
for (const sub of this.subManager) {
|
|
1033
1148
|
console.log(`当前订阅UP主:${sub.uid}`);
|
|
1034
1149
|
// 判断是否是订阅的UP主
|
|
1035
|
-
|
|
1150
|
+
// biome-ignore lint/suspicious/noDoubleEquals: <explanation>
|
|
1151
|
+
if (sub.dynamic && sub.uid == upUID) {
|
|
1152
|
+
// 订阅该UP主,推送该动态
|
|
1036
1153
|
// 判断更新动态是否为1条
|
|
1037
1154
|
if (updateNum === 1) {
|
|
1038
1155
|
// 判断dynamicIdStr是否有值,是否与当前动态ID一致
|
|
@@ -1065,16 +1182,16 @@ class ComRegister {
|
|
|
1065
1182
|
}
|
|
1066
1183
|
catch (e) {
|
|
1067
1184
|
// 直播开播动态,不做处理
|
|
1068
|
-
if (e.message ===
|
|
1185
|
+
if (e.message === "直播开播动态,不做处理")
|
|
1069
1186
|
return;
|
|
1070
|
-
if (e.message ===
|
|
1187
|
+
if (e.message === "出现关键词,屏蔽该动态") {
|
|
1071
1188
|
// 如果需要发送才发送
|
|
1072
1189
|
if (this.config.filter.notify) {
|
|
1073
1190
|
await this.sendMsg(sub.target, `${upName}发布了一条含有屏蔽关键字的动态`);
|
|
1074
1191
|
}
|
|
1075
1192
|
return;
|
|
1076
1193
|
}
|
|
1077
|
-
if (e.message ===
|
|
1194
|
+
if (e.message === "已屏蔽转发动态") {
|
|
1078
1195
|
if (this.config.filter.notify) {
|
|
1079
1196
|
await this.sendMsg(sub.target, `${upName}发布了一条转发动态,已屏蔽`);
|
|
1080
1197
|
}
|
|
@@ -1082,30 +1199,32 @@ class ComRegister {
|
|
|
1082
1199
|
}
|
|
1083
1200
|
// 未知错误
|
|
1084
1201
|
if (i === attempts - 1) {
|
|
1085
|
-
this.logger.error(
|
|
1202
|
+
this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
|
|
1086
1203
|
// 发送私聊消息并重启服务
|
|
1087
1204
|
return await this.sendPrivateMsgAndStopService();
|
|
1088
1205
|
}
|
|
1089
1206
|
}
|
|
1090
1207
|
}
|
|
1091
1208
|
// 判断是否需要发送URL
|
|
1092
|
-
const dUrl = this.config.dynamicUrl
|
|
1209
|
+
const dUrl = this.config.dynamicUrl
|
|
1210
|
+
? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}`
|
|
1211
|
+
: "";
|
|
1093
1212
|
// 如果pic存在,则直接返回pic
|
|
1094
1213
|
if (pic) {
|
|
1095
|
-
this.logger.info(
|
|
1214
|
+
this.logger.info("推送动态中,使用render模式");
|
|
1096
1215
|
// pic存在,使用的是render模式
|
|
1097
|
-
await this.sendMsg(sub.target, pic +
|
|
1216
|
+
await this.sendMsg(sub.target, pic + dUrl);
|
|
1098
1217
|
}
|
|
1099
1218
|
else if (buffer) {
|
|
1100
|
-
this.logger.info(
|
|
1219
|
+
this.logger.info("推送动态中,使用page模式");
|
|
1101
1220
|
// pic不存在,说明使用的是page模式
|
|
1102
|
-
await this.sendMsg(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer,
|
|
1221
|
+
await this.sendMsg(sub.target, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/png"), dUrl] }));
|
|
1103
1222
|
}
|
|
1104
1223
|
else {
|
|
1105
|
-
this.logger.info(items[num].modules.module_author.name
|
|
1224
|
+
this.logger.info(`${items[num].modules.module_author.name}发布了一条动态,但是推送失败`);
|
|
1106
1225
|
}
|
|
1107
1226
|
}
|
|
1108
|
-
}
|
|
1227
|
+
}
|
|
1109
1228
|
}
|
|
1110
1229
|
}
|
|
1111
1230
|
finally {
|
|
@@ -1131,8 +1250,9 @@ class ComRegister {
|
|
|
1131
1250
|
break;
|
|
1132
1251
|
}
|
|
1133
1252
|
catch (e) {
|
|
1134
|
-
if (i === attempts - 1) {
|
|
1135
|
-
|
|
1253
|
+
if (i === attempts - 1) {
|
|
1254
|
+
// 已尝试三次
|
|
1255
|
+
this.logger.error(`liveDetect generateLiveImg() 推送卡片生成失败,原因:${e.message}`);
|
|
1136
1256
|
// 发送私聊消息并重启服务
|
|
1137
1257
|
return await this.sendPrivateMsgAndStopService();
|
|
1138
1258
|
}
|
|
@@ -1143,13 +1263,13 @@ class ComRegister {
|
|
|
1143
1263
|
if (pic) {
|
|
1144
1264
|
// 只有在开播时才艾特全体成员
|
|
1145
1265
|
if (liveType === LiveType.StartBroadcasting) {
|
|
1146
|
-
return await this.sendMsg(info.target, pic + (liveNotifyMsg ??
|
|
1266
|
+
return await this.sendMsg(info.target, pic + (liveNotifyMsg ?? ""), true);
|
|
1147
1267
|
}
|
|
1148
1268
|
// 正常不需要艾特全体成员
|
|
1149
|
-
return await this.sendMsg(info.target, pic + (liveNotifyMsg ??
|
|
1269
|
+
return await this.sendMsg(info.target, pic + (liveNotifyMsg ?? ""));
|
|
1150
1270
|
}
|
|
1151
1271
|
// pic不存在,说明使用的是page模式
|
|
1152
|
-
const msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer,
|
|
1272
|
+
const msg = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, "image/png"), liveNotifyMsg || ""] }));
|
|
1153
1273
|
// 只有在开播时才艾特全体成员
|
|
1154
1274
|
if (liveType === LiveType.StartBroadcasting) {
|
|
1155
1275
|
return await this.sendMsg(info.target, msg, true);
|
|
@@ -1160,10 +1280,15 @@ class ComRegister {
|
|
|
1160
1280
|
// 定义获取主播信息方法
|
|
1161
1281
|
async useMasterInfo(uid) {
|
|
1162
1282
|
const { data } = await this.ctx.ba.getMasterInfo(uid);
|
|
1163
|
-
return {
|
|
1283
|
+
return {
|
|
1284
|
+
username: data.info.uname,
|
|
1285
|
+
userface: data.info.face,
|
|
1286
|
+
roomId: data.room_id,
|
|
1287
|
+
};
|
|
1164
1288
|
}
|
|
1165
1289
|
async useLiveRoomInfo(roomId) {
|
|
1166
1290
|
// 发送请求获取直播间信息
|
|
1291
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
1167
1292
|
let content;
|
|
1168
1293
|
const attempts = 3;
|
|
1169
1294
|
for (let i = 0; i < attempts; i++) {
|
|
@@ -1174,8 +1299,9 @@ class ComRegister {
|
|
|
1174
1299
|
break;
|
|
1175
1300
|
}
|
|
1176
1301
|
catch (e) {
|
|
1177
|
-
this.logger.error(
|
|
1178
|
-
if (i === attempts - 1) {
|
|
1302
|
+
this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
|
|
1303
|
+
if (i === attempts - 1) {
|
|
1304
|
+
// 已尝试三次
|
|
1179
1305
|
// 发送私聊消息并重启服务
|
|
1180
1306
|
return await this.sendPrivateMsgAndStopService();
|
|
1181
1307
|
}
|
|
@@ -1194,6 +1320,7 @@ class ComRegister {
|
|
|
1194
1320
|
const liveRecord = {};
|
|
1195
1321
|
// 定义函数: 发送请求获取直播状态
|
|
1196
1322
|
const useLiveStatus = async (roomId) => {
|
|
1323
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
1197
1324
|
let content;
|
|
1198
1325
|
const attempts = 3;
|
|
1199
1326
|
for (let i = 0; i < attempts; i++) {
|
|
@@ -1204,8 +1331,9 @@ class ComRegister {
|
|
|
1204
1331
|
break;
|
|
1205
1332
|
}
|
|
1206
1333
|
catch (e) {
|
|
1207
|
-
this.logger.error(
|
|
1208
|
-
if (i === attempts - 1) {
|
|
1334
|
+
this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
|
|
1335
|
+
if (i === attempts - 1) {
|
|
1336
|
+
// 已尝试三次
|
|
1209
1337
|
// 发送私聊消息并重启服务
|
|
1210
1338
|
return await this.sendPrivateMsgAndStopService();
|
|
1211
1339
|
}
|
|
@@ -1228,17 +1356,21 @@ class ComRegister {
|
|
|
1228
1356
|
// 将第一次订阅置为false
|
|
1229
1357
|
liveDetectSetup = false;
|
|
1230
1358
|
// 初始化subRecord
|
|
1231
|
-
this.subManager
|
|
1359
|
+
for (const sub of this.subManager) {
|
|
1232
1360
|
// 判断是否订阅直播
|
|
1233
1361
|
if (sub.live) {
|
|
1234
1362
|
// 将该订阅添加到subRecord中
|
|
1235
|
-
liveRecord[sub.uid] = {
|
|
1363
|
+
liveRecord[sub.uid] = {
|
|
1364
|
+
liveStatus: 0,
|
|
1365
|
+
liveTime: "",
|
|
1366
|
+
target: sub.target,
|
|
1367
|
+
};
|
|
1236
1368
|
}
|
|
1237
|
-
}
|
|
1369
|
+
}
|
|
1238
1370
|
// 先判断是否有UP主正在直播
|
|
1239
1371
|
if (liveUsers.count > 0) {
|
|
1240
1372
|
// 遍历liveUsers
|
|
1241
|
-
liveUsers.items
|
|
1373
|
+
for (const item of liveUsers.items) {
|
|
1242
1374
|
// 判断是否有订阅对象正在直播
|
|
1243
1375
|
if (liveRecord[item.mid]) {
|
|
1244
1376
|
// 获取当前用户直播间信息
|
|
@@ -1248,26 +1380,28 @@ class ComRegister {
|
|
|
1248
1380
|
// 改变开播状态
|
|
1249
1381
|
liveRecord[item.mid].liveStatus = 1;
|
|
1250
1382
|
// 设置直播中消息
|
|
1251
|
-
const liveMsg = this.config.customLive
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1383
|
+
const liveMsg = this.config.customLive
|
|
1384
|
+
? this.config.customLive
|
|
1385
|
+
.replace("-name", item.uname)
|
|
1386
|
+
.replace("-time", await this.ctx.gi.getTimeDifference(liveRecord[item.mid].liveTime))
|
|
1387
|
+
.replace("-link", `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`)
|
|
1388
|
+
: null;
|
|
1255
1389
|
// 发送直播通知卡片
|
|
1256
1390
|
if (this.config.restartPush)
|
|
1257
1391
|
this.sendLiveNotifyCard({
|
|
1258
1392
|
username: item.uname,
|
|
1259
1393
|
userface: item.face,
|
|
1260
1394
|
target: liveRecord[item.mid].target,
|
|
1261
|
-
data
|
|
1395
|
+
data,
|
|
1262
1396
|
}, LiveType.LiveBroadcast, liveMsg);
|
|
1263
1397
|
}
|
|
1264
|
-
}
|
|
1398
|
+
}
|
|
1265
1399
|
}
|
|
1266
1400
|
// 没有正在直播的订阅对象,直接返回
|
|
1267
1401
|
return;
|
|
1268
1402
|
}
|
|
1269
1403
|
// 获取当前订阅直播的数量
|
|
1270
|
-
const currentLiveSubs = this.subManager.filter(sub => sub.live);
|
|
1404
|
+
const currentLiveSubs = this.subManager.filter((sub) => sub.live);
|
|
1271
1405
|
// 获取当前liveRecord里的订阅数量
|
|
1272
1406
|
const currentLiveRecordKeys = Object.keys(liveRecord);
|
|
1273
1407
|
// 判断是否能匹配双方数量
|
|
@@ -1280,15 +1414,25 @@ class ComRegister {
|
|
|
1280
1414
|
const data = await useLiveStatus(sub.roomId.toString());
|
|
1281
1415
|
switch (data.live_status) {
|
|
1282
1416
|
case 0:
|
|
1283
|
-
case 2: {
|
|
1417
|
+
case 2: {
|
|
1418
|
+
// 未开播
|
|
1284
1419
|
// 添加到liveRecord中
|
|
1285
|
-
liveRecord[sub.uid] = {
|
|
1420
|
+
liveRecord[sub.uid] = {
|
|
1421
|
+
liveStatus: 0,
|
|
1422
|
+
liveTime: "",
|
|
1423
|
+
target: sub.target,
|
|
1424
|
+
};
|
|
1286
1425
|
// break
|
|
1287
1426
|
break;
|
|
1288
1427
|
}
|
|
1289
|
-
case 1: {
|
|
1428
|
+
case 1: {
|
|
1429
|
+
//正在直播
|
|
1290
1430
|
// 添加到liveRecord中
|
|
1291
|
-
liveRecord[sub.uid] = {
|
|
1431
|
+
liveRecord[sub.uid] = {
|
|
1432
|
+
liveStatus: 1,
|
|
1433
|
+
liveTime: data.live_time,
|
|
1434
|
+
target: sub.target,
|
|
1435
|
+
};
|
|
1292
1436
|
}
|
|
1293
1437
|
}
|
|
1294
1438
|
}
|
|
@@ -1296,10 +1440,10 @@ class ComRegister {
|
|
|
1296
1440
|
}
|
|
1297
1441
|
if (currentLiveRecordKeys.length > currentLiveSubs.length) {
|
|
1298
1442
|
// 创建Set
|
|
1299
|
-
const setCurrentLiveSubs = new Set(currentLiveSubs.map(sub => sub.uid));
|
|
1443
|
+
const setCurrentLiveSubs = new Set(currentLiveSubs.map((sub) => sub.uid));
|
|
1300
1444
|
// 找出 currentLiveRecordKeys中比currentLiveSubs 多的元素
|
|
1301
|
-
const extraInCurrentLiveSubs = currentLiveRecordKeys.filter(key => !setCurrentLiveSubs.has(key));
|
|
1302
|
-
// 遍历 extraInCurrentLiveSubs
|
|
1445
|
+
const extraInCurrentLiveSubs = currentLiveRecordKeys.filter((key) => !setCurrentLiveSubs.has(key));
|
|
1446
|
+
// 遍历 extraInCurrentLiveSubs
|
|
1303
1447
|
for (const subUID of extraInCurrentLiveSubs) {
|
|
1304
1448
|
// 删除记录
|
|
1305
1449
|
delete liveRecord[subUID];
|
|
@@ -1307,79 +1451,90 @@ class ComRegister {
|
|
|
1307
1451
|
}
|
|
1308
1452
|
// 数量没有差异,则不进行其他操作
|
|
1309
1453
|
// 遍历liveUsers
|
|
1310
|
-
liveUsers.items
|
|
1454
|
+
for (const item of liveUsers.items) {
|
|
1311
1455
|
// 判断是否有正在直播的订阅对象
|
|
1312
|
-
if (liveRecord[item.mid]) {
|
|
1456
|
+
if (liveRecord[item.mid]) {
|
|
1457
|
+
// 有正在直播的订阅对象
|
|
1313
1458
|
// 获取当前用户直播间信息
|
|
1314
1459
|
const data = await useLiveStatus(item.room_id.toString());
|
|
1315
1460
|
// 判断开播状态
|
|
1316
1461
|
switch (liveRecord[item.mid].liveStatus) {
|
|
1317
|
-
case 0: {
|
|
1462
|
+
case 0: {
|
|
1463
|
+
// 之前未开播,现在开播了
|
|
1318
1464
|
// 设置开播时间
|
|
1319
1465
|
liveRecord[item.mid].liveTime = data.live_time;
|
|
1320
|
-
// 定义开播通知语
|
|
1321
|
-
const liveStartMsg = this.config.customLiveStart
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1466
|
+
// 定义开播通知语
|
|
1467
|
+
const liveStartMsg = this.config.customLiveStart
|
|
1468
|
+
? this.config.customLiveStart
|
|
1469
|
+
.replace("-name", item.uname)
|
|
1470
|
+
.replace("-time", await this.ctx.gi.getTimeDifference(liveRecord[item.mid].liveTime))
|
|
1471
|
+
.replace("-link", `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`)
|
|
1472
|
+
: null;
|
|
1325
1473
|
// 发送直播通知卡片
|
|
1326
1474
|
await this.sendLiveNotifyCard({
|
|
1327
1475
|
username: item.uname,
|
|
1328
1476
|
userface: item.face,
|
|
1329
1477
|
target: liveRecord[item.mid].target,
|
|
1330
|
-
data
|
|
1478
|
+
data,
|
|
1331
1479
|
}, LiveType.LiveBroadcast, liveStartMsg);
|
|
1332
1480
|
// 改变开播状态
|
|
1333
1481
|
liveRecord[item.mid].liveStatus = 1;
|
|
1334
1482
|
// 结束
|
|
1335
1483
|
break;
|
|
1336
1484
|
}
|
|
1337
|
-
case 1: {
|
|
1485
|
+
case 1: {
|
|
1486
|
+
// 仍在直播
|
|
1338
1487
|
if (this.config.pushTime > 0) {
|
|
1339
1488
|
timer++;
|
|
1340
1489
|
// 开始记录时间
|
|
1341
|
-
if (timer >=
|
|
1490
|
+
if (timer >= 6 * 60 * this.config.pushTime) {
|
|
1491
|
+
// 到时间推送直播消息
|
|
1342
1492
|
// 到时间重新计时
|
|
1343
1493
|
timer = 0;
|
|
1344
1494
|
// 定义直播中通知消息
|
|
1345
|
-
const liveMsg = this.config.customLive
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1495
|
+
const liveMsg = this.config.customLive
|
|
1496
|
+
? this.config.customLive
|
|
1497
|
+
.replace("-name", item.uname)
|
|
1498
|
+
.replace("-time", await this.ctx.gi.getTimeDifference(liveRecord[item.mid].liveTime))
|
|
1499
|
+
.replace("-link", `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`)
|
|
1500
|
+
: null;
|
|
1349
1501
|
// 发送直播通知卡片
|
|
1350
1502
|
this.sendLiveNotifyCard({
|
|
1351
1503
|
username: item.uname,
|
|
1352
1504
|
userface: item.face,
|
|
1353
1505
|
target: liveRecord[item.mid].target,
|
|
1354
|
-
data
|
|
1506
|
+
data,
|
|
1355
1507
|
}, LiveType.LiveBroadcast, liveMsg);
|
|
1356
1508
|
}
|
|
1357
1509
|
}
|
|
1358
1510
|
}
|
|
1359
1511
|
}
|
|
1360
1512
|
}
|
|
1361
|
-
}
|
|
1513
|
+
}
|
|
1362
1514
|
// 找出liveRecord中liveStatus为1但liveUsers中没有的元素
|
|
1363
|
-
const extraInLiveRecord = currentLiveRecordKeys.filter(key => !liveUsers.items.some(item => item.mid === Number(key)));
|
|
1515
|
+
const extraInLiveRecord = currentLiveRecordKeys.filter((key) => !liveUsers.items.some((item) => item.mid === Number(key)));
|
|
1364
1516
|
// 遍历 extraInLiveRecord
|
|
1365
|
-
for (const subUID of extraInLiveRecord) {
|
|
1517
|
+
for (const subUID of extraInLiveRecord) {
|
|
1518
|
+
// 下播的主播
|
|
1366
1519
|
// 获取主播信息
|
|
1367
1520
|
const masterInfo = await this.useMasterInfo(subUID);
|
|
1368
1521
|
// 获取直播间消息
|
|
1369
1522
|
const liveRoomInfo = await this.useLiveRoomInfo(masterInfo.roomId.toString());
|
|
1370
1523
|
// 设置开播时间
|
|
1371
1524
|
liveRoomInfo.live_time = liveRecord[subUID].liveTime;
|
|
1372
|
-
// 定义下播播通知语
|
|
1373
|
-
const liveEndMsg = this.config.customLiveEnd
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1525
|
+
// 定义下播播通知语
|
|
1526
|
+
const liveEndMsg = this.config.customLiveEnd
|
|
1527
|
+
? this.config.customLiveEnd
|
|
1528
|
+
.replace("-name", masterInfo.username)
|
|
1529
|
+
.replace("-time", await this.ctx.gi.getTimeDifference(liveRecord[subUID].liveTime))
|
|
1530
|
+
.replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
|
|
1531
|
+
: null;
|
|
1377
1532
|
// 发送下播通知
|
|
1378
1533
|
this.sendLiveNotifyCard({
|
|
1379
1534
|
username: masterInfo.username,
|
|
1380
1535
|
userface: masterInfo.userface,
|
|
1381
1536
|
target: liveRecord[subUID].target,
|
|
1382
|
-
data: liveRoomInfo
|
|
1537
|
+
data: liveRoomInfo,
|
|
1383
1538
|
}, LiveType.StopBroadcast, liveEndMsg);
|
|
1384
1539
|
}
|
|
1385
1540
|
}
|
|
@@ -1402,18 +1557,19 @@ class ComRegister {
|
|
|
1402
1557
|
// 定义channelIdArr总长度
|
|
1403
1558
|
let channelIdArrLen = 0;
|
|
1404
1559
|
// 定义数据
|
|
1560
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
1405
1561
|
let liveRoomInfo;
|
|
1406
1562
|
let masterInfo;
|
|
1407
1563
|
// 找到频道/群组对应的
|
|
1408
|
-
const liveGuardBuyPushTargetArr = target.map(channel => {
|
|
1564
|
+
const liveGuardBuyPushTargetArr = target.map((channel) => {
|
|
1409
1565
|
// 获取符合条件的target
|
|
1410
|
-
const liveGuardBuyArr = channel.channelIdArr.filter(channelId => channelId.liveGuardBuy);
|
|
1566
|
+
const liveGuardBuyArr = channel.channelIdArr.filter((channelId) => channelId.liveGuardBuy);
|
|
1411
1567
|
// 将当前liveDanmakuArr的长度+到channelIdArrLen中
|
|
1412
1568
|
channelIdArrLen += liveGuardBuyArr.length;
|
|
1413
1569
|
// 返回符合的target
|
|
1414
1570
|
return {
|
|
1415
1571
|
channelIdArr: liveGuardBuyArr,
|
|
1416
|
-
platform: channel.platform
|
|
1572
|
+
platform: channel.platform,
|
|
1417
1573
|
};
|
|
1418
1574
|
});
|
|
1419
1575
|
// 定义定时推送函数
|
|
@@ -1421,75 +1577,43 @@ class ComRegister {
|
|
|
1421
1577
|
// 判断是否信息是否获取成功
|
|
1422
1578
|
if (!(await useMasterAndLiveRoomInfo())) {
|
|
1423
1579
|
// 未获取成功,直接返回
|
|
1424
|
-
return this.sendPrivateMsg(
|
|
1580
|
+
return this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
|
|
1425
1581
|
}
|
|
1426
1582
|
// 设置开播时间
|
|
1427
1583
|
liveTime = liveRoomInfo.live_time;
|
|
1428
1584
|
// 设置直播中消息
|
|
1429
|
-
const liveMsg = this.config.customLive
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1585
|
+
const liveMsg = this.config.customLive
|
|
1586
|
+
? this.config.customLive
|
|
1587
|
+
.replace("-name", masterInfo.username)
|
|
1588
|
+
.replace("-time", await this.ctx.gi.getTimeDifference(liveTime))
|
|
1589
|
+
.replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
|
|
1590
|
+
: null;
|
|
1433
1591
|
// 发送直播通知卡片
|
|
1434
1592
|
await this.sendLiveNotifyCard({
|
|
1435
1593
|
username: masterInfo.username,
|
|
1436
1594
|
userface: masterInfo.userface,
|
|
1437
1595
|
target,
|
|
1438
|
-
data: liveRoomInfo
|
|
1596
|
+
data: liveRoomInfo,
|
|
1439
1597
|
}, LiveType.LiveBroadcast, liveMsg);
|
|
1440
1598
|
};
|
|
1441
|
-
//
|
|
1442
|
-
|
|
1599
|
+
// TODO:WordCloud
|
|
1600
|
+
/* // 定义获取弹幕权重Record函数
|
|
1601
|
+
const getDanmakuWeightRecord = (): Record<string, number> => {
|
|
1443
1602
|
// 创建segmentit
|
|
1444
|
-
const segmentit =
|
|
1603
|
+
const segmentit = useDefault(new Segment());
|
|
1445
1604
|
// 创建Record
|
|
1446
|
-
const danmakuWeightRecord = {};
|
|
1605
|
+
const danmakuWeightRecord: Record<string, number> = {};
|
|
1447
1606
|
// 循环遍历currentLiveDanmakuArr
|
|
1448
1607
|
for (const danmaku of currentLiveDanmakuArr) {
|
|
1449
1608
|
// 遍历结果
|
|
1450
|
-
segmentit.doSegment(danmaku).map((word) => {
|
|
1609
|
+
segmentit.doSegment(danmaku).map((word: { w: string; p: number }) => {
|
|
1451
1610
|
// 定义权重
|
|
1452
1611
|
danmakuWeightRecord[word.w] = (danmakuWeightRecord[word.w] || 0) + 1;
|
|
1453
1612
|
});
|
|
1454
1613
|
}
|
|
1455
1614
|
// 返回Record
|
|
1456
1615
|
return danmakuWeightRecord;
|
|
1457
|
-
};
|
|
1458
|
-
// 定义获取弹幕词云函数
|
|
1459
|
-
const sendDanmakuWordCloud = (danmakuWeightRecord) => {
|
|
1460
|
-
// 准备词云数据
|
|
1461
|
-
const wordList = Object.keys(danmakuWeightRecord).map(word => ({ text: word, value: danmakuWeightRecord[word] }));
|
|
1462
|
-
// 创建画布
|
|
1463
|
-
const width = 800;
|
|
1464
|
-
const height = 600;
|
|
1465
|
-
const canvas = (0, canvas_1.createCanvas)(width, height);
|
|
1466
|
-
const context = canvas.getContext('2d');
|
|
1467
|
-
// 定义绘制函数
|
|
1468
|
-
const draw = (words) => {
|
|
1469
|
-
context.clearRect(0, 0, width, height);
|
|
1470
|
-
context.fillStyle = '#fff';
|
|
1471
|
-
context.fillRect(0, 0, width, height);
|
|
1472
|
-
words.forEach(function (d) {
|
|
1473
|
-
context.font = `${d.size}px Arial`;
|
|
1474
|
-
context.fillStyle = '#000';
|
|
1475
|
-
context.fillText(d.text, d.x, d.y);
|
|
1476
|
-
});
|
|
1477
|
-
// 保存画布为buffer
|
|
1478
|
-
const buffer = canvas.toBuffer('image/png');
|
|
1479
|
-
// 发送消息
|
|
1480
|
-
this.sendMsg(target, koishi_1.h.image(buffer, 'image/png'));
|
|
1481
|
-
};
|
|
1482
|
-
// 配置词云
|
|
1483
|
-
const layout = (0, d3_cloud_1.default)()
|
|
1484
|
-
.size([width, height])
|
|
1485
|
-
.words(wordList.map(d => ({ text: d.text, size: d.value })))
|
|
1486
|
-
.padding(5)
|
|
1487
|
-
.font('Arial')
|
|
1488
|
-
.fontSize(d => d.size)
|
|
1489
|
-
.on('end', draw);
|
|
1490
|
-
// 生成词云
|
|
1491
|
-
layout.start();
|
|
1492
|
-
};
|
|
1616
|
+
}; */
|
|
1493
1617
|
// 定义直播间信息获取函数
|
|
1494
1618
|
const useMasterAndLiveRoomInfo = async () => {
|
|
1495
1619
|
// 定义函数是否执行成功flag
|
|
@@ -1521,15 +1645,15 @@ class ComRegister {
|
|
|
1521
1645
|
// 判断是否信息是否获取成功
|
|
1522
1646
|
if (!(await useMasterAndLiveRoomInfo())) {
|
|
1523
1647
|
// 未获取成功,直接返回
|
|
1524
|
-
return this.sendPrivateMsg(
|
|
1648
|
+
return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
|
|
1525
1649
|
}
|
|
1526
1650
|
// 构建消息处理函数
|
|
1527
1651
|
const handler = {
|
|
1528
1652
|
onOpen: () => {
|
|
1529
|
-
this.logger.info(
|
|
1653
|
+
this.logger.info("直播间连接成功");
|
|
1530
1654
|
},
|
|
1531
1655
|
onClose: () => {
|
|
1532
|
-
this.logger.info(
|
|
1656
|
+
this.logger.info("直播间连接已断开");
|
|
1533
1657
|
},
|
|
1534
1658
|
onIncomeDanmu: ({ body }) => {
|
|
1535
1659
|
// 保存消息到数组
|
|
@@ -1556,21 +1680,23 @@ class ComRegister {
|
|
|
1556
1680
|
// 设置开播状态为false
|
|
1557
1681
|
liveStatus = false;
|
|
1558
1682
|
// 未获取成功,直接返回
|
|
1559
|
-
return await this.sendPrivateMsg(
|
|
1683
|
+
return await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
|
|
1560
1684
|
}
|
|
1561
1685
|
// 设置开播时间
|
|
1562
1686
|
liveTime = liveRoomInfo.live_time;
|
|
1563
|
-
// 定义开播通知语
|
|
1564
|
-
const liveStartMsg = this.config.customLiveStart
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1687
|
+
// 定义开播通知语
|
|
1688
|
+
const liveStartMsg = this.config.customLiveStart
|
|
1689
|
+
? this.config.customLiveStart
|
|
1690
|
+
.replace("-name", masterInfo.username)
|
|
1691
|
+
.replace("-time", await this.ctx.gi.getTimeDifference(liveTime))
|
|
1692
|
+
.replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
|
|
1693
|
+
: null;
|
|
1568
1694
|
// 推送开播通知
|
|
1569
1695
|
await this.sendLiveNotifyCard({
|
|
1570
1696
|
username: masterInfo.username,
|
|
1571
1697
|
userface: masterInfo.userface,
|
|
1572
1698
|
target,
|
|
1573
|
-
data: liveRoomInfo
|
|
1699
|
+
data: liveRoomInfo,
|
|
1574
1700
|
}, LiveType.StartBroadcasting, liveStartMsg);
|
|
1575
1701
|
// 判断定时器是否已开启
|
|
1576
1702
|
if (!pushAtTimeTimer) {
|
|
@@ -1579,33 +1705,33 @@ class ComRegister {
|
|
|
1579
1705
|
}
|
|
1580
1706
|
},
|
|
1581
1707
|
onLiveEnd: async () => {
|
|
1708
|
+
// 将直播状态设置为false
|
|
1709
|
+
liveStatus = false;
|
|
1582
1710
|
// 判断是否信息是否获取成功
|
|
1583
1711
|
if (!(await useMasterAndLiveRoomInfo())) {
|
|
1584
1712
|
// 未获取成功,直接返回
|
|
1585
|
-
return this.sendPrivateMsg(
|
|
1713
|
+
return this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
|
|
1586
1714
|
}
|
|
1587
1715
|
// 更改直播时长
|
|
1588
1716
|
liveRoomInfo.live_time = liveTime;
|
|
1589
|
-
// 定义下播播通知语
|
|
1590
|
-
const liveEndMsg = this.config.customLiveEnd
|
|
1591
|
-
|
|
1592
|
-
|
|
1717
|
+
// 定义下播播通知语
|
|
1718
|
+
const liveEndMsg = this.config.customLiveEnd
|
|
1719
|
+
? this.config.customLiveEnd
|
|
1720
|
+
.replace("-name", masterInfo.username)
|
|
1721
|
+
.replace("-time", await this.ctx.gi.getTimeDifference(liveTime))
|
|
1722
|
+
: null;
|
|
1593
1723
|
// 推送通知卡片
|
|
1594
1724
|
await this.sendLiveNotifyCard({
|
|
1595
1725
|
username: masterInfo.username,
|
|
1596
1726
|
userface: masterInfo.userface,
|
|
1597
1727
|
target,
|
|
1598
|
-
data: liveRoomInfo
|
|
1728
|
+
data: liveRoomInfo,
|
|
1599
1729
|
}, LiveType.StopBroadcast, liveEndMsg);
|
|
1600
1730
|
// 关闭定时推送定时器
|
|
1601
1731
|
pushAtTimeTimer();
|
|
1602
1732
|
// 将推送定时器变量置空
|
|
1603
1733
|
pushAtTimeTimer = null;
|
|
1604
|
-
|
|
1605
|
-
sendDanmakuWordCloud(getDanmakuWeightRecord());
|
|
1606
|
-
// 将直播状态设置为false
|
|
1607
|
-
liveStatus = false;
|
|
1608
|
-
}
|
|
1734
|
+
},
|
|
1609
1735
|
};
|
|
1610
1736
|
// 启动直播间弹幕监测
|
|
1611
1737
|
await this.ctx.bl.startLiveRoomListener(roomId, handler);
|
|
@@ -1614,17 +1740,19 @@ class ComRegister {
|
|
|
1614
1740
|
// 设置开播时间
|
|
1615
1741
|
liveTime = liveRoomInfo.live_time;
|
|
1616
1742
|
// 定义直播中通知消息
|
|
1617
|
-
const liveMsg = this.config.customLive
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1743
|
+
const liveMsg = this.config.customLive
|
|
1744
|
+
? this.config.customLive
|
|
1745
|
+
.replace("-name", masterInfo.username)
|
|
1746
|
+
.replace("-time", await this.ctx.gi.getTimeDifference(liveTime))
|
|
1747
|
+
.replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`)
|
|
1748
|
+
: null;
|
|
1621
1749
|
// 发送直播通知卡片
|
|
1622
1750
|
if (this.config.restartPush) {
|
|
1623
1751
|
await this.sendLiveNotifyCard({
|
|
1624
1752
|
username: masterInfo.username,
|
|
1625
1753
|
userface: masterInfo.userface,
|
|
1626
1754
|
target,
|
|
1627
|
-
data: liveRoomInfo
|
|
1755
|
+
data: liveRoomInfo,
|
|
1628
1756
|
}, LiveType.LiveBroadcast, liveMsg);
|
|
1629
1757
|
}
|
|
1630
1758
|
// 正在直播,开启定时器
|
|
@@ -1639,18 +1767,20 @@ class ComRegister {
|
|
|
1639
1767
|
}
|
|
1640
1768
|
subShow() {
|
|
1641
1769
|
// 在控制台中显示订阅对象
|
|
1642
|
-
let table =
|
|
1643
|
-
this.subManager
|
|
1644
|
-
table += `UID:${sub.uid} ${sub.dynamic ?
|
|
1645
|
-
}
|
|
1646
|
-
return table ? table :
|
|
1770
|
+
let table = "";
|
|
1771
|
+
for (const sub of this.subManager) {
|
|
1772
|
+
table += `UID:${sub.uid} ${sub.dynamic ? "已订阅动态" : ""} ${sub.live ? "已订阅直播" : ""}\n`;
|
|
1773
|
+
}
|
|
1774
|
+
return table ? table : "没有订阅任何UP";
|
|
1647
1775
|
}
|
|
1648
|
-
async checkIfNeedSub(liveSub, dynamicSub, session,
|
|
1776
|
+
async checkIfNeedSub(liveSub, dynamicSub, session,
|
|
1777
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
1778
|
+
liveRoomData) {
|
|
1649
1779
|
// 定义方法:用户直播间是否存在
|
|
1650
1780
|
const liveRoom = async () => {
|
|
1651
1781
|
if (!liveRoomData) {
|
|
1652
1782
|
// 未开通直播间
|
|
1653
|
-
await session.send(
|
|
1783
|
+
await session.send("该用户未开通直播间,无法订阅直播");
|
|
1654
1784
|
// 返回false
|
|
1655
1785
|
return true;
|
|
1656
1786
|
}
|
|
@@ -1682,28 +1812,30 @@ class ComRegister {
|
|
|
1682
1812
|
// 获取订阅信息
|
|
1683
1813
|
const subInfo = this.subShow();
|
|
1684
1814
|
// 定义table
|
|
1685
|
-
let table =
|
|
1686
|
-
if (subInfo ===
|
|
1815
|
+
let table = "";
|
|
1816
|
+
if (subInfo === "没有订阅任何UP") {
|
|
1687
1817
|
table = subInfo;
|
|
1688
1818
|
}
|
|
1689
1819
|
else {
|
|
1690
1820
|
// 获取subTable
|
|
1691
|
-
const subTableArray = subInfo.split(
|
|
1821
|
+
const subTableArray = subInfo.split("\n");
|
|
1692
1822
|
subTableArray.splice(subTableArray.length - 1, 1);
|
|
1693
1823
|
// 定义Table
|
|
1694
|
-
table = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("p", { children: "\u5F53\u524D\u8BA2\u9605\u5BF9\u8C61\uFF1A" }), (0, jsx_runtime_1.jsx)("ul", { children: subTableArray.map(str => (
|
|
1824
|
+
table = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("p", { children: "\u5F53\u524D\u8BA2\u9605\u5BF9\u8C61\uFF1A" }), (0, jsx_runtime_1.jsx)("ul", { children: subTableArray.map((str) => (
|
|
1825
|
+
// biome-ignore lint/correctness/useJsxKeyInIterable: <explanation>
|
|
1826
|
+
(0, jsx_runtime_1.jsx)("li", { children: str }))) })] }));
|
|
1695
1827
|
}
|
|
1696
1828
|
// 设置更新后的提示
|
|
1697
1829
|
this.subNotifier = this.ctx.notifier.create(table);
|
|
1698
1830
|
}
|
|
1699
1831
|
async checkIfLoginInfoIsLoaded() {
|
|
1700
|
-
return new Promise(resolve => {
|
|
1832
|
+
return new Promise((resolve) => {
|
|
1701
1833
|
const check = () => {
|
|
1702
1834
|
if (!this.ctx.ba.getLoginInfoIsLoaded()) {
|
|
1703
1835
|
this.ctx.setTimeout(check, 500);
|
|
1704
1836
|
}
|
|
1705
1837
|
else {
|
|
1706
|
-
resolve(
|
|
1838
|
+
resolve("success");
|
|
1707
1839
|
}
|
|
1708
1840
|
};
|
|
1709
1841
|
check();
|
|
@@ -1713,7 +1845,8 @@ class ComRegister {
|
|
|
1713
1845
|
// 获取关注分组信息
|
|
1714
1846
|
const checkGroupIsReady = async () => {
|
|
1715
1847
|
// 判断是否有数据
|
|
1716
|
-
if (this.loginDBData.dynamic_group_id ===
|
|
1848
|
+
if (this.loginDBData.dynamic_group_id === "" ||
|
|
1849
|
+
this.loginDBData.dynamic_group_id === null) {
|
|
1717
1850
|
// 没有数据,没有创建分组,尝试创建分组
|
|
1718
1851
|
const createGroupData = await this.ctx.ba.createGroup("订阅");
|
|
1719
1852
|
// 如果分组已创建,则获取分组id
|
|
@@ -1723,7 +1856,7 @@ class ComRegister {
|
|
|
1723
1856
|
// 遍历所有分组
|
|
1724
1857
|
for (const group of allGroupData.data) {
|
|
1725
1858
|
// 找到订阅分组
|
|
1726
|
-
if (group.name ===
|
|
1859
|
+
if (group.name === "订阅") {
|
|
1727
1860
|
// 拿到分组id
|
|
1728
1861
|
this.loginDBData.dynamic_group_id = group.tagid;
|
|
1729
1862
|
// 结束循环
|
|
@@ -1737,7 +1870,9 @@ class ComRegister {
|
|
|
1737
1870
|
return false;
|
|
1738
1871
|
}
|
|
1739
1872
|
// 创建成功,保存到数据库
|
|
1740
|
-
this.ctx.database.set(
|
|
1873
|
+
this.ctx.database.set("loginBili", 1, {
|
|
1874
|
+
dynamic_group_id: this.loginDBData.dynamic_group_id,
|
|
1875
|
+
});
|
|
1741
1876
|
// 创建成功
|
|
1742
1877
|
return true;
|
|
1743
1878
|
}
|
|
@@ -1748,7 +1883,7 @@ class ComRegister {
|
|
|
1748
1883
|
// 判断是否创建成功
|
|
1749
1884
|
if (!flag) {
|
|
1750
1885
|
// 创建分组失败
|
|
1751
|
-
return { flag: false, msg:
|
|
1886
|
+
return { flag: false, msg: "创建分组失败,请尝试重启插件" };
|
|
1752
1887
|
}
|
|
1753
1888
|
// 获取分组明细
|
|
1754
1889
|
const relationGroupDetailData = await this.ctx.ba.getRelationGroupDetail(this.loginDBData.dynamic_group_id);
|
|
@@ -1762,51 +1897,67 @@ class ComRegister {
|
|
|
1762
1897
|
// 判断是否创建成功
|
|
1763
1898
|
if (!flag) {
|
|
1764
1899
|
// 创建分组失败
|
|
1765
|
-
return { flag: false, msg:
|
|
1900
|
+
return { flag: false, msg: "创建分组失败,请尝试重启插件" };
|
|
1766
1901
|
}
|
|
1767
|
-
return { flag: true, msg:
|
|
1902
|
+
return { flag: true, msg: "分组不存在,已重新创建分组" };
|
|
1768
1903
|
}
|
|
1769
1904
|
// 获取分组明细失败
|
|
1770
|
-
return { flag: false, msg:
|
|
1905
|
+
return { flag: false, msg: "获取分组明细失败" };
|
|
1771
1906
|
}
|
|
1772
|
-
relationGroupDetailData.data
|
|
1907
|
+
for (const user of relationGroupDetailData.data) {
|
|
1773
1908
|
if (user.mid === mid) {
|
|
1774
1909
|
// 已关注订阅对象
|
|
1775
|
-
return { flag: true, msg:
|
|
1910
|
+
return { flag: true, msg: "订阅对象已存在于分组中" };
|
|
1776
1911
|
}
|
|
1777
|
-
}
|
|
1912
|
+
}
|
|
1778
1913
|
// 订阅对象
|
|
1779
1914
|
const subUserData = await this.ctx.ba.follow(mid);
|
|
1780
1915
|
// 判断是否订阅成功
|
|
1781
1916
|
switch (subUserData.code) {
|
|
1782
|
-
case -101:
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
case
|
|
1788
|
-
|
|
1917
|
+
case -101:
|
|
1918
|
+
return {
|
|
1919
|
+
flag: false,
|
|
1920
|
+
msg: "账号未登录,请使用指令bili login登录后再进行订阅操作",
|
|
1921
|
+
};
|
|
1922
|
+
case -102:
|
|
1923
|
+
return { flag: false, msg: "账号被封停,无法进行订阅操作" };
|
|
1924
|
+
case 22002:
|
|
1925
|
+
return { flag: false, msg: "因对方隐私设置,无法进行订阅操作" };
|
|
1926
|
+
case 22003:
|
|
1927
|
+
return { flag: false, msg: "你已将对方拉黑,无法进行订阅操作" };
|
|
1928
|
+
case 22013:
|
|
1929
|
+
return { flag: false, msg: "账号已注销,无法进行订阅操作" };
|
|
1930
|
+
case 40061:
|
|
1931
|
+
return {
|
|
1932
|
+
flag: false,
|
|
1933
|
+
msg: "账号不存在,请检查uid输入是否正确或用户是否存在",
|
|
1934
|
+
};
|
|
1935
|
+
case 22001:
|
|
1936
|
+
break; // 订阅对象为自己 无需添加到分组
|
|
1789
1937
|
case 22014: // 已关注订阅对象 无需再次关注
|
|
1790
|
-
case 0: {
|
|
1938
|
+
case 0: {
|
|
1939
|
+
// 执行订阅成功
|
|
1791
1940
|
// 把订阅对象添加到分组中
|
|
1792
1941
|
const copyUserToGroupData = await this.ctx.ba.copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
|
|
1793
1942
|
// 判断是否添加成功
|
|
1794
1943
|
if (copyUserToGroupData.code !== 0) {
|
|
1795
1944
|
// 添加失败
|
|
1796
|
-
return { flag: false, msg:
|
|
1945
|
+
return { flag: false, msg: "添加订阅对象到分组失败,请稍后重试" };
|
|
1797
1946
|
}
|
|
1798
1947
|
}
|
|
1799
1948
|
}
|
|
1800
1949
|
// 订阅成功
|
|
1801
|
-
return { flag: true, msg:
|
|
1950
|
+
return { flag: true, msg: "用户订阅成功" };
|
|
1802
1951
|
}
|
|
1803
1952
|
async loadSubFromConfig(subs) {
|
|
1804
1953
|
for (const sub of subs) {
|
|
1805
1954
|
// 定义Data
|
|
1955
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
1806
1956
|
let data;
|
|
1807
1957
|
// 判断是否需要订阅直播
|
|
1808
1958
|
if (sub.live) {
|
|
1809
1959
|
// 获取用户信息
|
|
1960
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
1810
1961
|
let content;
|
|
1811
1962
|
// 设置重试次数
|
|
1812
1963
|
const attempts = 3;
|
|
@@ -1818,8 +1969,9 @@ class ComRegister {
|
|
|
1818
1969
|
break;
|
|
1819
1970
|
}
|
|
1820
1971
|
catch (e) {
|
|
1821
|
-
this.logger.error(
|
|
1822
|
-
if (i === attempts - 1) {
|
|
1972
|
+
this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
|
|
1973
|
+
if (i === attempts - 1) {
|
|
1974
|
+
// 已尝试三次
|
|
1823
1975
|
// 发送私聊消息并重启服务
|
|
1824
1976
|
return await this.sendPrivateMsgAndStopService();
|
|
1825
1977
|
}
|
|
@@ -1834,11 +1986,12 @@ class ComRegister {
|
|
|
1834
1986
|
// 发送提示
|
|
1835
1987
|
this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
|
|
1836
1988
|
}
|
|
1837
|
-
//
|
|
1989
|
+
//
|
|
1838
1990
|
const liveDetectModeSelector = {
|
|
1839
1991
|
API: async () => {
|
|
1840
1992
|
// 判断是否已开启直播检测
|
|
1841
|
-
if (!this.liveDispose) {
|
|
1993
|
+
if (!this.liveDispose) {
|
|
1994
|
+
// 未开启直播检测
|
|
1842
1995
|
// 开启直播检测并保存销毁函数
|
|
1843
1996
|
this.liveDispose = await this.liveDetectWithAPI();
|
|
1844
1997
|
}
|
|
@@ -1846,7 +1999,7 @@ class ComRegister {
|
|
|
1846
1999
|
WS: async () => {
|
|
1847
2000
|
// 连接到服务器
|
|
1848
2001
|
await this.liveDetectWithListener(data.live_room.roomid, sub.target);
|
|
1849
|
-
}
|
|
2002
|
+
},
|
|
1850
2003
|
};
|
|
1851
2004
|
// 判断是否订阅直播
|
|
1852
2005
|
if (sub.live) {
|
|
@@ -1863,25 +2016,26 @@ class ComRegister {
|
|
|
1863
2016
|
this.subManager.push({
|
|
1864
2017
|
id: +sub.uid,
|
|
1865
2018
|
uid: sub.uid,
|
|
1866
|
-
roomId: sub.live ? data.live_room.roomid :
|
|
2019
|
+
roomId: sub.live ? data.live_room.roomid : "",
|
|
1867
2020
|
target: sub.target,
|
|
1868
|
-
platform:
|
|
2021
|
+
platform: "",
|
|
1869
2022
|
live: sub.live,
|
|
1870
|
-
dynamic: sub.dynamic
|
|
2023
|
+
dynamic: sub.dynamic,
|
|
1871
2024
|
});
|
|
1872
2025
|
}
|
|
1873
2026
|
}
|
|
1874
2027
|
async loadSubFromDatabase() {
|
|
1875
2028
|
// 从数据库中获取数据
|
|
1876
|
-
const subData = await this.ctx.database.get(
|
|
2029
|
+
const subData = await this.ctx.database.get("bilibili", { id: { $gt: 0 } });
|
|
1877
2030
|
// 定义变量:订阅直播数
|
|
1878
2031
|
let liveSubNum = 0;
|
|
1879
2032
|
// 循环遍历
|
|
1880
2033
|
for (const sub of subData) {
|
|
1881
2034
|
// 判断是否存在没有任何订阅的数据
|
|
1882
|
-
if (!sub.dynamic && !sub.live) {
|
|
2035
|
+
if (!sub.dynamic && !sub.live) {
|
|
2036
|
+
// 存在未订阅任何项目的数据
|
|
1883
2037
|
// 删除该条数据
|
|
1884
|
-
this.ctx.database.remove(
|
|
2038
|
+
this.ctx.database.remove("bilibili", { id: sub.id });
|
|
1885
2039
|
// log
|
|
1886
2040
|
this.logger.warn(`UID:${sub.uid} 该条数据没有任何订阅数据,自动取消订阅`);
|
|
1887
2041
|
// 跳过下面的步骤
|
|
@@ -1896,7 +2050,7 @@ class ComRegister {
|
|
|
1896
2050
|
// 发送私聊消息
|
|
1897
2051
|
await this.sendPrivateMsg(`UID:${sub.uid} ${subUserData.msg},自动取消订阅`);
|
|
1898
2052
|
// 删除该条数据
|
|
1899
|
-
await this.ctx.database.remove(
|
|
2053
|
+
await this.ctx.database.remove("bilibili", { id: sub.id });
|
|
1900
2054
|
// 跳过下面的步骤
|
|
1901
2055
|
continue;
|
|
1902
2056
|
}
|
|
@@ -1904,6 +2058,7 @@ class ComRegister {
|
|
|
1904
2058
|
const target = JSON.parse(sub.target);
|
|
1905
2059
|
/* 判断数据库是否被篡改 */
|
|
1906
2060
|
// 获取用户信息
|
|
2061
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
1907
2062
|
let content;
|
|
1908
2063
|
const attempts = 3;
|
|
1909
2064
|
for (let i = 0; i < attempts; i++) {
|
|
@@ -1914,8 +2069,9 @@ class ComRegister {
|
|
|
1914
2069
|
break;
|
|
1915
2070
|
}
|
|
1916
2071
|
catch (e) {
|
|
1917
|
-
this.logger.error(
|
|
1918
|
-
if (i === attempts - 1) {
|
|
2072
|
+
this.logger.error(`getSubFromDatabase() getUserInfo() 发生了错误,错误为:${e.message}`);
|
|
2073
|
+
if (i === attempts - 1) {
|
|
2074
|
+
// 已尝试三次
|
|
1919
2075
|
// 发送私聊消息并重启服务
|
|
1920
2076
|
return await this.sendPrivateMsgAndStopService();
|
|
1921
2077
|
}
|
|
@@ -1926,7 +2082,7 @@ class ComRegister {
|
|
|
1926
2082
|
// 定义函数删除数据和发送提示
|
|
1927
2083
|
const deleteSub = async () => {
|
|
1928
2084
|
// 从数据库删除该条数据
|
|
1929
|
-
await this.ctx.database.remove(
|
|
2085
|
+
await this.ctx.database.remove("bilibili", { id: sub.id });
|
|
1930
2086
|
// 给用户发送提示
|
|
1931
2087
|
await this.sendPrivateMsg(`UID:${sub.uid} 数据库内容被篡改,已取消对该UP主的订阅`);
|
|
1932
2088
|
};
|
|
@@ -1935,11 +2091,9 @@ class ComRegister {
|
|
|
1935
2091
|
switch (content.code) {
|
|
1936
2092
|
case -352:
|
|
1937
2093
|
case -403: {
|
|
1938
|
-
await this.sendPrivateMsg(
|
|
2094
|
+
await this.sendPrivateMsg("你的登录信息已过期,请重新登录Bilibili");
|
|
1939
2095
|
return;
|
|
1940
2096
|
}
|
|
1941
|
-
case -400:
|
|
1942
|
-
case -404:
|
|
1943
2097
|
default: {
|
|
1944
2098
|
await deleteSub();
|
|
1945
2099
|
// PrivateMsg
|
|
@@ -1951,7 +2105,9 @@ class ComRegister {
|
|
|
1951
2105
|
}
|
|
1952
2106
|
}
|
|
1953
2107
|
// 检测房间号是否被篡改
|
|
1954
|
-
if (sub.live &&
|
|
2108
|
+
if (sub.live &&
|
|
2109
|
+
// biome-ignore lint/suspicious/noDoubleEquals: <explanation>
|
|
2110
|
+
(!data.live_room || data.live_room.roomid != sub.room_id)) {
|
|
1955
2111
|
// 房间号被篡改,删除该订阅
|
|
1956
2112
|
await deleteSub();
|
|
1957
2113
|
// log
|
|
@@ -1968,15 +2124,16 @@ class ComRegister {
|
|
|
1968
2124
|
roomId: sub.room_id,
|
|
1969
2125
|
target,
|
|
1970
2126
|
platform: sub.platform,
|
|
1971
|
-
live: sub.live === 1
|
|
1972
|
-
dynamic: sub.dynamic === 1
|
|
1973
|
-
liveDispose: null
|
|
2127
|
+
live: sub.live === 1,
|
|
2128
|
+
dynamic: sub.dynamic === 1,
|
|
2129
|
+
liveDispose: null,
|
|
1974
2130
|
};
|
|
1975
2131
|
// 定义直播模式监测器
|
|
1976
2132
|
const liveDetectModeSelector = {
|
|
1977
2133
|
API: async () => {
|
|
1978
2134
|
// 判断是否已开启直播检测
|
|
1979
|
-
if (!this.liveDispose) {
|
|
2135
|
+
if (!this.liveDispose) {
|
|
2136
|
+
// 未开启直播检测
|
|
1980
2137
|
// 开启直播检测并保存销毁函数
|
|
1981
2138
|
this.liveDispose = await this.liveDetectWithAPI();
|
|
1982
2139
|
}
|
|
@@ -1997,7 +2154,7 @@ class ComRegister {
|
|
|
1997
2154
|
// 订阅直播,开始循环检测
|
|
1998
2155
|
await this.liveDetectWithListener(sub.room_id, target);
|
|
1999
2156
|
}
|
|
2000
|
-
}
|
|
2157
|
+
},
|
|
2001
2158
|
};
|
|
2002
2159
|
// 判断是否订阅直播
|
|
2003
2160
|
if (sub.live) {
|
|
@@ -2010,7 +2167,7 @@ class ComRegister {
|
|
|
2010
2167
|
}
|
|
2011
2168
|
checkIfDynamicDetectIsNeeded() {
|
|
2012
2169
|
// 检查是否有订阅对象需要动态监测
|
|
2013
|
-
if (this.subManager.some(sub => sub.dynamic))
|
|
2170
|
+
if (this.subManager.some((sub) => sub.dynamic))
|
|
2014
2171
|
this.enableDynamicDetect();
|
|
2015
2172
|
}
|
|
2016
2173
|
enableDynamicDetect() {
|
|
@@ -2032,7 +2189,7 @@ class ComRegister {
|
|
|
2032
2189
|
// 从管理对象中移除
|
|
2033
2190
|
this.subManager.splice(index, 1);
|
|
2034
2191
|
// 从数据库中删除
|
|
2035
|
-
this.ctx.database.remove(
|
|
2192
|
+
this.ctx.database.remove("bilibili", [this.subManager[index].id]);
|
|
2036
2193
|
// num--
|
|
2037
2194
|
this.num--;
|
|
2038
2195
|
// 判断是否还存在订阅了动态的对象,不存在则停止动态监测
|
|
@@ -2040,25 +2197,26 @@ class ComRegister {
|
|
|
2040
2197
|
};
|
|
2041
2198
|
try {
|
|
2042
2199
|
switch (type) {
|
|
2043
|
-
case 0: {
|
|
2200
|
+
case 0: {
|
|
2201
|
+
// 取消Live订阅
|
|
2044
2202
|
// 获取订阅对象所在的索引
|
|
2045
|
-
const index = this.subManager.findIndex(sub => sub.roomId === id);
|
|
2203
|
+
const index = this.subManager.findIndex((sub) => sub.roomId === id);
|
|
2046
2204
|
// 获取订阅对象
|
|
2047
|
-
const sub = this.subManager.find(sub => sub.roomId === id);
|
|
2205
|
+
const sub = this.subManager.find((sub) => sub.roomId === id);
|
|
2048
2206
|
// 判断是否存在订阅对象
|
|
2049
2207
|
if (!sub) {
|
|
2050
|
-
msg =
|
|
2208
|
+
msg = "未订阅该用户,无需取消订阅";
|
|
2051
2209
|
return msg;
|
|
2052
2210
|
}
|
|
2053
2211
|
// 取消订阅
|
|
2054
2212
|
sub.live = false;
|
|
2055
2213
|
// 判断直播检测方式
|
|
2056
2214
|
switch (this.config.liveDetectMode) {
|
|
2057
|
-
case
|
|
2058
|
-
msg =
|
|
2215
|
+
case "API": {
|
|
2216
|
+
msg = "请手动删除订阅,并重启插件";
|
|
2059
2217
|
break;
|
|
2060
2218
|
}
|
|
2061
|
-
case
|
|
2219
|
+
case "WS": {
|
|
2062
2220
|
// 取消直播监听
|
|
2063
2221
|
this.ctx.bl.closeListener(sub.roomId);
|
|
2064
2222
|
}
|
|
@@ -2067,23 +2225,26 @@ class ComRegister {
|
|
|
2067
2225
|
if (checkIfNoSubExist(sub)) {
|
|
2068
2226
|
// 从管理对象中移除
|
|
2069
2227
|
removeSub(index);
|
|
2070
|
-
return
|
|
2228
|
+
return "已取消订阅该用户";
|
|
2071
2229
|
}
|
|
2072
2230
|
// 更新数据库
|
|
2073
|
-
this.ctx.database.upsert(
|
|
2231
|
+
this.ctx.database.upsert("bilibili", [
|
|
2232
|
+
{
|
|
2074
2233
|
id: +`${sub.id}`,
|
|
2075
|
-
live: 0
|
|
2076
|
-
}
|
|
2077
|
-
|
|
2234
|
+
live: 0,
|
|
2235
|
+
},
|
|
2236
|
+
]);
|
|
2237
|
+
return "已取消订阅Live";
|
|
2078
2238
|
}
|
|
2079
|
-
case 1: {
|
|
2239
|
+
case 1: {
|
|
2240
|
+
// 取消Dynamic订阅
|
|
2080
2241
|
// 获取订阅对象所在的索引
|
|
2081
|
-
const index = this.subManager.findIndex(sub => sub.uid === id);
|
|
2242
|
+
const index = this.subManager.findIndex((sub) => sub.uid === id);
|
|
2082
2243
|
// 获取订阅对象
|
|
2083
|
-
const sub = this.subManager.find(sub => sub.uid === id);
|
|
2244
|
+
const sub = this.subManager.find((sub) => sub.uid === id);
|
|
2084
2245
|
// 判断是否存在订阅对象
|
|
2085
2246
|
if (!sub) {
|
|
2086
|
-
msg =
|
|
2247
|
+
msg = "未订阅该用户,无需取消订阅";
|
|
2087
2248
|
return msg;
|
|
2088
2249
|
}
|
|
2089
2250
|
// 取消订阅
|
|
@@ -2094,14 +2255,16 @@ class ComRegister {
|
|
|
2094
2255
|
if (checkIfNoSubExist(sub)) {
|
|
2095
2256
|
// 从管理对象中移除
|
|
2096
2257
|
removeSub(index);
|
|
2097
|
-
return
|
|
2258
|
+
return "已取消订阅该用户";
|
|
2098
2259
|
}
|
|
2099
2260
|
// 更新数据库
|
|
2100
|
-
this.ctx.database.upsert(
|
|
2261
|
+
this.ctx.database.upsert("bilibili", [
|
|
2262
|
+
{
|
|
2101
2263
|
id: sub.id,
|
|
2102
|
-
dynamic: 0
|
|
2103
|
-
}
|
|
2104
|
-
|
|
2264
|
+
dynamic: 0,
|
|
2265
|
+
},
|
|
2266
|
+
]);
|
|
2267
|
+
return "已取消订阅Dynamic";
|
|
2105
2268
|
}
|
|
2106
2269
|
}
|
|
2107
2270
|
}
|
|
@@ -2111,14 +2274,16 @@ class ComRegister {
|
|
|
2111
2274
|
}
|
|
2112
2275
|
}
|
|
2113
2276
|
checkIfUserIsTheLastOneWhoSubDyn() {
|
|
2114
|
-
if (this.dynamicDispose && !this.subManager.some(sub => sub.dynamic)) {
|
|
2277
|
+
if (this.dynamicDispose && !this.subManager.some((sub) => sub.dynamic)) {
|
|
2115
2278
|
// 停止动态监测
|
|
2116
2279
|
this.dynamicDispose();
|
|
2117
2280
|
this.dynamicDispose = null;
|
|
2118
2281
|
}
|
|
2119
2282
|
}
|
|
2120
2283
|
unsubAll(uid) {
|
|
2121
|
-
this.subManager
|
|
2284
|
+
this.subManager
|
|
2285
|
+
.filter((sub) => sub.uid === uid)
|
|
2286
|
+
.map(async (sub, i) => {
|
|
2122
2287
|
// 判断是否还存在订阅了动态的对象,不存在则停止动态监测
|
|
2123
2288
|
this.checkIfUserIsTheLastOneWhoSubDyn();
|
|
2124
2289
|
switch (this.config.liveDetectMode) {
|
|
@@ -2131,7 +2296,9 @@ class ComRegister {
|
|
|
2131
2296
|
}
|
|
2132
2297
|
}
|
|
2133
2298
|
// 从数据库中删除订阅
|
|
2134
|
-
await this.ctx.database.remove(
|
|
2299
|
+
await this.ctx.database.remove("bilibili", {
|
|
2300
|
+
uid: this.subManager[i].uid,
|
|
2301
|
+
});
|
|
2135
2302
|
// 将该订阅对象从订阅管理对象中移除
|
|
2136
2303
|
this.subManager.splice(i, 1);
|
|
2137
2304
|
// id--
|
|
@@ -2143,9 +2310,11 @@ class ComRegister {
|
|
|
2143
2310
|
});
|
|
2144
2311
|
}
|
|
2145
2312
|
async checkIfIsLogin() {
|
|
2146
|
-
if ((await this.ctx.database.get(
|
|
2313
|
+
if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
|
|
2314
|
+
// 数据库中有数据
|
|
2147
2315
|
// 检查cookie中是否有值
|
|
2148
|
-
if (this.ctx.ba.getCookies() !==
|
|
2316
|
+
if (this.ctx.ba.getCookies() !== "[]") {
|
|
2317
|
+
// 有值说明已登录
|
|
2149
2318
|
return true;
|
|
2150
2319
|
}
|
|
2151
2320
|
}
|
|
@@ -2155,31 +2324,33 @@ class ComRegister {
|
|
|
2155
2324
|
(function (ComRegister) {
|
|
2156
2325
|
ComRegister.Config = koishi_1.Schema.object({
|
|
2157
2326
|
sub: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
2158
|
-
uid: koishi_1.Schema.string().description(
|
|
2159
|
-
dynamic: koishi_1.Schema.boolean().description(
|
|
2160
|
-
live: koishi_1.Schema.boolean().description(
|
|
2327
|
+
uid: koishi_1.Schema.string().description("订阅用户UID"),
|
|
2328
|
+
dynamic: koishi_1.Schema.boolean().description("是否订阅用户动态"),
|
|
2329
|
+
live: koishi_1.Schema.boolean().description("是否订阅用户直播"),
|
|
2161
2330
|
target: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
2162
2331
|
channelIdArr: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
2163
|
-
channelId: koishi_1.Schema.string().description(
|
|
2164
|
-
dynamic: koishi_1.Schema.boolean().description(
|
|
2165
|
-
live: koishi_1.Schema.boolean().description(
|
|
2166
|
-
liveGuardBuy: koishi_1.Schema.boolean().description(
|
|
2167
|
-
atAll: koishi_1.Schema.boolean().description(
|
|
2168
|
-
})).description(
|
|
2169
|
-
platform: koishi_1.Schema.string().description(
|
|
2170
|
-
})).description(
|
|
2171
|
-
}))
|
|
2332
|
+
channelId: koishi_1.Schema.string().description("频道/群组号"),
|
|
2333
|
+
dynamic: koishi_1.Schema.boolean().description("该频道/群组是否推送动态信息"),
|
|
2334
|
+
live: koishi_1.Schema.boolean().description("该频道/群组是否推送直播通知"),
|
|
2335
|
+
liveGuardBuy: koishi_1.Schema.boolean().description("该频道/群组是否推送弹幕消息"),
|
|
2336
|
+
atAll: koishi_1.Schema.boolean().description("推送开播通知时是否艾特全体成员"),
|
|
2337
|
+
})).description("频道/群组信息"),
|
|
2338
|
+
platform: koishi_1.Schema.string().description("推送平台"),
|
|
2339
|
+
})).description("订阅用户需要发送的频道/群组信息"),
|
|
2340
|
+
}))
|
|
2341
|
+
.role("table")
|
|
2342
|
+
.description("手动输入订阅信息,方便自定义订阅内容,这里的订阅内容不会存入数据库。uid: 订阅用户UID,dynamic: 是否需要订阅动态,live: 是否需要订阅直播"),
|
|
2172
2343
|
master: koishi_1.Schema.object({
|
|
2173
2344
|
enable: koishi_1.Schema.boolean(),
|
|
2174
2345
|
platform: koishi_1.Schema.string(),
|
|
2175
2346
|
masterAccount: koishi_1.Schema.string(),
|
|
2176
|
-
masterAccountGuildId: koishi_1.Schema.string()
|
|
2347
|
+
masterAccountGuildId: koishi_1.Schema.string(),
|
|
2177
2348
|
}),
|
|
2178
2349
|
unlockSubLimits: koishi_1.Schema.boolean().required(),
|
|
2179
2350
|
automaticResend: koishi_1.Schema.boolean().required(),
|
|
2180
2351
|
liveDetectMode: koishi_1.Schema.union([
|
|
2181
|
-
koishi_1.Schema.const(
|
|
2182
|
-
koishi_1.Schema.const(
|
|
2352
|
+
koishi_1.Schema.const("API"),
|
|
2353
|
+
koishi_1.Schema.const("WS"),
|
|
2183
2354
|
]).required(),
|
|
2184
2355
|
restartPush: koishi_1.Schema.boolean().required(),
|
|
2185
2356
|
pushTime: koishi_1.Schema.number().required(),
|
|
@@ -2195,7 +2366,7 @@ class ComRegister {
|
|
|
2195
2366
|
regex: koishi_1.Schema.string(),
|
|
2196
2367
|
keywords: koishi_1.Schema.array(String),
|
|
2197
2368
|
}),
|
|
2198
|
-
dynamicDebugMode: koishi_1.Schema.boolean().required()
|
|
2369
|
+
dynamicDebugMode: koishi_1.Schema.boolean().required(),
|
|
2199
2370
|
});
|
|
2200
2371
|
})(ComRegister || (ComRegister = {}));
|
|
2201
2372
|
exports.default = ComRegister;
|