koishi-plugin-bilibili-notify 1.2.9-alpha.0 → 1.2.11-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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Context, Service } from "koishi";
1
+ import { Context, Schema, Service } from "koishi";
2
2
  import { CookieJar } from 'tough-cookie';
3
3
  import { Notifier } from "@koishijs/plugin-notifier";
4
4
  declare module 'koishi' {
@@ -10,11 +10,12 @@ declare class BiliAPI extends Service {
10
10
  static inject: string[];
11
11
  jar: CookieJar;
12
12
  client: any;
13
+ apiConfig: BiliAPI.Config;
13
14
  loginData: any;
14
15
  loginNotifier: Notifier;
15
16
  refreshCookieTimer: Function;
16
17
  loginInfoIsLoaded: boolean;
17
- constructor(ctx: Context);
18
+ constructor(ctx: Context, config: BiliAPI.Config);
18
19
  protected start(): void | Promise<void>;
19
20
  protected stop(): void | Promise<void>;
20
21
  getServerUTCTime(): Promise<number>;
@@ -41,4 +42,10 @@ declare class BiliAPI extends Service {
41
42
  enableRefreshCookiesDetect(): void;
42
43
  checkIfTokenNeedRefresh(refreshToken: string, csrf: string, times?: number): Promise<void>;
43
44
  }
45
+ declare namespace BiliAPI {
46
+ interface Config {
47
+ userAgent: string;
48
+ }
49
+ const Config: Schema<Config>;
50
+ }
44
51
  export default BiliAPI;
package/lib/biliAPI.js CHANGED
@@ -26,19 +26,20 @@ class BiliAPI extends koishi_1.Service {
26
26
  static inject = ['database', 'wbi', 'notifier'];
27
27
  jar;
28
28
  client;
29
+ apiConfig;
29
30
  loginData;
30
31
  loginNotifier;
31
32
  refreshCookieTimer;
32
33
  loginInfoIsLoaded = false;
33
- constructor(ctx) {
34
+ constructor(ctx, config) {
34
35
  super(ctx, 'biliAPI');
36
+ this.apiConfig = config;
35
37
  }
36
38
  start() {
37
39
  // 创建新的http客户端(axios)
38
40
  this.createNewClient();
39
41
  // 从数据库加载cookies
40
42
  this.loadCookiesFromDatabase();
41
- // logger
42
43
  // this.logger.info('工作中')
43
44
  }
44
45
  stop() {
@@ -152,16 +153,11 @@ class BiliAPI extends koishi_1.Service {
152
153
  disposeNotifier() { this.loginNotifier && this.loginNotifier.dispose(); }
153
154
  getRandomUserAgent() {
154
155
  const userAgents = [
155
- // Chrome
156
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',
157
- // Firefox
158
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0',
159
- // Safari
160
- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.3 Safari/605.1.15',
161
- // Internet Explorer
162
- 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; AS; rv:11.0) like Gecko',
163
- // Edge
164
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36 Edg/98.0.1108.62',
156
+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
157
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
158
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36',
159
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0',
160
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36'
165
161
  ];
166
162
  const index = Math.floor(Math.random() * userAgents.length);
167
163
  return userAgents[index];
@@ -172,7 +168,8 @@ class BiliAPI extends koishi_1.Service {
172
168
  jar: this.jar,
173
169
  headers: {
174
170
  'Content-Type': 'application/json',
175
- 'User-Agent': this.getRandomUserAgent(),
171
+ 'User-Agent': this.apiConfig.userAgent !== 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' ?
172
+ this.apiConfig.userAgent : this.getRandomUserAgent(),
176
173
  'Origin': 'https://www.bilibili.com',
177
174
  'Referer': 'https://www.bilibili.com/'
178
175
  }
@@ -394,4 +391,9 @@ class BiliAPI extends koishi_1.Service {
394
391
  // 没有问题,cookies已更新完成
395
392
  }
396
393
  }
394
+ (function (BiliAPI) {
395
+ BiliAPI.Config = koishi_1.Schema.object({
396
+ userAgent: koishi_1.Schema.string()
397
+ });
398
+ })(BiliAPI || (BiliAPI = {}));
397
399
  exports.default = BiliAPI;
@@ -38,6 +38,7 @@ declare class ComRegister {
38
38
  checkIfLoginInfoIsLoaded(ctx: Context): Promise<unknown>;
39
39
  getSubFromDatabase(ctx: Context): Promise<void>;
40
40
  unsubSingle(ctx: Context, id: string, type: number): string;
41
+ unsubAll(ctx: Context, bot: Bot<Context>, uid: string): void;
41
42
  checkIfIsLogin(ctx: Context): Promise<boolean>;
42
43
  }
43
44
  declare namespace ComRegister {
@@ -791,12 +791,13 @@ class ComRegister {
791
791
  await this.sendPrivateMsg(bot, '账号未登录,请登录后重新订阅动态');
792
792
  break;
793
793
  }
794
- default: await this.sendPrivateMsg(bot, '获取动态信息错误,错误为:' + content.message); // 未知错误
794
+ default: await this.sendPrivateMsg(bot, '获取动态信息错误,错误码为:' + content.code + ',错误为:' + content.message); // 未知错误
795
795
  }
796
796
  // 取消订阅
797
- this.unsubSingle(ctx, uid, 1); /* 1为取消动态订阅 */
797
+ this.unsubAll(ctx, bot, uid);
798
+ // this.unsubSingle(ctx, uid, 1) /* 1为取消动态订阅 */
798
799
  // 发送取消订阅消息
799
- await this.sendPrivateMsg(bot, `UID:${uid},已取消订阅动态`);
800
+ // await this.sendPrivateMsg(bot, `UID:${uid},已取消订阅动态`)
800
801
  // 结束循环
801
802
  return;
802
803
  }
@@ -850,12 +851,12 @@ class ComRegister {
850
851
  const dUrl = this.config.dynamicUrl ? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}` : '';
851
852
  // 如果pic存在,则直接返回pic
852
853
  if (pic) {
853
- console.log('render mode');
854
+ this.logger.info('推送动态中,使用render模式');
854
855
  // pic存在,使用的是render模式
855
856
  await this.sendMsg(ctx, guildId, bot, pic + (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: dUrl }));
856
857
  }
857
858
  else {
858
- console.log('page mode');
859
+ this.logger.info('推送动态中,使用page模式');
859
860
  // pic不存在,说明使用的是page模式
860
861
  await this.sendMsg(ctx, guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("img", { src: 'data:image/png;base64,' + buffer.toString('base64') }), " ", dUrl] }));
861
862
  }
@@ -1368,6 +1369,25 @@ class ComRegister {
1368
1369
  this.updateSubNotifier(ctx);
1369
1370
  }
1370
1371
  }
1372
+ unsubAll(ctx, bot, uid) {
1373
+ this.subManager.filter(sub => sub.uid === uid).map(async (sub, i) => {
1374
+ // 取消全部订阅 执行dispose方法,销毁定时器
1375
+ if (sub.dynamic)
1376
+ this.subManager[i].dynamicDispose();
1377
+ if (sub.live)
1378
+ this.subManager[i].liveDispose();
1379
+ // 从数据库中删除订阅
1380
+ await ctx.database.remove('bilibili', { uid: this.subManager[i].uid });
1381
+ // 将该订阅对象从订阅管理对象中移除
1382
+ this.subManager.splice(i, 1);
1383
+ // id--
1384
+ this.num--;
1385
+ // 发送成功通知
1386
+ this.sendPrivateMsg(bot, `UID:${uid},已取消订阅该用户`);
1387
+ // 更新控制台提示
1388
+ this.updateSubNotifier(ctx);
1389
+ });
1390
+ }
1371
1391
  async checkIfIsLogin(ctx) {
1372
1392
  if ((await ctx.database.get('loginBili', 1)).length !== 0) { // 数据库中有数据
1373
1393
  // 检查cookie中是否有值
package/lib/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export interface Config {
13
13
  basicSettings: {};
14
14
  unlockSubLimits: boolean;
15
15
  renderType: 'render' | 'page';
16
+ userAgent: string;
16
17
  dynamic: {};
17
18
  dynamicUrl: boolean;
18
19
  dynamicCheckNumber: number;
package/lib/index.js CHANGED
@@ -76,6 +76,9 @@ exports.Config = koishi_1.Schema.object({
76
76
  .role('')
77
77
  .default('render')
78
78
  .description('渲染类型,默认为render模式,渲染速度更快,但会出现乱码问题,若出现乱码问题,请切换到page模式。若使用自定义字体,建议选择render模式'),
79
+ userAgent: koishi_1.Schema.string()
80
+ .default('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36')
81
+ .description('设置请求头User-Agen,请求出现-352时可以尝试修改'),
79
82
  dynamic: koishi_1.Schema.object({}).description('动态推送设置'),
80
83
  dynamicUrl: koishi_1.Schema.boolean()
81
84
  .default(false)
@@ -172,7 +175,9 @@ class ServerManager extends koishi_1.Service {
172
175
  this.registerPlugin();
173
176
  }
174
177
  registerPlugin = () => {
175
- const biliApi = this.ctx.plugin(biliAPI_1.default);
178
+ const biliApi = this.ctx.plugin(biliAPI_1.default, {
179
+ userAgent: globalConfig.userAgent
180
+ });
176
181
  const generateImg = this.ctx.plugin(generateImg_1.default, {
177
182
  renderType: this.renderType,
178
183
  filter: globalConfig.filter,
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.2.9-alpha.0",
4
+ "version": "1.2.11-alpha.0",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -143,6 +143,8 @@
143
143
  - ver 1.2.7 修复不论选择什么渲染模式都是render模式的bug,优化直播卡片推送逻辑
144
144
  - ver 1.2.8 修复例如像UP主籽岷使用webp格式的头像,下播通知无法发出的bug
145
145
  - ver 1.2.9-alpha.0 bug测试版本,请跳过
146
+ - ver 1.2.10 修复插件启动一段时间后一直报错的问题,更新了UA列表,新增了更多日志输出
147
+ - ver 1.2.11-alpha.0 新增自定义UA的设置。动态推送出错时,现在会直接取消订阅该UP主而不是取消订阅动态
146
148
 
147
149
  ## 交流群
148
150