koishi-plugin-bilibili-notify 1.0.0-rc.2 → 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Akokko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/lib/biliAPI.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Context, Service } from "koishi";
2
2
  import { CookieJar } from 'tough-cookie';
3
+ import { Notifier } from "@koishijs/plugin-notifier";
3
4
  declare module 'koishi' {
4
5
  interface Context {
5
6
  biliAPI: BiliAPI;
@@ -10,6 +11,7 @@ declare class BiliAPI extends Service {
10
11
  jar: CookieJar;
11
12
  client: any;
12
13
  loginData: any;
14
+ loginNotifier: Notifier;
13
15
  constructor(ctx: Context);
14
16
  protected start(): void | Promise<void>;
15
17
  getTimeNow(): Promise<any>;
@@ -21,6 +23,7 @@ declare class BiliAPI extends Service {
21
23
  getLoginStatus(qrcodeKey: string): Promise<any>;
22
24
  getLiveRoomInfo(roomId: string): Promise<any>;
23
25
  getMasterInfo(mid: string): Promise<any>;
26
+ disposeNotifier(): void;
24
27
  createNewClient(): void;
25
28
  getCookies(): string;
26
29
  loadCookiesFromDatabase(): Promise<void>;
package/lib/biliAPI.js CHANGED
@@ -8,7 +8,7 @@ const axios_1 = __importDefault(require("axios"));
8
8
  const tough_cookie_1 = require("tough-cookie");
9
9
  const axios_cookiejar_support_1 = require("axios-cookiejar-support");
10
10
  const jsdom_1 = require("jsdom");
11
- const GET_DYNAMIC_LIST = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all';
11
+ // const GET_DYNAMIC_LIST = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all'
12
12
  const GET_USER_SPACE_DYNAMIC_LIST = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space';
13
13
  const GET_COOKIES_INFO = 'https://passport.bilibili.com/x/passport-login/web/cookie/info';
14
14
  const GET_USER_INFO = 'https://api.bilibili.com/x/space/wbi/acc/info';
@@ -19,10 +19,11 @@ const GET_LIVE_ROOM_INFO = 'https://api.live.bilibili.com/room/v1/Room/get_info'
19
19
  const GET_MASTER_INFO = 'https://api.live.bilibili.com/live_user/v1/Master/info';
20
20
  const GET_TIME_NOW = 'https://api.bilibili.com/x/report/click/now';
21
21
  class BiliAPI extends koishi_1.Service {
22
- static inject = ['database', 'wbi'];
22
+ static inject = ['database', 'wbi', 'notifier'];
23
23
  jar;
24
24
  client;
25
25
  loginData;
26
+ loginNotifier;
26
27
  constructor(ctx) {
27
28
  super(ctx, 'biliAPI');
28
29
  }
@@ -117,6 +118,7 @@ class BiliAPI extends koishi_1.Service {
117
118
  throw new Error('网络异常,本次请求失败!');
118
119
  }
119
120
  }
121
+ disposeNotifier() { this.loginNotifier && this.loginNotifier.dispose(); }
120
122
  createNewClient() {
121
123
  this.jar = new tough_cookie_1.CookieJar();
122
124
  this.client = (0, axios_cookiejar_support_1.wrapper)(axios_1.default.create({ jar: this.jar, headers: { 'Content-Type': 'application/json' } }));
@@ -133,11 +135,30 @@ class BiliAPI extends koishi_1.Service {
133
135
  async loadCookiesFromDatabase() {
134
136
  // 读取数据库获取cookies
135
137
  const data = (await this.ctx.database.get('loginBili', 1))[0];
136
- // 没有数据则直接返回
137
- if (data === undefined)
138
+ // 判断是否登录
139
+ if (data === undefined) { // 没有数据则直接返回
140
+ // 未登录,在控制台提示
141
+ this.loginNotifier = this.ctx.notifier.create({
142
+ type: 'warning',
143
+ content: '您尚未登录,将无法使用插件提供的指令'
144
+ });
145
+ return;
146
+ }
147
+ // 定义解密信息
148
+ let decryptedCookies;
149
+ let decryptedRefreshToken;
150
+ try {
151
+ // 解密数据
152
+ decryptedCookies = this.ctx.wbi.decrypt(data.bili_cookies);
153
+ // 解密refresh_token
154
+ decryptedRefreshToken = this.ctx.wbi.decrypt(data.bili_refresh_token);
155
+ }
156
+ catch (e) {
157
+ // 解密失败,删除数据库登录信息
158
+ await this.ctx.database.remove('loginBili', [1]);
159
+ // 直接返回
138
160
  return;
139
- // 解密数据
140
- const decryptedCookies = this.ctx.wbi.decrypt(data.bili_cookies);
161
+ }
141
162
  // 解析从数据库读到的cookies
142
163
  const cookies = JSON.parse(decryptedCookies);
143
164
  // 定义CSRF Token
@@ -160,10 +181,10 @@ class BiliAPI extends koishi_1.Service {
160
181
  });
161
182
  this.jar.setCookieSync(cookie, `http${cookie.secure ? 's' : ''}://${cookie.domain}${cookie.path}`, {});
162
183
  });
163
- // 解密refresh_token
164
- const decryptedRefreshToken = this.ctx.wbi.decrypt(data.bili_refresh_token);
165
- // Check if token need refresh
166
- this.checkIfTokenNeedRefresh(decryptedRefreshToken, csrf);
184
+ // Open scheduled tasks and check if token need refresh
185
+ this.ctx.setInterval(() => {
186
+ this.checkIfTokenNeedRefresh(decryptedRefreshToken, csrf);
187
+ }, 43200000);
167
188
  }
168
189
  async checkIfTokenNeedRefresh(refreshToken, csrf, times = 0) {
169
190
  let data;
@@ -204,22 +225,30 @@ class BiliAPI extends koishi_1.Service {
204
225
  const refresh_csrf = targetElement ? targetElement.textContent : null;
205
226
  // 发送刷新请求
206
227
  const { data: refreshData } = await this.client.post('https://passport.bilibili.com/x/passport-login/web/cookie/refresh', {
207
- csrf,
228
+ csrf: csrf.trim(),
208
229
  refresh_csrf,
209
230
  source: 'main_web',
210
231
  refresh_token: refreshToken
211
232
  });
233
+ const notifyAndError = (info) => {
234
+ // 设置控制台通知
235
+ this.loginNotifier = this.ctx.notifier.create({
236
+ type: 'warning',
237
+ content: info
238
+ });
239
+ throw new Error(info);
240
+ };
212
241
  // 检查是否有其他问题
213
242
  switch (refreshData.code) {
214
243
  // 账号未登录
215
244
  case -101: return this.createNewClient();
216
245
  case -111: {
217
246
  await this.ctx.database.remove('loginBili', [1]);
218
- throw new Error('csrf 校验失败');
247
+ notifyAndError('csrf 校验错误,请重新登录');
219
248
  }
220
249
  case 86095: {
221
250
  await this.ctx.database.remove('loginBili', [1]);
222
- throw new Error('refresh_csrf 错误或 refresh_token 与 cookie 不匹配');
251
+ notifyAndError('refresh_csrf 错误或 refresh_token 与 cookie 不匹配,请重新登录');
223
252
  }
224
253
  }
225
254
  // 更新 新的cookies和refresh_token
@@ -247,7 +276,10 @@ class BiliAPI extends koishi_1.Service {
247
276
  });
248
277
  // 检查是否有其他问题
249
278
  switch (aceeptData.code) {
250
- case -111: throw new Error('csrf 校验失败');
279
+ case -111: {
280
+ await this.ctx.database.remove('loginBili', [1]);
281
+ notifyAndError('csrf 校验失败,请重新登录');
282
+ }
251
283
  case -400: throw new Error('请求错误');
252
284
  }
253
285
  // 没有问题,cookies已更新完成
@@ -23,13 +23,13 @@ declare class ComRegister {
23
23
  getSubFromDatabase(ctx: Context): Promise<void>;
24
24
  unsubSingle(ctx: Context, id: string, type: number): string;
25
25
  checkIfIsLogin(ctx: Context): Promise<boolean>;
26
- test_dynamicDetect(ctx: Context, session: Session, uid: string): () => Promise<void>;
27
26
  }
28
27
  declare namespace ComRegister {
29
28
  interface Config {
30
29
  pushTime: number;
31
30
  liveLoopTime: number;
32
31
  dynamicLoopTime: number;
32
+ dynamicCheckNumber: number;
33
33
  }
34
34
  const Config: Schema<Config>;
35
35
  }
@@ -172,6 +172,8 @@ class ComRegister {
172
172
  }]);
173
173
  // 销毁定时器
174
174
  dispose();
175
+ // 清除控制台通知
176
+ ctx.biliAPI.disposeNotifier();
175
177
  // 发送成功登录推送
176
178
  await session.send('登录成功!');
177
179
  // 订阅之前的订阅
@@ -244,7 +246,7 @@ class ComRegister {
244
246
  .option('live', '-l')
245
247
  .option('dynamic', '-d')
246
248
  .usage('订阅用户动态和直播通知,若需要订阅直播请加上-l,需要订阅动态则加上-d。若没有加任何参数,之后会向你单独询问,尖括号中为必选参数,中括号为可选参数,目标群号若不填,则默认为当前群聊')
247
- .example('bili sub 用户uid 目标QQ群号(暂不支持) -l -d')
249
+ .example('bili sub 1194210119 目标QQ群号(暂不支持) -l -d 订阅UID为1194210119的UP主的动态和直播')
248
250
  .action(async ({ session, options }, mid, guildId) => {
249
251
  this.logger.info('调用bili.sub指令');
250
252
  // 检查是否登录
@@ -382,7 +384,7 @@ class ComRegister {
382
384
  .subcommand('.dynamic <uid:string> <guildId:string>', '订阅用户动态推送', { hidden: true })
383
385
  .option('bot', '-b <type:string>')
384
386
  .usage('订阅用户动态推送')
385
- .example('bili dynamic 1')
387
+ .example('bili dynamic 1194210119 订阅UID为1194210119的动态')
386
388
  .action(async ({ session, options }, uid, guildId) => {
387
389
  this.logger.info('调用bili.dynamic指令');
388
390
  // 如果uid为空则返回
@@ -411,7 +413,7 @@ class ComRegister {
411
413
  default: return '非法调用';
412
414
  }
413
415
  // 开始循环检测
414
- const dispose = ctx.setInterval(this.dynamicDetect(ctx, bot, guildId, uid), 60000);
416
+ const dispose = ctx.setInterval(this.dynamicDetect(ctx, bot, guildId, uid), config.dynamicLoopTime * 1000);
415
417
  // 将销毁函数保存到订阅管理对象
416
418
  this.subManager[index].dynamicDispose = dispose;
417
419
  });
@@ -419,7 +421,7 @@ class ComRegister {
419
421
  .subcommand('.live <roomId:string> <guildId:string>', '订阅主播开播通知', { hidden: true })
420
422
  .option('bot', '-b <type:string>')
421
423
  .usage('订阅主播开播通知')
422
- .example('bili live 732')
424
+ .example('bili live 26316137 订阅房间号为26316137的直播间')
423
425
  .action(async ({ options }, roomId, guildId) => {
424
426
  this.logger.info('调用bili.live指令');
425
427
  // 如果room_id为空则返回
@@ -446,7 +448,7 @@ class ComRegister {
446
448
  default: return '非法调用';
447
449
  }
448
450
  // 开始循环检测
449
- const dispose = ctx.setInterval(this.liveDetect(ctx, bot, guildId, roomId), 5000);
451
+ const dispose = ctx.setInterval(this.liveDetect(ctx, bot, guildId, roomId), config.liveLoopTime * 1000);
450
452
  // 保存销毁函数
451
453
  this.subManager[index].liveDispose = dispose;
452
454
  });
@@ -534,8 +536,8 @@ class ComRegister {
534
536
  }
535
537
  // 获取数据内容
536
538
  const items = content.data.items;
537
- // 发送请求 只查看前五条数据
538
- for (let num = 4; num >= 0; num--) {
539
+ // 发送请求 默认只查看前五条数据
540
+ for (let num = this.config.dynamicCheckNumber - 1; num >= 0; num--) {
539
541
  // 没有动态内容则直接跳过
540
542
  if (!items[num])
541
543
  continue;
@@ -548,11 +550,15 @@ class ComRegister {
548
550
  if (num === 0) {
549
551
  timePoint = items[num].modules.module_author.pub_ts
550
552
  } */
551
- switch (num) {
553
+ // 检查最一条动态是否是置顶动态
554
+ if (num === 0) {
552
555
  // 如果是置顶动态,则跳过
553
- case 0: if (items[num].modules.module_tag)
556
+ if (items[num].modules.module_tag) {
557
+ // 将上一条动态的发布时间设为时间点
558
+ timePoint = items[num + 1].modules.module_author.pub_ts;
554
559
  continue;
555
- case 1: timePoint = items[num].modules.module_author.pub_ts;
560
+ }
561
+ timePoint = items[num].modules.module_author.pub_ts;
556
562
  }
557
563
  // 推送该条动态
558
564
  let attempts = 3;
@@ -849,82 +855,13 @@ class ComRegister {
849
855
  }
850
856
  return false;
851
857
  }
852
- test_dynamicDetect(ctx, session, uid) {
853
- let firstSubscription = true;
854
- let timePoint;
855
- // Test code
856
- let timer = 0;
857
- return async () => {
858
- // Test code
859
- console.log('timer:' + timer++);
860
- console.log('firstSubscription:' + firstSubscription);
861
- console.log(`timePoint: ${timePoint}`);
862
- console.log(`timePoint: ${ctx.gimg.unixTimestampToString(timePoint)}`);
863
- // 第一次订阅判断
864
- if (firstSubscription) {
865
- // 设置第一次的时间点
866
- timePoint = Math.floor(Date.now() / 1000);
867
- // 设置第一次为false
868
- firstSubscription = false;
869
- return;
870
- }
871
- // 获取用户空间动态数据
872
- let content;
873
- try {
874
- content = await ctx.biliAPI.getUserSpaceDynamic(uid);
875
- }
876
- catch (e) {
877
- return this.logger.error('dynamicDetect getUserSpaceDynamic() 网络请求失败');
878
- }
879
- // 判断是否出现其他问题
880
- if (content.code !== 0) {
881
- switch (content.code) {
882
- case -101: { // 账号未登录
883
- await session.send('账号未登录,请登录后重新订阅动态');
884
- }
885
- default: { // 未知错误
886
- await session.send('未知错误,请重新订阅动态');
887
- }
888
- }
889
- // 取消订阅
890
- this.unsubSingle(ctx, uid, 1); /* 1为取消动态订阅 */
891
- return;
892
- }
893
- // 获取数据内容
894
- const items = content.data.items;
895
- // 发送请求 只查看前五条数据
896
- for (let num = 4; num >= 0; num--) {
897
- // 没有动态内容则直接跳过
898
- if (!items[num])
899
- continue;
900
- // Test code
901
- console.log(`items[${num}].modules.module_author.pub_ts: ${ctx.gimg.unixTimestampToString(items[num].modules.module_author.pub_ts)}`);
902
- // 寻找发布时间比时间点时间更晚的动态
903
- if (items[num].modules.module_author.pub_ts > timePoint) {
904
- // 如果这是遍历的最后一条,将时间点设置为这条动态的发布时间
905
- /* if (num === 1) timePoint = items[num].modules.module_author.pub_ts
906
- if (num === 0) {
907
- timePoint = items[num].modules.module_author.pub_ts
908
- } */
909
- switch (num) {
910
- // 如果是置顶动态,则跳过
911
- case 0: if (items[num].modules.module_tag)
912
- continue;
913
- case 1: timePoint = items[num].modules.module_author.pub_ts;
914
- }
915
- // 推送该条动态
916
- const [pic] = await ctx.gimg.generateDynamicImg(items[num]);
917
- await session.send(pic);
918
- }
919
- }
920
- };
921
- }
922
858
  }
923
859
  (function (ComRegister) {
924
860
  ComRegister.Config = koishi_1.Schema.object({
925
861
  pushTime: koishi_1.Schema.number().required(),
926
862
  liveLoopTime: koishi_1.Schema.number().default(10),
927
- dynamicLoopTime: koishi_1.Schema.number().default(60)
863
+ dynamicLoopTime: koishi_1.Schema.number().default(60),
864
+ dynamicCheckNumber: koishi_1.Schema.number().required()
928
865
  });
929
866
  })(ComRegister || (ComRegister = {}));
930
867
  exports.default = ComRegister;
@@ -25,14 +25,14 @@ const DYNAMIC_TYPE_BANNER = 'DYNAMIC_TYPE_BANNER';
25
25
  const DYNAMIC_TYPE_UGC_SEASON = 'DYNAMIC_TYPE_UGC_SEASON';
26
26
  const DYNAMIC_TYPE_SUBSCRIPTION_NEW = 'DYNAMIC_TYPE_SUBSCRIPTION_NEW';
27
27
  // 内容卡片类型
28
- const ADDITIONAL_TYPE_NONE = 'ADDITIONAL_TYPE_NONE';
29
- const ADDITIONAL_TYPE_PGC = 'ADDITIONAL_TYPE_PGC';
30
- const ADDITIONAL_TYPE_GOODS = 'ADDITIONAL_TYPE_GOODS';
31
- const ADDITIONAL_TYPE_VOTE = 'ADDITIONAL_TYPE_VOTE';
32
- const ADDITIONAL_TYPE_COMMON = 'ADDITIONAL_TYPE_COMMON';
33
- const ADDITIONAL_TYPE_MATCH = 'ADDITIONAL_TYPE_MATCH';
34
- const ADDITIONAL_TYPE_UP_RCMD = 'ADDITIONAL_TYPE_UP_RCMD';
35
- const ADDITIONAL_TYPE_UGC = 'ADDITIONAL_TYPE_UGC';
28
+ /* const ADDITIONAL_TYPE_NONE = 'ADDITIONAL_TYPE_NONE'
29
+ const ADDITIONAL_TYPE_PGC = 'ADDITIONAL_TYPE_PGC'
30
+ const ADDITIONAL_TYPE_GOODS = 'ADDITIONAL_TYPE_GOODS'
31
+ const ADDITIONAL_TYPE_VOTE = 'ADDITIONAL_TYPE_VOTE'
32
+ const ADDITIONAL_TYPE_COMMON = 'ADDITIONAL_TYPE_COMMON'
33
+ const ADDITIONAL_TYPE_MATCH = 'ADDITIONAL_TYPE_MATCH'
34
+ const ADDITIONAL_TYPE_UP_RCMD = 'ADDITIONAL_TYPE_UP_RCMD'
35
+ const ADDITIONAL_TYPE_UGC = 'ADDITIONAL_TYPE_UGC' */
36
36
  const ADDITIONAL_TYPE_RESERVE = 'ADDITIONAL_TYPE_RESERVE';
37
37
  class GenerateImg extends koishi_1.Service {
38
38
  static inject = ['puppeteer', 'biliAPI'];
package/lib/index.d.ts CHANGED
@@ -3,6 +3,8 @@ export declare const inject: string[];
3
3
  export declare const name = "bilibili-notify";
4
4
  export interface Config {
5
5
  pushTime: number;
6
+ dynamicCheckNumber: number;
7
+ dynamicLoopTime: '1分钟' | '2分钟' | '3分钟' | '5分钟';
6
8
  cardColorStart: string;
7
9
  cardColorEnd: string;
8
10
  key: string;
package/lib/index.js CHANGED
@@ -28,8 +28,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.apply = exports.Config = exports.name = exports.inject = void 0;
30
30
  const koishi_1 = require("koishi");
31
- // import crypto
32
- // import crypto from 'crypto'
33
31
  // import plugins
34
32
  // import Authority from './authority'
35
33
  const comRegister_1 = __importDefault(require("./comRegister"));
@@ -38,7 +36,7 @@ const Database = __importStar(require("./database"));
38
36
  const wbi_1 = __importDefault(require("./wbi"));
39
37
  const generateImg_1 = __importDefault(require("./generateImg"));
40
38
  const biliAPI_1 = __importDefault(require("./biliAPI"));
41
- exports.inject = ['puppeteer', 'database'];
39
+ exports.inject = ['puppeteer', 'database', 'notifier'];
42
40
  exports.name = 'bilibili-notify';
43
41
  exports.Config = koishi_1.Schema.object({
44
42
  pushTime: koishi_1.Schema.number()
@@ -47,6 +45,17 @@ exports.Config = koishi_1.Schema.object({
47
45
  .step(0.5)
48
46
  .default(1)
49
47
  .description('设定隔多长时间推送一次直播状态,单位为小时,默认为一小时'),
48
+ dynamicCheckNumber: koishi_1.Schema.number()
49
+ .min(2)
50
+ .max(10)
51
+ .role('slider')
52
+ .step(1)
53
+ .default(5)
54
+ .description('设定每次检查动态的数量。若订阅的UP主经常在短时间内连着发多条动态可以将该值提高,若订阅的UP主有置顶动态,在计算该值时应-1。默认值为5条'),
55
+ dynamicLoopTime: koishi_1.Schema.union(['1分钟', '2分钟', '3分钟', '5分钟'])
56
+ .role('')
57
+ .default('2分钟')
58
+ .description('设定多久检测一次动态。若需动态的时效性,可以设置为1分钟。若订阅的UP主经常在短时间内连着发多条动态应该将该值提高,否则会出现动态漏推送和晚推送的问题,默认值为2分钟'),
50
59
  cardColorStart: koishi_1.Schema.string()
51
60
  .pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
52
61
  .default('#F38AB5')
@@ -62,6 +71,9 @@ exports.Config = koishi_1.Schema.object({
62
71
  .description('请输入一个32位小写字母的十六进制密钥(例如:9b8db7ae562b9864efefe06289cc5530),使用此密钥将你的B站登录信息存储在数据库中,请一定保存好此密钥。如果你忘记了此密钥,必须重新登录。你可以自行生成,或到这个网站生成:https://www.sexauth.com/')
63
72
  });
64
73
  function apply(ctx, config) {
74
+ ctx.notifier.create({
75
+ content: '请记得使用Auth插件创建超级管理员账号,没有权限将无法使用该插件提供的指令。'
76
+ });
65
77
  // load database
66
78
  ctx.plugin(Database);
67
79
  // Regist server
@@ -70,7 +82,23 @@ function apply(ctx, config) {
70
82
  ctx.plugin(biliAPI_1.default);
71
83
  // load plugin
72
84
  // ctx.plugin(Authority)
73
- ctx.plugin(comRegister_1.default, { pushTime: config.pushTime });
85
+ // 转换为具体时间
86
+ let dynamicLoopTime;
87
+ switch (config.dynamicLoopTime) {
88
+ case '1分钟':
89
+ dynamicLoopTime = 60;
90
+ break;
91
+ case '2分钟':
92
+ dynamicLoopTime = 120;
93
+ break;
94
+ case '3分钟':
95
+ dynamicLoopTime = 180;
96
+ break;
97
+ case '5分钟':
98
+ dynamicLoopTime = 300;
99
+ break;
100
+ }
101
+ ctx.plugin(comRegister_1.default, { pushTime: config.pushTime, dynamicCheckNumber: config.dynamicCheckNumber, dynamicLoopTime });
74
102
  // 当用户输入“恶魔兔,启动!”时,执行 help 指令
75
103
  ctx.middleware((session, next) => {
76
104
  if (session.content === '恶魔兔,启动!') {
@@ -82,6 +110,3 @@ function apply(ctx, config) {
82
110
  });
83
111
  }
84
112
  exports.apply = apply;
85
- /* function generateKey(): string {
86
- return crypto.randomBytes(32).toString('hex');
87
- } */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-bilibili-notify",
3
3
  "description": "Koishi bilibili notify plugin",
4
- "version": "1.0.0-rc.2",
4
+ "version": "1.0.1",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
@@ -16,6 +16,7 @@
16
16
  "type": "git",
17
17
  "url": "git+https://github.com/Akokk0/koishi-plugin-bilibili-notify"
18
18
  },
19
+ "homepage": "https://www.npmjs.com/package/koishi-plugin-bilibili-notify",
19
20
  "scripts": {},
20
21
  "keywords": [
21
22
  "chatbot",
@@ -37,15 +38,15 @@
37
38
  "koishi-plugin-puppeteer": "^3.7.3"
38
39
  },
39
40
  "koishi": {
40
- "preview": true,
41
41
  "service": {
42
42
  "required": [
43
43
  "database",
44
- "puppeteer"
44
+ "puppeteer",
45
+ "notifier"
45
46
  ]
46
47
  },
47
48
  "description": {
48
- "zh": "开发中的Bilibili直播通知,动态推送插件。目前还只是个雏形,不建议使用,发布做测试用"
49
+ "zh": "Bilibili动态推送,直播通知插件。具体使用方法请参考readme.md"
49
50
  },
50
51
  "locales": [
51
52
  "zh"
package/readme.md CHANGED
@@ -1,15 +1,89 @@
1
- # koishi-plugin-bilibili-notify
1
+ <div align="center">
2
+ # Bilibili-Botify
3
+ </div>
2
4
 
3
- [![npm](https://img.shields.io/npm/v/koishi-plugin-bilibili-notify?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-bilibili-notify)
4
5
 
5
- 此插件依赖于"database"和"puppeteer"服务,同时受权限控制,需要具备authority:3及以上的权限才能使用本插件提供的指令,你可以参考下面链接中的方法得到一个超级管理员账号(具有authority:5的最高权限)
6
- https://koishi.chat/zh-CN/manual/usage/platform.html#%E9%85%8D%E7%BD%AE%E7%99%BB%E5%BD%95%E6%8F%92%E4%BB%B6
6
+ 基于 [koishi](../../../../koishijs/koishi) 框架的B站推送插件
7
7
 
8
- 您还可以安装admin插件,给其他用户授予权限,操作方法请参考下面的链接
9
- https://koishi.chat/zh-CN/manual/usage/customize.html
8
+ ---
10
9
 
11
- 指令使用方法请参考 help bili,子命令使用方法请加-h,例如bili login -h
10
+ - **koishi-plugin-bilibili-notify** [![npm](https://img.shields.io/npm/v/koishi-plugin-bilibili-notify?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-bilibili-notify)
11
+ - [功能](#功能)
12
+ - [安装](#安装)
13
+ - [使用方法](#使用方法)
14
+ - [注意事项](#注意事项)
15
+ - [感谢](#感谢)
16
+ - [License](#License)
12
17
 
13
- 本插件功能均建立在B站账号登录之上,所有操作之前请先登录
18
+ ## 功能
14
19
 
15
- 登录方式为二维码,输入命令bili login之后扫码登录,您的登录凭证将存储在您的本地数据库,并由您自己填写的密钥加密,所以请保管好你的密钥
20
+ 订阅B站UP主动态
21
+
22
+ 订阅B站UP主直播
23
+
24
+ ## 安装
25
+
26
+ 1. 下载插件运行平台 [Koishi](https://koishi.chat/)
27
+ 2. 在插件平台的 **`插件市场`** 中搜索 **`bilibili-notify`** 并安装
28
+
29
+ ## 使用方法
30
+
31
+ 登录B站:进行任何操作前,请先登录B站
32
+
33
+ - 使用指令 `bili login` 获取登录二维码,使用B站扫码登录
34
+
35
+ 订阅UP主:订阅你想要推送的UP主
36
+
37
+ - 使用指令 `bili sub <uid>` 订阅需要订阅的UP主
38
+ - 参数说明:`uid` 为必填参数,为 `up主` 的 `uid`
39
+ - 选项说明:`bili sub <uid>` 有两个选项:-l 和 -d
40
+ - `-l` 为订阅UP主直播间,包括直播开播通知,定时推送直播内容,下播通知
41
+ - `-d` 为订阅UP主动态推送,目前实现推送的动态类型有:普通图文动态,转发动态,直播预约动态
42
+
43
+ - 例如:
44
+ - `bili sub 1194210119 ` 订阅UID为1194210119的UP主
45
+ - `bili sub 1194210119 -d` 订阅UID为1194210119的UP主动态推送
46
+ - `bili sub 1194210119 -ld` 订阅UID为1194210119的UP主动态推送和直播间
47
+ - Tips:
48
+ - 除非使用指令 `bili sub 1194210119 -ld` ,没有加选项或只加了一个选项的指令都会再次询问是否需要订阅另一项。例如:使用指令 `bili sub 1194210119 -d` 机器人会询问是否需要订阅直播间
49
+
50
+ 取消订阅UP主:取消订阅不需要推送的UP主
51
+
52
+ - 使用指令 `bili unsub <uid>` 取消订阅不需要订阅的UP主
53
+ - 参数说明:`uid` 为必填参数,为 `up主` 的 `uid`
54
+ - 选项说明:`bili unsub <uid>` 有两个选项:-l 和 -d
55
+ - `-l` 为取消订阅UP主直播间
56
+ - `-d` 为取消订阅UP主动态
57
+ - 例如:
58
+ - `bili unsub 123456` 取消订阅UID为123456的UP主动态推送和直播间
59
+ - `bili unsub 123456 -d` 取消订阅UID为123456的UP主动态推送
60
+ - `bili unsub 123456 -dl` 取消订阅UID为123456的UP主动态推送和直播间
61
+
62
+ 查看目前已订阅的UP主:
63
+
64
+ - 使用指令 `bili show`
65
+
66
+ ## 注意事项
67
+
68
+ 1. 此插件依赖于 `database` 和 `puppeteer` 服务,同时受权限控制,需要具备 `authority:3` 及以上的权限才能使用本插件提供的指令,你可以参考下方配置登录插件中的方法得到一个超级管理员账号(具有 `authority:5` 的最高权限)
69
+
70
+ [配置登录插件](https://koishi.chat/zh-CN/manual/usage/platform.html#%E9%85%8D%E7%BD%AE%E7%99%BB%E5%BD%95%E6%8F%92%E4%BB%B6)
71
+
72
+ 2. 您还可以安装 `admin` 插件,给其他用户授予权限,操作方法请参考下方的权限管理
73
+
74
+ [权限管理](https://koishi.chat/zh-CN/manual/usage/customize.html)
75
+
76
+ 3. 指令使用方法请参考 `help bili`,子命令使用方法请加 `-h` ,例如 `bili login -h`
77
+ 4. 登录方式为二维码,输入命令 `bili login` 之后扫码登录,您的登录凭证将存储在您的本地数据库,并由您自己填写的密钥加密,所以请保管好你的密钥
78
+
79
+ ## 更新日志
80
+
81
+ ver 1.0.1 修复了一些bug,提供用户自己选择动态检测时间的选项
82
+
83
+ ## 感谢
84
+
85
+ 感谢 [koishijs](https://github.com/koishijs/koishi) 官方提供的插件开发框架, 以及技术指导
86
+
87
+ ## License
88
+
89
+ MIT