koishi-plugin-bilibili-notify 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/comRegister.d.ts +9 -13
- package/lib/comRegister.js +197 -88
- package/lib/database.d.ts +2 -0
- package/lib/database.js +3 -1
- package/package.json +1 -1
package/lib/comRegister.d.ts
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
import { Context, Logger, Schema, Session } from "koishi";
|
|
1
|
+
import { Bot, Context, Logger, Schema, Session } from "koishi";
|
|
2
2
|
declare class ComRegister {
|
|
3
3
|
static inject: string[];
|
|
4
4
|
logger: Logger;
|
|
5
5
|
config: ComRegister.Config;
|
|
6
|
-
|
|
7
|
-
sub: {
|
|
8
|
-
id: number;
|
|
9
|
-
uid: string;
|
|
10
|
-
room_id: string;
|
|
11
|
-
dynamic: number;
|
|
12
|
-
video: 1;
|
|
13
|
-
live: number;
|
|
14
|
-
time: Date;
|
|
15
|
-
};
|
|
6
|
+
num: number;
|
|
16
7
|
subManager: {
|
|
8
|
+
id: number;
|
|
17
9
|
uid: string;
|
|
18
10
|
roomId: string;
|
|
11
|
+
targetId: string;
|
|
19
12
|
live: boolean;
|
|
20
13
|
dynamic: boolean;
|
|
21
14
|
liveDispose: Function;
|
|
22
15
|
dynamicDispose: Function;
|
|
23
16
|
}[];
|
|
17
|
+
qqBot: Bot<Context>;
|
|
18
|
+
qqguildBot: Bot<Context>;
|
|
24
19
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
25
|
-
dynamicDetect(ctx: Context,
|
|
26
|
-
liveDetect(ctx: Context,
|
|
20
|
+
dynamicDetect(ctx: Context, bot: Bot<Context>, groupId: string, uid: string): () => Promise<"账号未登录" | "未知错误">;
|
|
21
|
+
liveDetect(ctx: Context, bot: Bot<Context>, groupId: string, roomId: string): () => Promise<void>;
|
|
27
22
|
checkIfNeedSub(comNeed: boolean, subType: string, session: Session, data?: any): Promise<boolean>;
|
|
23
|
+
getSubFromDatabase(ctx: Context): Promise<void>;
|
|
28
24
|
}
|
|
29
25
|
declare namespace ComRegister {
|
|
30
26
|
interface Config {
|
package/lib/comRegister.js
CHANGED
|
@@ -16,12 +16,20 @@ class ComRegister {
|
|
|
16
16
|
static inject = ['biliAPI', 'gimg', 'wbi', 'database'];
|
|
17
17
|
logger;
|
|
18
18
|
config;
|
|
19
|
-
|
|
20
|
-
sub;
|
|
19
|
+
num = 0;
|
|
21
20
|
subManager = [];
|
|
21
|
+
// QQ群机器人
|
|
22
|
+
qqBot;
|
|
23
|
+
// QQ频道机器人
|
|
24
|
+
qqguildBot;
|
|
22
25
|
constructor(ctx, config) {
|
|
23
26
|
this.logger = ctx.logger('commandRegister');
|
|
24
27
|
this.config = config;
|
|
28
|
+
// 拿到QQ群机器人
|
|
29
|
+
this.qqBot = ctx.bots[ctx.bots.findIndex(bot => bot.platform === 'qq')];
|
|
30
|
+
// 拿到QQ频道机器人
|
|
31
|
+
this.qqguildBot = ctx.bots[ctx.bots.findIndex(bot => bot.platform === 'qqguild')];
|
|
32
|
+
this.getSubFromDatabase(ctx);
|
|
25
33
|
ctx.command('test')
|
|
26
34
|
.subcommand('.cookies')
|
|
27
35
|
.usage('测试指令,用于测试从数据库读取cookies')
|
|
@@ -77,6 +85,20 @@ class ComRegister {
|
|
|
77
85
|
.action(() => {
|
|
78
86
|
console.log(this.subManager);
|
|
79
87
|
});
|
|
88
|
+
ctx.command('test')
|
|
89
|
+
.subcommand('.group')
|
|
90
|
+
.usage('查看session groupId')
|
|
91
|
+
.example('test group')
|
|
92
|
+
.action(({ session }) => {
|
|
93
|
+
console.log(session.event.channel);
|
|
94
|
+
});
|
|
95
|
+
ctx.command('test')
|
|
96
|
+
.subcommand('.session')
|
|
97
|
+
.usage('查看seesion')
|
|
98
|
+
.example('test session')
|
|
99
|
+
.action(({ session }) => {
|
|
100
|
+
console.log(session);
|
|
101
|
+
});
|
|
80
102
|
ctx.command('bili', 'bili-notify插件相关指令')
|
|
81
103
|
.subcommand('.login', '登录B站之后才可以进行之后的操作')
|
|
82
104
|
.usage('使用二维码登录,登录B站之后才可以进行之后的操作')
|
|
@@ -135,24 +157,30 @@ class ComRegister {
|
|
|
135
157
|
.subcommand('.unsub <uid:string>')
|
|
136
158
|
.usage('取消订阅')
|
|
137
159
|
.example('bili unsub 用户UID')
|
|
138
|
-
.action(({ session }, uid) => {
|
|
160
|
+
.action(async ({ session }, uid) => {
|
|
161
|
+
this.logger.info('调用bili.unsub指令');
|
|
162
|
+
// 若用户UID为空则直接返回
|
|
139
163
|
if (!uid)
|
|
140
164
|
return '用户UID不能为空';
|
|
141
165
|
// 定义是否存在
|
|
142
|
-
let exist
|
|
143
|
-
this.subManager.
|
|
166
|
+
let exist;
|
|
167
|
+
await Promise.all(this.subManager.map(async (sub, i) => {
|
|
144
168
|
if (sub.uid === uid) {
|
|
145
169
|
// 执行dispose方法,销毁定时器
|
|
146
170
|
this.subManager[i].dynamicDispose();
|
|
147
171
|
this.subManager[i].liveDispose();
|
|
172
|
+
// 从数据库中删除订阅
|
|
173
|
+
await ctx.database.remove('bilibili', { uid: this.subManager[i].uid });
|
|
148
174
|
// 将该订阅对象从订阅管理对象中移除
|
|
149
175
|
this.subManager = this.subManager.splice(i, i);
|
|
176
|
+
// id--
|
|
177
|
+
this.num--;
|
|
150
178
|
// 发送成功通知
|
|
151
179
|
session.send('已取消订阅该用户');
|
|
152
180
|
// 将存在flag设置为true
|
|
153
181
|
exist = true;
|
|
154
182
|
}
|
|
155
|
-
});
|
|
183
|
+
}));
|
|
156
184
|
// 未订阅该用户,无需取消订阅
|
|
157
185
|
!exist && session.send('未订阅该用户,无需取消订阅');
|
|
158
186
|
});
|
|
@@ -169,23 +197,23 @@ class ComRegister {
|
|
|
169
197
|
table && session.send(table);
|
|
170
198
|
});
|
|
171
199
|
ctx.command('bili')
|
|
172
|
-
.subcommand('.sub <mid:string> [
|
|
200
|
+
.subcommand('.sub <mid:string> [guildId:string]')
|
|
173
201
|
.option('live', '-l')
|
|
174
202
|
.option('dynamic', '-d')
|
|
175
203
|
.usage('订阅用户动态和直播通知,若需要订阅直播请加上-l,需要订阅动态则加上-d。若没有加任何参数,之后会向你单独询问,<>中为必选参数,[]中为可选参数,目标群号若不填,则默认为当前群聊')
|
|
176
204
|
.example('bili sub 用户uid 目标QQ群号(暂不支持) -l -d')
|
|
177
|
-
.action(async ({ session, options }, mid,
|
|
205
|
+
.action(async ({ session, options }, mid, guildId) => {
|
|
178
206
|
this.logger.info('调用bili.sub指令');
|
|
207
|
+
// 如果订阅人数超过三个则直接返回
|
|
208
|
+
if (this.num >= 3)
|
|
209
|
+
return '目前最多只能订阅三个人';
|
|
179
210
|
// 检查必选参数是否有值
|
|
180
|
-
if (mid
|
|
211
|
+
if (!mid)
|
|
181
212
|
return '请输入用户uid';
|
|
182
|
-
}
|
|
183
213
|
// 判断要订阅的用户是否已经存在于订阅管理对象中
|
|
184
|
-
this.subManager && this.subManager.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return session.send('已订阅该用户,请勿重复订阅');
|
|
188
|
-
});
|
|
214
|
+
if (this.subManager && this.subManager.some(sub => sub.uid === mid)) {
|
|
215
|
+
return '已订阅该用户,请勿重复订阅';
|
|
216
|
+
}
|
|
189
217
|
// 定义是否需要直播通知,动态订阅,视频推送
|
|
190
218
|
let liveMsg, dynamicMsg;
|
|
191
219
|
// 获取用户信息
|
|
@@ -216,99 +244,142 @@ class ComRegister {
|
|
|
216
244
|
liveMsg = await this.checkIfNeedSub(options.live, '直播', session, data);
|
|
217
245
|
// 判断是否需要订阅动态
|
|
218
246
|
dynamicMsg = await this.checkIfNeedSub(options.dynamic, '动态', session);
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
247
|
+
// 判断是哪个平台
|
|
248
|
+
let platform;
|
|
249
|
+
if (!guildId) { // 没有输入群号,默认当前聊天环境
|
|
250
|
+
switch (session.event.platform) {
|
|
251
|
+
case 'qqguild':
|
|
252
|
+
guildId = session.event.channel.id;
|
|
253
|
+
break;
|
|
254
|
+
case 'qq':
|
|
255
|
+
guildId = session.event.guild.id;
|
|
256
|
+
break;
|
|
257
|
+
default: return '暂不支持该平台';
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
// 定义Bot
|
|
261
|
+
let bot;
|
|
262
|
+
// 判断是哪个聊天平台
|
|
263
|
+
switch (session.event.platform) {
|
|
264
|
+
case 'qqguild': {
|
|
265
|
+
bot = this.qqguildBot;
|
|
266
|
+
platform = 'qqguild';
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
case 'qq': {
|
|
270
|
+
bot = this.qqBot;
|
|
271
|
+
platform = 'qq';
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
default: return '暂不支持该平台';
|
|
275
|
+
}
|
|
276
|
+
// 保存到数据库中
|
|
277
|
+
const sub = await ctx.database.create('bilibili', {
|
|
222
278
|
uid: mid,
|
|
223
279
|
room_id: data.live_room.roomid.toString(),
|
|
224
280
|
dynamic: dynamicMsg ? 1 : 0,
|
|
225
281
|
video: 1,
|
|
226
282
|
live: liveMsg ? 1 : 0,
|
|
283
|
+
targetId: guildId,
|
|
284
|
+
platform,
|
|
227
285
|
time: new Date()
|
|
228
|
-
};
|
|
229
|
-
//
|
|
230
|
-
|
|
231
|
-
// 让id自增
|
|
232
|
-
this.id++;
|
|
286
|
+
});
|
|
287
|
+
// 订阅数+1
|
|
288
|
+
this.num++;
|
|
233
289
|
// 开始订阅
|
|
234
290
|
// 保存新订阅对象
|
|
235
291
|
this.subManager.push({
|
|
292
|
+
id: sub.id,
|
|
236
293
|
uid: mid,
|
|
294
|
+
targetId: guildId,
|
|
237
295
|
roomId: data.live_room.roomid.toString(),
|
|
238
296
|
live: liveMsg,
|
|
239
297
|
dynamic: dynamicMsg,
|
|
240
298
|
liveDispose: null,
|
|
241
299
|
dynamicDispose: null
|
|
242
300
|
});
|
|
301
|
+
// 获取用户信息
|
|
302
|
+
const { data: userData } = await ctx.biliAPI.getMasterInfo(sub.uid);
|
|
243
303
|
// 需要订阅直播
|
|
244
|
-
if (liveMsg)
|
|
245
|
-
await session.execute(`bili live ${data.live_room.roomid}`);
|
|
304
|
+
if (liveMsg) {
|
|
305
|
+
await session.execute(`bili live ${data.live_room.roomid} ${guildId} -b ${platform}`);
|
|
306
|
+
// 发送订阅消息通知
|
|
307
|
+
await bot.sendMessage(sub.targetId, `订阅${userData.info.uname}直播通知`);
|
|
308
|
+
}
|
|
246
309
|
// 需要订阅动态
|
|
247
|
-
if (dynamicMsg)
|
|
248
|
-
await session.execute(`bili dynamic ${mid}`);
|
|
249
|
-
|
|
310
|
+
if (dynamicMsg) {
|
|
311
|
+
await session.execute(`bili dynamic ${mid} ${guildId} -b ${platform}`);
|
|
312
|
+
// 发送订阅消息通知
|
|
313
|
+
await bot.sendMessage(sub.targetId, `订阅${userData.info.uname}动态通知`);
|
|
314
|
+
}
|
|
250
315
|
});
|
|
251
316
|
ctx.command('bili')
|
|
252
317
|
.subcommand('.dynamic <uid:string>')
|
|
318
|
+
.option('bot', '-b <type:string>')
|
|
253
319
|
.usage('订阅用户动态推送')
|
|
254
320
|
.example('bili dynamic 1')
|
|
255
|
-
.action(async ({ session }, uid) => {
|
|
321
|
+
.action(async ({ session, options }, uid, guildId) => {
|
|
256
322
|
this.logger.info('调用bili.dynamic指令');
|
|
257
323
|
// 如果uid为空则返回
|
|
258
|
-
if (!uid)
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
// 定义订阅对象索引
|
|
263
|
-
let index;
|
|
264
|
-
// 定义要订阅的对象是否存在于订阅管理对象中
|
|
265
|
-
let exist;
|
|
324
|
+
if (!uid)
|
|
325
|
+
return '用户uid不能为空';
|
|
326
|
+
if (!options.bot)
|
|
327
|
+
return '非法调用';
|
|
266
328
|
// 保存到订阅管理对象
|
|
267
|
-
this.subManager.
|
|
268
|
-
if (sub.uid === uid) {
|
|
269
|
-
exist = true;
|
|
270
|
-
index = i;
|
|
271
|
-
}
|
|
272
|
-
});
|
|
329
|
+
const index = this.subManager.findIndex(sub => sub.uid === uid);
|
|
273
330
|
// 不存在则直接返回
|
|
274
|
-
if (
|
|
331
|
+
if (index === -1) {
|
|
275
332
|
session.send('请勿直接调用该指令');
|
|
276
333
|
return;
|
|
277
334
|
}
|
|
335
|
+
// 获取对应Bot
|
|
336
|
+
let bot;
|
|
337
|
+
switch (options.bot) {
|
|
338
|
+
case 'qq':
|
|
339
|
+
bot = this.qqBot;
|
|
340
|
+
break;
|
|
341
|
+
case 'qqguild':
|
|
342
|
+
bot = this.qqguildBot;
|
|
343
|
+
break;
|
|
344
|
+
default: return '非法调用';
|
|
345
|
+
}
|
|
278
346
|
// 开始循环检测
|
|
279
|
-
const dispose = ctx.setInterval(this.dynamicDetect(ctx,
|
|
347
|
+
const dispose = ctx.setInterval(this.dynamicDetect(ctx, bot, guildId, uid), 60000);
|
|
280
348
|
// 将销毁函数保存到订阅管理对象
|
|
281
349
|
this.subManager[index].dynamicDispose = dispose;
|
|
282
350
|
});
|
|
283
351
|
ctx.command('bili')
|
|
284
|
-
.subcommand('.live <roomId:string>')
|
|
352
|
+
.subcommand('.live <roomId:string> <guildId:string>')
|
|
353
|
+
.option('bot', '-b <type:string>')
|
|
285
354
|
.usage('订阅主播开播通知')
|
|
286
355
|
.example('bili live 732')
|
|
287
|
-
.action(async ({ session }, roomId) => {
|
|
356
|
+
.action(async ({ session, options }, roomId, guildId) => {
|
|
288
357
|
this.logger.info('调用bili.live指令');
|
|
289
358
|
// 如果room_id为空则返回
|
|
290
|
-
if (!roomId)
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
// 定义要订阅的对象是否存在于订阅管理对象中
|
|
297
|
-
let exist;
|
|
359
|
+
if (!roomId)
|
|
360
|
+
return '订阅主播房间号不能为空';
|
|
361
|
+
if (!guildId)
|
|
362
|
+
return '目标群组或频道不能为空';
|
|
363
|
+
if (!options.bot)
|
|
364
|
+
return '非法调用';
|
|
298
365
|
// 保存到订阅管理对象
|
|
299
|
-
this.subManager.
|
|
300
|
-
if (sub.roomId === roomId) {
|
|
301
|
-
exist = true;
|
|
302
|
-
index = i;
|
|
303
|
-
}
|
|
304
|
-
});
|
|
366
|
+
const index = this.subManager.findIndex(sub => sub.roomId === roomId);
|
|
305
367
|
// 要订阅的对象不在订阅管理对象中,直接返回
|
|
306
|
-
if (
|
|
307
|
-
|
|
308
|
-
|
|
368
|
+
if (index === -1)
|
|
369
|
+
return '请勿直接调用该指令';
|
|
370
|
+
// 获取对应Bot
|
|
371
|
+
let bot;
|
|
372
|
+
switch (options.bot) {
|
|
373
|
+
case 'qq':
|
|
374
|
+
bot = this.qqBot;
|
|
375
|
+
break;
|
|
376
|
+
case 'qqguild':
|
|
377
|
+
bot = this.qqguildBot;
|
|
378
|
+
break;
|
|
379
|
+
default: return '非法调用';
|
|
309
380
|
}
|
|
310
381
|
// 开始循环检测
|
|
311
|
-
const dispose = ctx.setInterval(this.liveDetect(ctx,
|
|
382
|
+
const dispose = ctx.setInterval(this.liveDetect(ctx, bot, guildId, roomId), 5000);
|
|
312
383
|
// 保存销毁函数
|
|
313
384
|
this.subManager[index].liveDispose = dispose;
|
|
314
385
|
});
|
|
@@ -340,16 +411,12 @@ class ComRegister {
|
|
|
340
411
|
session.send(string);
|
|
341
412
|
});
|
|
342
413
|
}
|
|
343
|
-
dynamicDetect(ctx,
|
|
414
|
+
dynamicDetect(ctx, bot, groupId, uid) {
|
|
344
415
|
let firstSubscription = true;
|
|
345
416
|
let timePoint;
|
|
346
417
|
return async () => {
|
|
347
|
-
//
|
|
418
|
+
// 第一次订阅判断
|
|
348
419
|
if (firstSubscription) {
|
|
349
|
-
// 获取用户信息
|
|
350
|
-
const { data: userData } = await ctx.biliAPI.getMasterInfo(uid);
|
|
351
|
-
// 发送订阅消息通知
|
|
352
|
-
session.send(`订阅${userData.info.uname}动态通知!`);
|
|
353
420
|
// 设置第一次的时间点
|
|
354
421
|
timePoint = Date.now();
|
|
355
422
|
// 设置第一次为false
|
|
@@ -391,33 +458,28 @@ class ComRegister {
|
|
|
391
458
|
}
|
|
392
459
|
// 推送该条动态
|
|
393
460
|
const [pic] = await ctx.gimg.generateDynamicImg(items[num]);
|
|
394
|
-
|
|
461
|
+
await bot.sendMessage(groupId, pic);
|
|
395
462
|
}
|
|
396
463
|
}
|
|
397
464
|
};
|
|
398
465
|
}
|
|
399
|
-
liveDetect(ctx,
|
|
466
|
+
liveDetect(ctx, bot, groupId, roomId) {
|
|
400
467
|
let firstSubscription = true;
|
|
401
468
|
let timer = 0;
|
|
402
469
|
let open = false;
|
|
403
470
|
let liveTime;
|
|
404
471
|
let uData;
|
|
405
472
|
return async () => {
|
|
406
|
-
// Test code
|
|
407
|
-
/* console.log('===========================>');
|
|
408
|
-
console.log(timer);
|
|
409
|
-
console.log(open);
|
|
410
|
-
console.log('===========================>'); */
|
|
411
473
|
// 发送请求检测直播状态
|
|
412
474
|
const content = await ctx.biliAPI.getLiveRoomInfo(roomId);
|
|
413
475
|
const { data } = content;
|
|
414
476
|
// B站出问题了
|
|
415
477
|
if (content.code !== 0) {
|
|
416
478
|
if (content.msg === '未找到该房间') {
|
|
417
|
-
|
|
479
|
+
await bot.sendMessage(groupId, '未找到该房间!');
|
|
418
480
|
}
|
|
419
481
|
else {
|
|
420
|
-
|
|
482
|
+
await bot.sendMessage(groupId, '未知错误,请呼叫管理员检查问题!');
|
|
421
483
|
}
|
|
422
484
|
// dispose
|
|
423
485
|
return;
|
|
@@ -428,15 +490,14 @@ class ComRegister {
|
|
|
428
490
|
const { data: userData } = await ctx.biliAPI.getMasterInfo(data.uid);
|
|
429
491
|
// 主播信息不会变,请求一次即可
|
|
430
492
|
uData = userData;
|
|
431
|
-
//
|
|
432
|
-
session.send(`订阅${userData.info.uname}直播通知`);
|
|
493
|
+
// 判断直播状态
|
|
433
494
|
if (data.live_status === 1) { // 当前正在直播
|
|
434
|
-
// 改变开播状态
|
|
435
|
-
open = true;
|
|
436
495
|
// 推送直播信息
|
|
437
|
-
await
|
|
496
|
+
await bot.sendMessage(groupId, await ctx
|
|
438
497
|
.gimg
|
|
439
498
|
.generateLiveImg(data, uData, LiveType.LiveBroadcast));
|
|
499
|
+
// 改变开播状态
|
|
500
|
+
open = true;
|
|
440
501
|
} // 未开播,直接返回
|
|
441
502
|
return;
|
|
442
503
|
}
|
|
@@ -450,7 +511,7 @@ class ComRegister {
|
|
|
450
511
|
// 下播了将定时器清零
|
|
451
512
|
timer = 0;
|
|
452
513
|
// 发送下播通知
|
|
453
|
-
|
|
514
|
+
bot.sendMessage(groupId, `${uData.info.uname}下播啦,本次直播了${ctx.gimg.getTimeDifference(liveTime)}`);
|
|
454
515
|
}
|
|
455
516
|
// 未进循环,还未开播,继续循环
|
|
456
517
|
break;
|
|
@@ -466,7 +527,7 @@ class ComRegister {
|
|
|
466
527
|
// 主播信息不会变,开播时刷新一次即可
|
|
467
528
|
uData = userData;
|
|
468
529
|
// 发送直播通知
|
|
469
|
-
await
|
|
530
|
+
await bot.sendMessage(groupId, await ctx.gimg.generateLiveImg(data, uData, LiveType.StartBroadcasting));
|
|
470
531
|
}
|
|
471
532
|
else { // 还在直播
|
|
472
533
|
if (this.config.pushTime > 0) {
|
|
@@ -476,7 +537,7 @@ class ComRegister {
|
|
|
476
537
|
// 到时间重新计时
|
|
477
538
|
timer = 0;
|
|
478
539
|
// 发送状态信息
|
|
479
|
-
|
|
540
|
+
bot.sendMessage(groupId, await ctx
|
|
480
541
|
.gimg
|
|
481
542
|
.generateLiveImg(data, uData, LiveType.LiveBroadcast));
|
|
482
543
|
}
|
|
@@ -521,6 +582,54 @@ class ComRegister {
|
|
|
521
582
|
}
|
|
522
583
|
}
|
|
523
584
|
}
|
|
585
|
+
async getSubFromDatabase(ctx) {
|
|
586
|
+
// 从数据库中获取数据
|
|
587
|
+
const subData = await ctx.database.get('bilibili', { id: { $gt: 0 } });
|
|
588
|
+
// 设定订阅数量
|
|
589
|
+
this.num = subData.length;
|
|
590
|
+
// 如果订阅数量超过三个则被非法修改数据库
|
|
591
|
+
// 向管理员发送重新订阅通知
|
|
592
|
+
if (this.num > 3)
|
|
593
|
+
return;
|
|
594
|
+
// 定义Bot
|
|
595
|
+
let bot;
|
|
596
|
+
// 循环遍历
|
|
597
|
+
subData.forEach(sub => {
|
|
598
|
+
// 拿到对应bot
|
|
599
|
+
switch (sub.platform) {
|
|
600
|
+
case 'qq': bot = this.qqBot;
|
|
601
|
+
case 'qqguild': bot = this.qqguildBot;
|
|
602
|
+
}
|
|
603
|
+
// 构建订阅对象
|
|
604
|
+
let subManagerItem = {
|
|
605
|
+
id: sub.id,
|
|
606
|
+
uid: sub.uid,
|
|
607
|
+
roomId: sub.room_id,
|
|
608
|
+
targetId: sub.targetId,
|
|
609
|
+
live: +sub.live === 1 ? true : false,
|
|
610
|
+
dynamic: +sub.dynamic === 1 ? true : false,
|
|
611
|
+
liveDispose: null,
|
|
612
|
+
dynamicDispose: null
|
|
613
|
+
};
|
|
614
|
+
// 判断需要订阅的服务
|
|
615
|
+
if (sub.dynamic) { // 需要订阅动态
|
|
616
|
+
// 开始循环检测
|
|
617
|
+
const dispose = ctx.setInterval(this.dynamicDetect(ctx, bot, sub.targetId, sub.uid), 60000);
|
|
618
|
+
// 保存销毁函数
|
|
619
|
+
subManagerItem.dynamicDispose = dispose;
|
|
620
|
+
}
|
|
621
|
+
if (sub.live) { // 需要订阅动态
|
|
622
|
+
// 开始循环检测
|
|
623
|
+
const dispose = ctx.setInterval(this.liveDetect(ctx, bot, sub.targetId, sub.room_id), 5000);
|
|
624
|
+
// 保存销毁函数
|
|
625
|
+
subManagerItem.liveDispose = dispose;
|
|
626
|
+
}
|
|
627
|
+
// 保存新订阅对象
|
|
628
|
+
this.subManager.push(subManagerItem);
|
|
629
|
+
// 发送订阅成功通知
|
|
630
|
+
bot.sendMessage(sub.targetId, '重新加载测试发送');
|
|
631
|
+
});
|
|
632
|
+
}
|
|
524
633
|
}
|
|
525
634
|
(function (ComRegister) {
|
|
526
635
|
ComRegister.Config = koishi_1.Schema.object({
|
package/lib/database.d.ts
CHANGED
package/lib/database.js
CHANGED