koishi-plugin-bilibili-notify 1.0.8 → 1.0.10-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/biliAPI.js +9 -1
- package/lib/comRegister.d.ts +2 -0
- package/lib/comRegister.js +73 -60
- package/lib/generateImg.d.ts +7 -0
- package/lib/generateImg.js +53 -25
- package/lib/index.d.ts +7 -1
- package/lib/index.js +42 -8
- package/package.json +1 -1
- package/readme.md +2 -0
package/lib/biliAPI.js
CHANGED
|
@@ -138,7 +138,15 @@ class BiliAPI extends koishi_1.Service {
|
|
|
138
138
|
disposeNotifier() { this.loginNotifier && this.loginNotifier.dispose(); }
|
|
139
139
|
createNewClient() {
|
|
140
140
|
this.jar = new tough_cookie_1.CookieJar();
|
|
141
|
-
this.client = (0, axios_cookiejar_support_1.wrapper)(axios_1.default.create({
|
|
141
|
+
this.client = (0, axios_cookiejar_support_1.wrapper)(axios_1.default.create({
|
|
142
|
+
jar: this.jar,
|
|
143
|
+
headers: {
|
|
144
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
145
|
+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
|
146
|
+
'Origin': 'https://www.bilibili.com',
|
|
147
|
+
'Referer': 'https://www.bilibili.com/'
|
|
148
|
+
}
|
|
149
|
+
}));
|
|
142
150
|
}
|
|
143
151
|
getCookies() {
|
|
144
152
|
let cookies;
|
package/lib/comRegister.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ declare class ComRegister {
|
|
|
18
18
|
}[];
|
|
19
19
|
qqBot: Bot<Context>;
|
|
20
20
|
qqguildBot: Bot<Context>;
|
|
21
|
+
oneBot: Bot<Context>;
|
|
21
22
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
22
23
|
dynamicDetect(ctx: Context, bot: Bot<Context>, guildId: string, uid: string): () => Promise<void | string[]>;
|
|
23
24
|
liveDetect(ctx: Context, bot: Bot<Context>, guildId: string, roomId: string): () => Promise<void>;
|
|
@@ -30,6 +31,7 @@ declare class ComRegister {
|
|
|
30
31
|
}
|
|
31
32
|
declare namespace ComRegister {
|
|
32
33
|
interface Config {
|
|
34
|
+
unlockSubLimits: boolean;
|
|
33
35
|
pushTime: number;
|
|
34
36
|
liveLoopTime: number;
|
|
35
37
|
dynamicLoopTime: number;
|
package/lib/comRegister.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("@satorijs/element/jsx-runtime");
|
|
6
7
|
const koishi_1 = require("koishi");
|
|
7
8
|
// 导入qrcode
|
|
8
9
|
const qrcode_1 = __importDefault(require("qrcode"));
|
|
@@ -23,23 +24,28 @@ class ComRegister {
|
|
|
23
24
|
qqBot;
|
|
24
25
|
// QQ频道机器人
|
|
25
26
|
qqguildBot;
|
|
27
|
+
// OneBot机器人
|
|
28
|
+
oneBot;
|
|
26
29
|
constructor(ctx, config) {
|
|
27
30
|
this.logger = ctx.logger('commandRegister');
|
|
28
31
|
this.config = config;
|
|
29
32
|
// 拿到QQ群机器人
|
|
30
|
-
this.qqBot = ctx.bots
|
|
33
|
+
this.qqBot = ctx.bots.find(bot => bot.platform === 'qq');
|
|
31
34
|
// 拿到QQ频道机器人
|
|
32
|
-
this.qqguildBot = ctx.bots
|
|
35
|
+
this.qqguildBot = ctx.bots.find(bot => bot.platform === 'qqguild');
|
|
36
|
+
// 拿到OneBot机器人
|
|
37
|
+
this.oneBot = ctx.bots.find(bot => bot.platform === 'onebot');
|
|
33
38
|
// 从数据库获取订阅
|
|
34
39
|
this.getSubFromDatabase(ctx);
|
|
35
|
-
/* ctx.command('test', { hidden: true, permissions: ['authority:5'] })
|
|
36
|
-
|
|
40
|
+
/* const testCom = ctx.command('test', { hidden: true, permissions: ['authority:5'] })
|
|
41
|
+
|
|
42
|
+
testCom.subcommand('.cookies')
|
|
37
43
|
.usage('测试指令,用于测试从数据库读取cookies')
|
|
38
44
|
.action(async () => {
|
|
39
45
|
await ctx.biliAPI.loadCookiesFromDatabase()
|
|
40
46
|
})
|
|
41
47
|
|
|
42
|
-
|
|
48
|
+
testCom
|
|
43
49
|
.subcommand('.my')
|
|
44
50
|
.usage('测试指令,用于测试获取自己信息')
|
|
45
51
|
.example('test.my')
|
|
@@ -48,7 +54,7 @@ class ComRegister {
|
|
|
48
54
|
console.log(content);
|
|
49
55
|
})
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
testCom
|
|
52
58
|
.subcommand('.user <mid:string>')
|
|
53
59
|
.usage('测试指令,用于测试获取用户信息')
|
|
54
60
|
.example('test.user 用户UID')
|
|
@@ -57,7 +63,7 @@ class ComRegister {
|
|
|
57
63
|
console.log(content);
|
|
58
64
|
})
|
|
59
65
|
|
|
60
|
-
|
|
66
|
+
testCom
|
|
61
67
|
.subcommand('.time')
|
|
62
68
|
.usage('测试时间接口')
|
|
63
69
|
.example('test.time')
|
|
@@ -65,7 +71,7 @@ class ComRegister {
|
|
|
65
71
|
session.send(await ctx.biliAPI.getTimeNow())
|
|
66
72
|
})
|
|
67
73
|
|
|
68
|
-
|
|
74
|
+
testCom
|
|
69
75
|
.subcommand('.exist')
|
|
70
76
|
.usage('测试写法')
|
|
71
77
|
.example('test.exist')
|
|
@@ -74,7 +80,7 @@ class ComRegister {
|
|
|
74
80
|
console.log(num && `Hello World`);
|
|
75
81
|
})
|
|
76
82
|
|
|
77
|
-
|
|
83
|
+
testCom
|
|
78
84
|
.subcommand('.gimg <uid:string> <index:number>')
|
|
79
85
|
.usage('测试图片生成')
|
|
80
86
|
.example('test.gimg')
|
|
@@ -89,7 +95,7 @@ class ComRegister {
|
|
|
89
95
|
await session.send(h.image(buffer, 'image/png'))
|
|
90
96
|
})
|
|
91
97
|
|
|
92
|
-
|
|
98
|
+
testCom
|
|
93
99
|
.subcommand('.group')
|
|
94
100
|
.usage('查看session groupId')
|
|
95
101
|
.example('test group')
|
|
@@ -97,7 +103,7 @@ class ComRegister {
|
|
|
97
103
|
console.log(session.event.channel);
|
|
98
104
|
})
|
|
99
105
|
|
|
100
|
-
|
|
106
|
+
testCom
|
|
101
107
|
.subcommand('.session')
|
|
102
108
|
.usage('查看seesion')
|
|
103
109
|
.example('test session')
|
|
@@ -105,15 +111,15 @@ class ComRegister {
|
|
|
105
111
|
console.log(session);
|
|
106
112
|
})
|
|
107
113
|
|
|
108
|
-
|
|
114
|
+
testCom
|
|
109
115
|
.subcommand('.utc')
|
|
110
116
|
.usage('获取当前UTC+8 Unix时间戳')
|
|
111
117
|
.example('test utc')
|
|
112
118
|
.action(async ({ session }) => {
|
|
113
119
|
session.send((await ctx.biliAPI.getServerUTCTime()).toString())
|
|
114
120
|
}) */
|
|
115
|
-
ctx.command('bili', 'bili-notify插件相关指令', { permissions: ['authority:3'] })
|
|
116
|
-
|
|
121
|
+
const biliCom = ctx.command('bili', 'bili-notify插件相关指令', { permissions: ['authority:3'] });
|
|
122
|
+
biliCom.subcommand('.login', '登录B站之后才可以进行之后的操作')
|
|
117
123
|
.usage('使用二维码登录,登录B站之后才可以进行之后的操作')
|
|
118
124
|
.example('bili login')
|
|
119
125
|
.action(async ({ session }) => {
|
|
@@ -188,7 +194,7 @@ class ComRegister {
|
|
|
188
194
|
}
|
|
189
195
|
}, 1000);
|
|
190
196
|
});
|
|
191
|
-
|
|
197
|
+
biliCom
|
|
192
198
|
.subcommand('.unsub <uid:string>', '取消订阅UP主动态、直播或全部')
|
|
193
199
|
.usage('取消订阅,加-l为取消直播订阅,加-d为取消动态订阅,什么都不加则为全部取消')
|
|
194
200
|
.option('live', '-l')
|
|
@@ -238,7 +244,7 @@ class ComRegister {
|
|
|
238
244
|
// 未订阅该用户,无需取消订阅
|
|
239
245
|
!exist && session.send('未订阅该用户,无需取消订阅');
|
|
240
246
|
});
|
|
241
|
-
|
|
247
|
+
biliCom
|
|
242
248
|
.subcommand('.show', '展示订阅对象')
|
|
243
249
|
.usage('展示订阅对象')
|
|
244
250
|
.example('bili show')
|
|
@@ -246,7 +252,7 @@ class ComRegister {
|
|
|
246
252
|
const subTable = this.subShow();
|
|
247
253
|
return subTable;
|
|
248
254
|
});
|
|
249
|
-
|
|
255
|
+
biliCom
|
|
250
256
|
.subcommand('.sub <mid:string> [guildId:string]', '订阅用户动态和直播通知')
|
|
251
257
|
.option('live', '-l')
|
|
252
258
|
.option('dynamic', '-d')
|
|
@@ -260,7 +266,7 @@ class ComRegister {
|
|
|
260
266
|
return '请使用指令bili login登录后再进行订阅操作';
|
|
261
267
|
}
|
|
262
268
|
// 如果订阅人数超过三个则直接返回
|
|
263
|
-
if (this.num >= 3)
|
|
269
|
+
if (!config.unlockSubLimits && this.num >= 3)
|
|
264
270
|
return '目前最多只能订阅三个人';
|
|
265
271
|
// 检查必选参数是否有值
|
|
266
272
|
if (!mid)
|
|
@@ -309,11 +315,11 @@ class ComRegister {
|
|
|
309
315
|
if (!liveMsg && !dynamicMsg) {
|
|
310
316
|
return '您未订阅该UP的任何消息';
|
|
311
317
|
}
|
|
312
|
-
//
|
|
313
|
-
let platform;
|
|
318
|
+
// 设置群号
|
|
314
319
|
if (!guildId) { // 没有输入群号,默认当前聊天环境
|
|
315
320
|
switch (session.event.platform) {
|
|
316
321
|
case 'qqguild':
|
|
322
|
+
case 'onebot':
|
|
317
323
|
guildId = session.event.channel.id;
|
|
318
324
|
break;
|
|
319
325
|
case 'qq':
|
|
@@ -322,21 +328,8 @@ class ComRegister {
|
|
|
322
328
|
default: return '暂不支持该平台';
|
|
323
329
|
}
|
|
324
330
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
// 判断是哪个聊天平台
|
|
328
|
-
switch (session.event.platform) {
|
|
329
|
-
case 'qqguild': {
|
|
330
|
-
bot = this.qqguildBot;
|
|
331
|
-
platform = 'qqguild';
|
|
332
|
-
break;
|
|
333
|
-
}
|
|
334
|
-
case 'qq': {
|
|
335
|
-
bot = this.qqBot;
|
|
336
|
-
platform = 'qq';
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
default: return '暂不支持该平台';
|
|
331
|
+
else {
|
|
332
|
+
return '暂不支持群号发送!';
|
|
340
333
|
}
|
|
341
334
|
// 保存到数据库中
|
|
342
335
|
const sub = await ctx.database.create('bilibili', {
|
|
@@ -346,7 +339,7 @@ class ComRegister {
|
|
|
346
339
|
video: 1,
|
|
347
340
|
live: liveMsg ? 1 : 0,
|
|
348
341
|
targetId: guildId,
|
|
349
|
-
platform,
|
|
342
|
+
platform: session.event.platform,
|
|
350
343
|
time: new Date()
|
|
351
344
|
});
|
|
352
345
|
// 订阅数+1
|
|
@@ -374,27 +367,20 @@ class ComRegister {
|
|
|
374
367
|
}
|
|
375
368
|
// 需要订阅直播
|
|
376
369
|
if (liveMsg) {
|
|
377
|
-
await session.execute(`bili live ${data.live_room.roomid} ${guildId} -b ${platform}`);
|
|
370
|
+
await session.execute(`bili live ${data.live_room.roomid} ${guildId} -b ${session.event.platform}`);
|
|
378
371
|
// 发送订阅消息通知
|
|
379
|
-
await
|
|
372
|
+
await session.send(`订阅${userData.info.uname}直播通知`);
|
|
380
373
|
}
|
|
381
374
|
// 需要订阅动态
|
|
382
375
|
if (dynamicMsg) {
|
|
383
|
-
await session.execute(`bili dynamic ${mid} ${guildId} -b ${platform}`);
|
|
376
|
+
await session.execute(`bili dynamic ${mid} ${guildId} -b ${session.event.platform}`);
|
|
384
377
|
// 发送订阅消息通知
|
|
385
|
-
await
|
|
378
|
+
await session.send(`订阅${userData.info.uname}动态通知`);
|
|
386
379
|
}
|
|
387
380
|
// 新增订阅展示到控制台
|
|
388
|
-
|
|
389
|
-
const subTable = this.subShow();
|
|
390
|
-
// 判断之前是否存在Notifier
|
|
391
|
-
this.subNotifier && this.subNotifier.dispose();
|
|
392
|
-
this.subNotifier = ctx.notifier.create({
|
|
393
|
-
type: 'primary',
|
|
394
|
-
content: subTable
|
|
395
|
-
});
|
|
381
|
+
this.updateSubNotifier(ctx);
|
|
396
382
|
});
|
|
397
|
-
|
|
383
|
+
biliCom
|
|
398
384
|
.subcommand('.dynamic <uid:string> <guildId:string>', '订阅用户动态推送', { hidden: true })
|
|
399
385
|
.option('bot', '-b <type:string>')
|
|
400
386
|
.usage('订阅用户动态推送')
|
|
@@ -424,6 +410,9 @@ class ComRegister {
|
|
|
424
410
|
case 'qqguild':
|
|
425
411
|
bot = this.qqguildBot;
|
|
426
412
|
break;
|
|
413
|
+
case 'onebot':
|
|
414
|
+
bot = this.oneBot;
|
|
415
|
+
break;
|
|
427
416
|
default: return '非法调用';
|
|
428
417
|
}
|
|
429
418
|
// 开始循环检测
|
|
@@ -431,7 +420,7 @@ class ComRegister {
|
|
|
431
420
|
// 将销毁函数保存到订阅管理对象
|
|
432
421
|
this.subManager[index].dynamicDispose = dispose;
|
|
433
422
|
});
|
|
434
|
-
|
|
423
|
+
biliCom
|
|
435
424
|
.subcommand('.live <roomId:string> <guildId:string>', '订阅主播开播通知', { hidden: true })
|
|
436
425
|
.option('bot', '-b <type:string>')
|
|
437
426
|
.usage('订阅主播开播通知')
|
|
@@ -459,6 +448,9 @@ class ComRegister {
|
|
|
459
448
|
case 'qqguild':
|
|
460
449
|
bot = this.qqguildBot;
|
|
461
450
|
break;
|
|
451
|
+
case 'onebot':
|
|
452
|
+
bot = this.oneBot;
|
|
453
|
+
break;
|
|
462
454
|
default: return '非法调用';
|
|
463
455
|
}
|
|
464
456
|
// 开始循环检测
|
|
@@ -466,7 +458,7 @@ class ComRegister {
|
|
|
466
458
|
// 保存销毁函数
|
|
467
459
|
this.subManager[index].liveDispose = dispose;
|
|
468
460
|
});
|
|
469
|
-
|
|
461
|
+
biliCom
|
|
470
462
|
.subcommand('.status <roomId:string>', '查询主播当前直播状态', { hidden: true })
|
|
471
463
|
.usage('查询主播当前直播状态')
|
|
472
464
|
.example('bili status 732')
|
|
@@ -588,6 +580,10 @@ class ComRegister {
|
|
|
588
580
|
// 直播开播动态,不做处理
|
|
589
581
|
if (e.message === '直播开播动态,不做处理')
|
|
590
582
|
break;
|
|
583
|
+
if (e.message === '出现关键词,屏蔽该动态') {
|
|
584
|
+
await bot.sendMessage(guildId, `UID:${uid} 发布了一条含有屏蔽关键字的动态`);
|
|
585
|
+
break;
|
|
586
|
+
}
|
|
591
587
|
}
|
|
592
588
|
// 如果pic存在,则直接返回pic
|
|
593
589
|
if (pic)
|
|
@@ -806,12 +802,15 @@ class ComRegister {
|
|
|
806
802
|
// 更新控制台提示
|
|
807
803
|
this.subNotifier && this.subNotifier.dispose();
|
|
808
804
|
// 获取subTable
|
|
809
|
-
|
|
805
|
+
let subTableArray = this.subShow().split('\n');
|
|
806
|
+
subTableArray.splice(subTableArray.length - 1, 1);
|
|
807
|
+
// 定义Table
|
|
808
|
+
let table = (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("ul", { children: subTableArray.map(str => ((0, jsx_runtime_1.jsx)("li", { children: str }))) }) });
|
|
809
|
+
/* subTableArray.forEach(str => {
|
|
810
|
+
table +=
|
|
811
|
+
}) */
|
|
810
812
|
// 设置更新后的提示
|
|
811
|
-
this.subNotifier = ctx.notifier.create(
|
|
812
|
-
type: 'primary',
|
|
813
|
-
content: subTable
|
|
814
|
-
});
|
|
813
|
+
this.subNotifier = ctx.notifier.create(table);
|
|
815
814
|
}
|
|
816
815
|
async getSubFromDatabase(ctx) {
|
|
817
816
|
// 如果未登录,则直接返回
|
|
@@ -826,10 +825,10 @@ class ComRegister {
|
|
|
826
825
|
this.num = subData.length;
|
|
827
826
|
// 如果订阅数量超过三个则被非法修改数据库
|
|
828
827
|
// 在控制台提示重新订阅
|
|
829
|
-
if (this.num > 3) {
|
|
828
|
+
if (!this.config.unlockSubLimits && this.num > 3) {
|
|
830
829
|
ctx.notifier.create({
|
|
831
830
|
type: 'danger',
|
|
832
|
-
content: '
|
|
831
|
+
content: '您未解锁订阅限制,且订阅数大于3人,请您手动删除bilibili表中多余的数据后重启本插件'
|
|
833
832
|
});
|
|
834
833
|
return;
|
|
835
834
|
}
|
|
@@ -846,8 +845,21 @@ class ComRegister {
|
|
|
846
845
|
}
|
|
847
846
|
// 拿到对应bot
|
|
848
847
|
switch (sub.platform) {
|
|
849
|
-
case 'qq':
|
|
850
|
-
|
|
848
|
+
case 'qq':
|
|
849
|
+
bot = this.qqBot;
|
|
850
|
+
break;
|
|
851
|
+
case 'qqguild':
|
|
852
|
+
bot = this.qqguildBot;
|
|
853
|
+
break;
|
|
854
|
+
case 'onebot':
|
|
855
|
+
bot = this.oneBot;
|
|
856
|
+
break;
|
|
857
|
+
default: {
|
|
858
|
+
// 本条数据被篡改,删除该条订阅
|
|
859
|
+
ctx.database.remove('bilibili', { id: sub.id });
|
|
860
|
+
// 继续下个循环
|
|
861
|
+
continue;
|
|
862
|
+
}
|
|
851
863
|
}
|
|
852
864
|
// 判断数据库是否被篡改
|
|
853
865
|
// 获取用户信息
|
|
@@ -999,6 +1011,7 @@ class ComRegister {
|
|
|
999
1011
|
}
|
|
1000
1012
|
(function (ComRegister) {
|
|
1001
1013
|
ComRegister.Config = koishi_1.Schema.object({
|
|
1014
|
+
unlockSubLimits: koishi_1.Schema.boolean().required(),
|
|
1002
1015
|
pushTime: koishi_1.Schema.number().required(),
|
|
1003
1016
|
liveLoopTime: koishi_1.Schema.number().default(10),
|
|
1004
1017
|
dynamicLoopTime: koishi_1.Schema.number().default(60),
|
package/lib/generateImg.d.ts
CHANGED
|
@@ -33,6 +33,13 @@ declare class GenerateImg extends Service {
|
|
|
33
33
|
declare namespace GenerateImg {
|
|
34
34
|
interface Config {
|
|
35
35
|
renderType: number;
|
|
36
|
+
filter: {
|
|
37
|
+
enable: boolean;
|
|
38
|
+
regex: string;
|
|
39
|
+
keywords: Array<string>;
|
|
40
|
+
filter: boolean;
|
|
41
|
+
};
|
|
42
|
+
removeBorder: boolean;
|
|
36
43
|
cardColorStart: string;
|
|
37
44
|
cardColorEnd: string;
|
|
38
45
|
font: string;
|
package/lib/generateImg.js
CHANGED
|
@@ -91,9 +91,13 @@ class GenerateImg extends koishi_1.Service {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
.base-plate {
|
|
94
|
+
${this.config.removeBorder ? `
|
|
95
|
+
width: 740px;
|
|
96
|
+
` : `
|
|
94
97
|
width: 704px;
|
|
95
|
-
height: auto;
|
|
96
98
|
margin: 20px auto;
|
|
99
|
+
`}
|
|
100
|
+
height: auto;
|
|
97
101
|
border-radius: 10px;
|
|
98
102
|
background-color: #fff;
|
|
99
103
|
}
|
|
@@ -228,24 +232,37 @@ class GenerateImg extends koishi_1.Service {
|
|
|
228
232
|
const like = module_stat.like.count;
|
|
229
233
|
// TOPIC
|
|
230
234
|
const topic = data.modules.module_dynamic.topic ? data.modules.module_dynamic.topic.name : '';
|
|
231
|
-
async
|
|
235
|
+
const getDynamicMajor = async (dynamicMajorData, forward) => {
|
|
232
236
|
// 定义返回值
|
|
233
237
|
let main = '';
|
|
234
238
|
let link = '';
|
|
235
239
|
// 定义forward类型返回值
|
|
236
240
|
let forwardInfo;
|
|
237
241
|
// 最基本的图文处理
|
|
238
|
-
|
|
242
|
+
const basicDynamic = () => {
|
|
239
243
|
const module_dynamic = dynamicMajorData.modules.module_dynamic;
|
|
240
244
|
if (module_dynamic.desc) {
|
|
241
245
|
const richText = module_dynamic.desc.rich_text_nodes.reduce((accumulator, currentValue) => {
|
|
242
246
|
if (currentValue.emoji) {
|
|
243
|
-
return accumulator + `<img style="width:
|
|
247
|
+
return accumulator + `<img style="width:28px; height:28px;" src="${currentValue.emoji.icon_url}"/>`;
|
|
244
248
|
}
|
|
245
249
|
else {
|
|
246
250
|
return accumulator + currentValue.text;
|
|
247
251
|
}
|
|
248
252
|
}, '');
|
|
253
|
+
// 关键字和正则屏蔽
|
|
254
|
+
if (this.config.filter.enable) { // 开启关键字和正则屏蔽
|
|
255
|
+
if (this.config.filter.regex) { // 正则屏蔽
|
|
256
|
+
const reg = new RegExp(this.config.filter.regex);
|
|
257
|
+
if (reg.test(richText))
|
|
258
|
+
throw new Error('出现关键词,屏蔽该动态');
|
|
259
|
+
}
|
|
260
|
+
if (this.config.filter.keywords.length !== 0 &&
|
|
261
|
+
this.config.filter.keywords
|
|
262
|
+
.some(keyword => richText.includes(keyword))) {
|
|
263
|
+
throw new Error('出现关键词,屏蔽该动态');
|
|
264
|
+
}
|
|
265
|
+
}
|
|
249
266
|
// 查找\n
|
|
250
267
|
const text = richText.replace(/\n/g, '<br>');
|
|
251
268
|
// 拼接字符串
|
|
@@ -279,7 +296,7 @@ class GenerateImg extends koishi_1.Service {
|
|
|
279
296
|
</div>
|
|
280
297
|
`;
|
|
281
298
|
}
|
|
282
|
-
}
|
|
299
|
+
};
|
|
283
300
|
// 判断动态类型
|
|
284
301
|
switch (dynamicMajorData.type) {
|
|
285
302
|
case DYNAMIC_TYPE_WORD:
|
|
@@ -493,7 +510,7 @@ class GenerateImg extends koishi_1.Service {
|
|
|
493
510
|
default: return [`${upName}发布了一条我无法识别的动态,请自行查看`, ''];
|
|
494
511
|
}
|
|
495
512
|
return [main, link, forwardInfo];
|
|
496
|
-
}
|
|
513
|
+
};
|
|
497
514
|
// 获取动态主要内容
|
|
498
515
|
const [main, link] = await getDynamicMajor(data, false);
|
|
499
516
|
// 加载字体
|
|
@@ -513,6 +530,7 @@ class GenerateImg extends koishi_1.Service {
|
|
|
513
530
|
* {
|
|
514
531
|
margin: 0;
|
|
515
532
|
padding: 0;
|
|
533
|
+
box-sizing: border-box;
|
|
516
534
|
font-family: "${this.config.font}", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
|
|
517
535
|
}
|
|
518
536
|
|
|
@@ -539,9 +557,13 @@ class GenerateImg extends koishi_1.Service {
|
|
|
539
557
|
}
|
|
540
558
|
|
|
541
559
|
.base-plate {
|
|
560
|
+
${this.config.removeBorder ? `
|
|
561
|
+
width: 740px;
|
|
562
|
+
` : `
|
|
542
563
|
width: 704px;
|
|
543
|
-
height: auto;
|
|
544
564
|
margin: 20px auto;
|
|
565
|
+
`}
|
|
566
|
+
height: auto;
|
|
545
567
|
border-radius: 10px;
|
|
546
568
|
background-color: #fff;
|
|
547
569
|
}
|
|
@@ -552,10 +574,9 @@ class GenerateImg extends koishi_1.Service {
|
|
|
552
574
|
}
|
|
553
575
|
|
|
554
576
|
.card .anchor-avatar {
|
|
555
|
-
|
|
556
|
-
max-width: 50px;
|
|
577
|
+
max-width: 70px;
|
|
557
578
|
/* 设置最大宽度为容器宽度的100% */
|
|
558
|
-
max-height:
|
|
579
|
+
max-height: 70px;
|
|
559
580
|
/* 设置最大高度为容器高度的90% */
|
|
560
581
|
margin-right: 20px;
|
|
561
582
|
border-radius: 10px;
|
|
@@ -575,15 +596,15 @@ class GenerateImg extends koishi_1.Service {
|
|
|
575
596
|
display: flex;
|
|
576
597
|
flex-direction: column;
|
|
577
598
|
justify-content: space-between;
|
|
578
|
-
height:
|
|
599
|
+
height: 70px;
|
|
579
600
|
}
|
|
580
601
|
|
|
581
602
|
.card .up-info .up-name {
|
|
582
|
-
font-size:
|
|
603
|
+
font-size: 27px;
|
|
583
604
|
}
|
|
584
605
|
|
|
585
606
|
.card .pub-time {
|
|
586
|
-
font-size:
|
|
607
|
+
font-size: 20px;
|
|
587
608
|
color: grey;
|
|
588
609
|
}
|
|
589
610
|
|
|
@@ -593,12 +614,9 @@ class GenerateImg extends koishi_1.Service {
|
|
|
593
614
|
|
|
594
615
|
.card .dress-up {
|
|
595
616
|
position: relative;
|
|
596
|
-
max-width: 110px;
|
|
597
|
-
max-height: 34px;
|
|
598
617
|
/* background-image: url('${dynamicCardUrl}');
|
|
599
618
|
background-size: cover; */
|
|
600
|
-
font-size:
|
|
601
|
-
line-height: 33px;
|
|
619
|
+
font-size: 17px;
|
|
602
620
|
}
|
|
603
621
|
|
|
604
622
|
.card .dress-up img {
|
|
@@ -609,20 +627,23 @@ class GenerateImg extends koishi_1.Service {
|
|
|
609
627
|
.card .dress-up span {
|
|
610
628
|
position: absolute;
|
|
611
629
|
color: ${dynamicCardColor};
|
|
612
|
-
right:
|
|
613
|
-
top:
|
|
630
|
+
right: 67px;
|
|
631
|
+
top: 24px;
|
|
614
632
|
}
|
|
615
633
|
|
|
616
634
|
.card .card-topic {
|
|
617
635
|
display: flex;
|
|
618
636
|
align-items: center;
|
|
619
637
|
margin-top: 10px;
|
|
638
|
+
font-size: 20px;
|
|
620
639
|
color: #008AC5;
|
|
621
640
|
gap: 3px;
|
|
622
641
|
}
|
|
623
642
|
|
|
624
643
|
.card .card-details {
|
|
644
|
+
margin-top: 5px;
|
|
625
645
|
margin-bottom: 15px;
|
|
646
|
+
font-size: 22px;
|
|
626
647
|
width: 90%;
|
|
627
648
|
}
|
|
628
649
|
|
|
@@ -749,8 +770,8 @@ class GenerateImg extends koishi_1.Service {
|
|
|
749
770
|
}
|
|
750
771
|
|
|
751
772
|
.card .card-forward {
|
|
752
|
-
margin: 0 -15px 0 -
|
|
753
|
-
padding: 12px 15px 14px
|
|
773
|
+
margin: 0 -15px 0 -105px;
|
|
774
|
+
padding: 12px 15px 14px 105px;
|
|
754
775
|
background-color: #F6F7F8;
|
|
755
776
|
}
|
|
756
777
|
|
|
@@ -758,18 +779,18 @@ class GenerateImg extends koishi_1.Service {
|
|
|
758
779
|
display: flex;
|
|
759
780
|
align-items: center;
|
|
760
781
|
gap: 5px;
|
|
761
|
-
height:
|
|
782
|
+
height: 35px;
|
|
762
783
|
}
|
|
763
784
|
|
|
764
785
|
.forward-userinfo img {
|
|
765
|
-
width:
|
|
766
|
-
height:
|
|
786
|
+
width: 25px;
|
|
787
|
+
height: 25px;
|
|
767
788
|
border-radius: 50%;
|
|
768
789
|
}
|
|
769
790
|
|
|
770
791
|
.forward-userinfo span {
|
|
771
792
|
color: #61666D;
|
|
772
|
-
font-size:
|
|
793
|
+
font-size: 20px;
|
|
773
794
|
}
|
|
774
795
|
|
|
775
796
|
.card .card-reserve {
|
|
@@ -986,6 +1007,13 @@ class GenerateImg extends koishi_1.Service {
|
|
|
986
1007
|
(function (GenerateImg) {
|
|
987
1008
|
GenerateImg.Config = koishi_1.Schema.object({
|
|
988
1009
|
renderType: koishi_1.Schema.number(),
|
|
1010
|
+
filter: koishi_1.Schema.object({
|
|
1011
|
+
enable: koishi_1.Schema.boolean(),
|
|
1012
|
+
regex: koishi_1.Schema.string(),
|
|
1013
|
+
keywords: koishi_1.Schema.array(String),
|
|
1014
|
+
filter: koishi_1.Schema.boolean()
|
|
1015
|
+
}),
|
|
1016
|
+
removeBorder: koishi_1.Schema.boolean(),
|
|
989
1017
|
cardColorStart: koishi_1.Schema.string(),
|
|
990
1018
|
cardColorEnd: koishi_1.Schema.string(),
|
|
991
1019
|
font: koishi_1.Schema.string()
|
package/lib/index.d.ts
CHANGED
|
@@ -2,14 +2,20 @@ import { Context, Schema } from 'koishi';
|
|
|
2
2
|
export declare const inject: string[];
|
|
3
3
|
export declare const name = "bilibili-notify";
|
|
4
4
|
export interface Config {
|
|
5
|
+
require: {};
|
|
6
|
+
key: string;
|
|
7
|
+
basicSettings: {};
|
|
8
|
+
unlockSubLimits: boolean;
|
|
5
9
|
pushTime: number;
|
|
6
10
|
dynamicCheckNumber: number;
|
|
7
11
|
dynamicLoopTime: '1分钟' | '2分钟' | '3分钟' | '5分钟';
|
|
8
12
|
renderType: 'render' | 'page';
|
|
13
|
+
filter: {};
|
|
14
|
+
style: {};
|
|
15
|
+
removeBorder: boolean;
|
|
9
16
|
cardColorStart: string;
|
|
10
17
|
cardColorEnd: string;
|
|
11
18
|
font: string;
|
|
12
|
-
key: string;
|
|
13
19
|
}
|
|
14
20
|
export declare const Config: Schema<Config>;
|
|
15
21
|
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -39,6 +39,16 @@ const biliAPI_1 = __importDefault(require("./biliAPI"));
|
|
|
39
39
|
exports.inject = ['puppeteer', 'database', 'notifier'];
|
|
40
40
|
exports.name = 'bilibili-notify';
|
|
41
41
|
exports.Config = koishi_1.Schema.object({
|
|
42
|
+
require: koishi_1.Schema.object({}).description('必填设置'),
|
|
43
|
+
key: koishi_1.Schema.string()
|
|
44
|
+
.pattern(/^[0-9a-f]{32}$/)
|
|
45
|
+
.role('secret')
|
|
46
|
+
.required()
|
|
47
|
+
.description('请输入一个32位小写字母的十六进制密钥(例如:9b8db7ae562b9864efefe06289cc5530),使用此密钥将你的B站登录信息存储在数据库中,请一定保存好此密钥。如果你忘记了此密钥,必须重新登录。你可以自行生成,或到这个网站生成:https://www.sexauth.com/'),
|
|
48
|
+
basicSettings: koishi_1.Schema.object({}).description('基本设置'),
|
|
49
|
+
unlockSubLimits: koishi_1.Schema.boolean()
|
|
50
|
+
.default(false)
|
|
51
|
+
.description('解锁3个订阅限制,默认只允许订阅3位UP主。订阅过多用户可能有导致IP暂时被封禁的风险'),
|
|
42
52
|
pushTime: koishi_1.Schema.number()
|
|
43
53
|
.min(0)
|
|
44
54
|
.max(12)
|
|
@@ -60,6 +70,27 @@ exports.Config = koishi_1.Schema.object({
|
|
|
60
70
|
.role('')
|
|
61
71
|
.default('render')
|
|
62
72
|
.description('渲染类型,默认为render模式,渲染速度更快,但会出现乱码问题,若出现乱码问题,请切换到page模式。若使用自定义字体,建议选择render模式'),
|
|
73
|
+
filter: koishi_1.Schema.intersect([
|
|
74
|
+
koishi_1.Schema.object({
|
|
75
|
+
enable: koishi_1.Schema.boolean()
|
|
76
|
+
.default(false)
|
|
77
|
+
.description('是否开启动态关键字屏蔽功能')
|
|
78
|
+
}).description('屏蔽设置'),
|
|
79
|
+
koishi_1.Schema.union([
|
|
80
|
+
koishi_1.Schema.object({
|
|
81
|
+
enable: koishi_1.Schema.const(true).required(),
|
|
82
|
+
regex: koishi_1.Schema.string()
|
|
83
|
+
.description('正则表达式屏蔽'),
|
|
84
|
+
keywords: koishi_1.Schema.array(String)
|
|
85
|
+
.description('关键字屏蔽,一个关键字为一项')
|
|
86
|
+
}),
|
|
87
|
+
koishi_1.Schema.object({})
|
|
88
|
+
])
|
|
89
|
+
]),
|
|
90
|
+
style: koishi_1.Schema.object({}).description('美化设置'),
|
|
91
|
+
removeBorder: koishi_1.Schema.boolean()
|
|
92
|
+
.default(false)
|
|
93
|
+
.description('移除推送卡片边框'),
|
|
63
94
|
cardColorStart: koishi_1.Schema.string()
|
|
64
95
|
.pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
|
|
65
96
|
.default('#F38AB5')
|
|
@@ -69,17 +100,20 @@ exports.Config = koishi_1.Schema.object({
|
|
|
69
100
|
.default('#F9CCDF')
|
|
70
101
|
.description('推送卡片的结束渐变背景色,请填入16进制颜色代码,参考网站:https://colorate.azurewebsites.net/'),
|
|
71
102
|
font: koishi_1.Schema.string()
|
|
72
|
-
.description('推送卡片的字体样式,如果你想用你自己的字体可以在此填写,例如:Microsoft YaHei')
|
|
73
|
-
key: koishi_1.Schema.string()
|
|
74
|
-
.pattern(/^[0-9a-f]{32}$/)
|
|
75
|
-
.role('secret')
|
|
76
|
-
.required()
|
|
77
|
-
.description('请输入一个32位小写字母的十六进制密钥(例如:9b8db7ae562b9864efefe06289cc5530),使用此密钥将你的B站登录信息存储在数据库中,请一定保存好此密钥。如果你忘记了此密钥,必须重新登录。你可以自行生成,或到这个网站生成:https://www.sexauth.com/')
|
|
103
|
+
.description('推送卡片的字体样式,如果你想用你自己的字体可以在此填写,例如:Microsoft YaHei')
|
|
78
104
|
});
|
|
79
105
|
function apply(ctx, config) {
|
|
106
|
+
// 设置提示
|
|
80
107
|
ctx.notifier.create({
|
|
81
108
|
content: '请记得使用Auth插件创建超级管理员账号,没有权限将无法使用该插件提供的指令。'
|
|
82
109
|
});
|
|
110
|
+
if (config.unlockSubLimits) { // 用户允许订阅超过三个用户
|
|
111
|
+
// 设置警告
|
|
112
|
+
ctx.notifier.create({
|
|
113
|
+
type: 'danger',
|
|
114
|
+
content: '过多的订阅可能会导致IP暂时被封禁!'
|
|
115
|
+
});
|
|
116
|
+
}
|
|
83
117
|
// load config
|
|
84
118
|
// 转换为具体时间
|
|
85
119
|
let dynamicLoopTime;
|
|
@@ -111,11 +145,11 @@ function apply(ctx, config) {
|
|
|
111
145
|
ctx.plugin(Database);
|
|
112
146
|
// Regist server
|
|
113
147
|
ctx.plugin(wbi_1.default, { key: config.key });
|
|
114
|
-
ctx.plugin(generateImg_1.default, { renderType, cardColorStart: config.cardColorStart, cardColorEnd: config.cardColorEnd, font: config.font });
|
|
148
|
+
ctx.plugin(generateImg_1.default, { renderType, filter: config.filter, removeBorder: config.removeBorder, cardColorStart: config.cardColorStart, cardColorEnd: config.cardColorEnd, font: config.font });
|
|
115
149
|
ctx.plugin(biliAPI_1.default);
|
|
116
150
|
// load plugin
|
|
117
151
|
// ctx.plugin(Authority)
|
|
118
|
-
ctx.plugin(comRegister_1.default, { pushTime: config.pushTime, dynamicCheckNumber: config.dynamicCheckNumber, dynamicLoopTime });
|
|
152
|
+
ctx.plugin(comRegister_1.default, { unlockSubLimits: config.unlockSubLimits, pushTime: config.pushTime, dynamicCheckNumber: config.dynamicCheckNumber, dynamicLoopTime });
|
|
119
153
|
// 当用户输入“恶魔兔,启动!”时,执行 help 指令
|
|
120
154
|
ctx.middleware((session, next) => {
|
|
121
155
|
if (session.content === '恶魔兔,启动!') {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -84,6 +84,8 @@
|
|
|
84
84
|
- ver 1.0.6 修复了转发动态转发信息出现undefined的bug,修复了再次登录订阅显示错误的bug,优化了动态推送的逻辑
|
|
85
85
|
- ver 1.0.7 修复了在已登录情况下,再次登录会导致重复订阅和提示用户未订阅任何UP主的提示(实际上已订阅)的bug,新增了订阅对象在控制台的显示,优化了bili show指令的逻辑
|
|
86
86
|
- ver 1.0.8 修复了取消订阅的bug
|
|
87
|
+
- ver 1.0.9 更新请求客户端header信息。优化了动态推送卡片的页面布局,增加了字体大小。提供用户开放订阅数量限制的选项,提供用户移除推送卡片边框的选项。在控制台页面增加订阅信息提示
|
|
88
|
+
- ver 1.0.10 增加对onebot的支持,添加动态关键字屏蔽功能
|
|
87
89
|
|
|
88
90
|
## 感谢
|
|
89
91
|
|