koishi-plugin-bilibili-notify 1.2.0-rc.5 → 1.2.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/lib/biliAPI.js CHANGED
@@ -9,6 +9,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
11
  const luxon_1 = require("luxon");
12
+ // 在getUserInfo中检测到番剧出差的UID时,要传回的数据:
13
+ const bangumiTripData = { "code": 0, "data": { "live_room": { "roomid": 931774 } } };
12
14
  // const GET_DYNAMIC_LIST = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all'
13
15
  const GET_USER_SPACE_DYNAMIC_LIST = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space';
14
16
  const GET_COOKIES_INFO = 'https://passport.bilibili.com/x/passport-login/web/cookie/info';
@@ -127,6 +129,11 @@ class BiliAPI extends koishi_1.Service {
127
129
  }
128
130
  }
129
131
  async getUserInfo(mid) {
132
+ //如果为番剧出差的UID,则不从远程接口拉取数据,直接传回一段精简过的有效数据
133
+ if (mid === "11783021") {
134
+ console.log("检测到番剧出差UID,跳过远程用户接口访问");
135
+ return bangumiTripData;
136
+ }
130
137
  try {
131
138
  const wbi = await this.ctx.wbi.getWbi({ mid });
132
139
  const { data } = await this.client.get(`${GET_USER_INFO}?${wbi}`);
@@ -23,6 +23,7 @@ declare class ComRegister {
23
23
  oneBot: Bot<Context>;
24
24
  redBot: Bot<Context>;
25
25
  telegramBot: Bot<Context>;
26
+ satoriBot: Bot<Context>;
26
27
  constructor(ctx: Context, config: ComRegister.Config);
27
28
  dynamicDetect(ctx: Context, bot: Bot<Context>, uid: string, guildId: Array<string>): () => Promise<void>;
28
29
  sendMsg(targets: Array<string>, bot: Bot<Context>, content: any): Promise<void>;
@@ -42,13 +43,14 @@ declare namespace ComRegister {
42
43
  liveLoopTime: number;
43
44
  customLiveStart: string;
44
45
  customLiveEnd: string;
46
+ dynamicUrl: boolean;
45
47
  dynamicLoopTime: number;
46
48
  dynamicCheckNumber: number;
47
49
  filter: {
48
50
  enable: boolean;
51
+ notify: boolean;
49
52
  regex: string;
50
53
  keywords: Array<string>;
51
- notify: boolean;
52
54
  };
53
55
  }
54
56
  const Config: Schema<Config>;
@@ -31,6 +31,8 @@ class ComRegister {
31
31
  redBot;
32
32
  // Telegram机器人
33
33
  telegramBot;
34
+ // Satori机器人
35
+ satoriBot;
34
36
  constructor(ctx, config) {
35
37
  this.logger = ctx.logger('commandRegister');
36
38
  this.config = config;
@@ -52,6 +54,9 @@ class ComRegister {
52
54
  case 'telegram':
53
55
  this.telegramBot = bot;
54
56
  break;
57
+ case 'satori':
58
+ this.satoriBot = bot;
59
+ break;
55
60
  }
56
61
  });
57
62
  // 从数据库获取订阅
@@ -305,6 +310,7 @@ class ComRegister {
305
310
  case 'red':
306
311
  case 'onebot':
307
312
  case 'telegram':
313
+ case 'satori':
308
314
  case 'qq':
309
315
  case 'qqguild': break;
310
316
  default: return '暂不支持该平台';
@@ -394,6 +400,10 @@ class ComRegister {
394
400
  okGuild = await checkIfGuildHasJoined(this.redBot);
395
401
  break;
396
402
  }
403
+ case 'satori': {
404
+ okGuild = await checkIfGuildHasJoined(this.satoriBot);
405
+ break;
406
+ }
397
407
  default: {
398
408
  // 发送错误提示并返回
399
409
  session.send('您尚未配置任何QQ群相关机器人,不能对QQ群进行操作');
@@ -472,7 +482,6 @@ class ComRegister {
472
482
  });
473
483
  biliCom
474
484
  .subcommand('.dynamic <uid:string> <...guildId:string>', '订阅用户动态推送', { hidden: true })
475
- // .option('bot', '-b <type:string>')
476
485
  .usage('订阅用户动态推送')
477
486
  .example('bili dynamic 1194210119 订阅UID为1194210119的动态')
478
487
  .action(async ({ session }, uid, ...guildId) => {
@@ -482,10 +491,6 @@ class ComRegister {
482
491
  return `${uid}非法调用 dynamic 指令`; // 用户uid不能为空
483
492
  if (!guildId)
484
493
  return `${uid}非法调用 dynamic 指令`; // 目标群组或频道不能为空
485
- /* if (!options.bot) {
486
- this.logger.warn(`${uid}非法调用 dynamic 指令,未传入订阅平台`)
487
- return `${uid}非法调用 dynamic 指令`
488
- } */
489
494
  // 寻找对应订阅管理对象
490
495
  const index = this.subManager.findIndex(sub => sub.uid === uid);
491
496
  // 不存在则直接返回
@@ -509,6 +514,9 @@ class ComRegister {
509
514
  case 'telegram':
510
515
  bot = this.telegramBot;
511
516
  break;
517
+ case 'satori':
518
+ bot = this.satoriBot;
519
+ break;
512
520
  default: {
513
521
  this.logger.warn(`${uid}非法调用 dynamic 指令,不支持该平台`);
514
522
  return '非法调用';
@@ -521,7 +529,6 @@ class ComRegister {
521
529
  });
522
530
  biliCom
523
531
  .subcommand('.live <roomId:string> <...guildId:string>', '订阅主播开播通知', { hidden: true })
524
- // .option('bot', '-b <type:string>')
525
532
  .usage('订阅主播开播通知')
526
533
  .example('bili live 26316137 订阅房间号为26316137的直播间')
527
534
  .action(async ({ session }, roomId, ...guildId) => {
@@ -531,10 +538,6 @@ class ComRegister {
531
538
  return `${roomId}非法调用 dynamic 指令`; // 订阅主播房间号不能为空
532
539
  if (!guildId)
533
540
  return `${roomId}非法调用 dynamic 指令`; // 目标群组或频道不能为空
534
- /* if (!options.bot) {
535
- this.logger.warn(`${roomId}非法调用 dynamic 指令,未传入推送平台`)
536
- return `${roomId}非法调用 dynamic 指令`
537
- } */
538
541
  // 要订阅的对象不在订阅管理对象中,直接返回
539
542
  const index = this.subManager.findIndex(sub => sub.roomId === roomId);
540
543
  if (index === -1)
@@ -557,6 +560,9 @@ class ComRegister {
557
560
  case 'telegram':
558
561
  bot = this.telegramBot;
559
562
  break;
563
+ case 'satori':
564
+ bot = this.satoriBot;
565
+ break;
560
566
  default: {
561
567
  this.logger.warn(`${roomId}非法调用 dynamic 指令,不支持该平台`);
562
568
  return `${roomId}非法调用 dynamic 指令`;
@@ -661,6 +667,11 @@ class ComRegister {
661
667
  // 定义变量
662
668
  let pic;
663
669
  let buffer;
670
+ // 从动态数据中取出UP主名称和动态ID
671
+ const upName = content.data.items[num].modules.module_author.name;
672
+ const dynamicId = content.data.items[num].id_str;
673
+ // 判断是否需要发送URL
674
+ const dUrl = this.config.dynamicUrl ? `${upName}发布了一条动态:https://t.bilibili.com/${dynamicId}` : '';
664
675
  // 获取动态推送图片
665
676
  try {
666
677
  // 渲染图片
@@ -674,18 +685,22 @@ class ComRegister {
674
685
  break;
675
686
  if (e.message === '出现关键词,屏蔽该动态') {
676
687
  // 如果需要发送才发送
677
- this.config.filter.notify && await this.sendMsg(guildId, bot, `UID:${uid} 发布了一条含有屏蔽关键字的动态`);
688
+ this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条含有屏蔽关键字的动态`);
689
+ break;
690
+ }
691
+ if (e.message === '已屏蔽转发动态') {
692
+ this.config.filter.notify && await this.sendMsg(guildId, bot, `${upName}发布了一条转发动态,已屏蔽`);
678
693
  break;
679
694
  }
680
695
  }
681
696
  // 如果pic存在,则直接返回pic
682
697
  if (pic) {
683
698
  // pic存在,使用的是render模式
684
- await this.sendMsg(guildId, bot, pic);
699
+ await this.sendMsg(guildId, bot, pic + ' ' + dUrl);
685
700
  }
686
701
  else {
687
702
  // pic不存在,说明使用的是page模式
688
- await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png'));
703
+ await this.sendMsg(guildId, bot, koishi_1.h.image(buffer, 'image/png' + ' ' + dUrl));
689
704
  }
690
705
  // 如果成功,那么跳出循环
691
706
  break;
@@ -952,14 +967,19 @@ class ComRegister {
952
967
  this.subNotifier = ctx.notifier.create(table);
953
968
  }
954
969
  async getSubFromDatabase(ctx) {
970
+ this.logger.info('开始执行数据库读取操作');
955
971
  // 如果未登录,则直接返回
956
972
  if (!(await this.checkIfIsLogin(ctx)))
957
973
  return;
974
+ this.logger.info('已登录账号');
958
975
  // 已存在订阅管理对象,不再进行订阅操作
959
976
  if (this.subManager.length !== 0)
960
977
  return;
978
+ this.logger.info('不存在订阅管理对象');
961
979
  // 从数据库中获取数据
962
980
  const subData = await ctx.database.get('bilibili', { id: { $gt: 0 } });
981
+ this.logger.info('已从数据库获取到数据,数据为:');
982
+ this.logger.info(subData);
963
983
  // 设定订阅数量
964
984
  this.num = subData.length;
965
985
  // 如果订阅数量超过三个则数据库被非法修改
@@ -979,6 +999,8 @@ class ComRegister {
979
999
  if (!sub.dynamic && !sub.live) { // 存在未订阅任何项目的数据
980
1000
  // 删除该条数据
981
1001
  ctx.database.remove('bilibili', { id: sub.id });
1002
+ // log
1003
+ this.logger.warn(`UID:${sub.uid} 该条数据没有任何订阅数据,自动取消订阅`);
982
1004
  // 跳过下面的步骤
983
1005
  continue;
984
1006
  }
@@ -999,9 +1021,14 @@ class ComRegister {
999
1021
  case 'telegram':
1000
1022
  bot = this.telegramBot;
1001
1023
  break;
1024
+ case 'satori':
1025
+ bot = this.satoriBot;
1026
+ break;
1002
1027
  default: {
1003
1028
  // 本条数据被篡改,删除该条订阅
1004
1029
  ctx.database.remove('bilibili', { id: sub.id });
1030
+ // 不支持的协议
1031
+ this.logger.info(`UID:${sub.uid} 出现不支持的协议,该条数据被篡改,自动取消订阅`);
1005
1032
  // 继续下个循环
1006
1033
  continue;
1007
1034
  }
@@ -1014,7 +1041,10 @@ class ComRegister {
1014
1041
  let attempts = 3;
1015
1042
  for (let i = 0; i < attempts; i++) {
1016
1043
  try {
1044
+ // 获取用户信息
1017
1045
  content = await ctx.biliAPI.getUserInfo(sub.uid);
1046
+ // log
1047
+ this.logger.info(`UID:${sub.uid} 获取到用户信息`);
1018
1048
  // 成功则跳出循环
1019
1049
  break;
1020
1050
  }
@@ -1044,17 +1074,24 @@ class ComRegister {
1044
1074
  }
1045
1075
  case -400:
1046
1076
  case -404:
1047
- default:
1077
+ default: {
1048
1078
  await deleteSub();
1079
+ // log
1080
+ this.logger.info(`UID:${sub.uid} 数据出现问题,自动取消订阅`);
1049
1081
  return;
1082
+ }
1050
1083
  }
1051
1084
  }
1052
1085
  // 检测房间号是否被篡改
1053
1086
  if (sub.live && (!data.live_room || data.live_room.roomid.toString() !== sub.room_id)) {
1054
1087
  // 房间号被篡改,删除该订阅
1055
1088
  await deleteSub();
1089
+ // log
1090
+ this.logger.info(`UID:${sub.uid} 房间号被篡改,自动取消订阅`);
1056
1091
  return;
1057
1092
  }
1093
+ // log
1094
+ this.logger.info(`UID:${sub.uid} 开始构建订阅对象`);
1058
1095
  // 构建订阅对象
1059
1096
  let subManagerItem = {
1060
1097
  id: sub.id,
@@ -1067,24 +1104,34 @@ class ComRegister {
1067
1104
  liveDispose: null,
1068
1105
  dynamicDispose: null
1069
1106
  };
1107
+ // log
1108
+ this.logger.info(`UID:${sub.uid} 订阅对象构建成功,开始进行订阅操作`);
1070
1109
  // 判断需要订阅的服务
1071
1110
  if (sub.dynamic) { // 需要订阅动态
1072
1111
  // 开始循环检测
1073
1112
  const dispose = ctx.setInterval(this.dynamicDetect(ctx, bot, sub.uid, targetArr), this.config.dynamicLoopTime * 1000);
1074
1113
  // 保存销毁函数
1075
1114
  subManagerItem.dynamicDispose = dispose;
1115
+ // log
1116
+ this.logger.info(`UID:${sub.uid} 成功订阅动态`);
1076
1117
  }
1077
- if (sub.live) { // 需要订阅动态
1118
+ if (sub.live) { // 需要订阅直播
1078
1119
  // 开始循环检测
1079
1120
  const dispose = ctx.setInterval(this.liveDetect(ctx, bot, sub.room_id, targetArr), this.config.liveLoopTime * 1000);
1080
1121
  // 保存销毁函数
1081
1122
  subManagerItem.liveDispose = dispose;
1123
+ // log
1124
+ this.logger.info(`UID:${sub.uid} 成功订阅直播`);
1082
1125
  }
1083
1126
  // 保存新订阅对象
1084
1127
  this.subManager.push(subManagerItem);
1128
+ // log
1129
+ this.logger.info(`UID:${sub.uid} 成功保存订阅对象`);
1085
1130
  }
1086
1131
  // 在控制台中显示订阅对象
1087
1132
  this.updateSubNotifier(ctx);
1133
+ // log
1134
+ this.logger.info(`数据库读取操作已完成`);
1088
1135
  }
1089
1136
  unsubSingle(ctx, id /* UID或RoomId */, type /* 0取消Live订阅,1取消Dynamic订阅 */) {
1090
1137
  let index;
@@ -1167,13 +1214,14 @@ class ComRegister {
1167
1214
  liveLoopTime: koishi_1.Schema.number().default(10),
1168
1215
  customLiveStart: koishi_1.Schema.string().required(),
1169
1216
  customLiveEnd: koishi_1.Schema.string().required(),
1217
+ dynamicUrl: koishi_1.Schema.boolean().required(),
1170
1218
  dynamicLoopTime: koishi_1.Schema.number().default(60),
1171
1219
  dynamicCheckNumber: koishi_1.Schema.number().required(),
1172
1220
  filter: koishi_1.Schema.object({
1173
1221
  enable: koishi_1.Schema.boolean(),
1222
+ notify: koishi_1.Schema.boolean(),
1174
1223
  regex: koishi_1.Schema.string(),
1175
1224
  keywords: koishi_1.Schema.array(String),
1176
- notify: koishi_1.Schema.boolean(),
1177
1225
  }),
1178
1226
  });
1179
1227
  })(ComRegister || (ComRegister = {}));
Binary file
@@ -35,8 +35,10 @@ declare namespace GenerateImg {
35
35
  renderType: number;
36
36
  filter: {
37
37
  enable: boolean;
38
+ notify: boolean;
38
39
  regex: string;
39
40
  keywords: Array<string>;
41
+ forward: boolean;
40
42
  };
41
43
  removeBorder: boolean;
42
44
  cardColorStart: string;
@@ -262,7 +262,7 @@ class GenerateImg extends koishi_1.Service {
262
262
  }
263
263
  }, '');
264
264
  // 关键字和正则屏蔽
265
- if (this.giConfig.filter.enable) { // 开启关键字和正则屏蔽
265
+ if (this.giConfig.filter.enable) { // 开启动态屏蔽功能
266
266
  if (this.giConfig.filter.regex) { // 正则屏蔽
267
267
  const reg = new RegExp(this.giConfig.filter.regex);
268
268
  if (reg.test(richText))
@@ -317,6 +317,9 @@ class GenerateImg extends koishi_1.Service {
317
317
  basicDynamic();
318
318
  // 转发动态
319
319
  if (dynamicMajorData.type === DYNAMIC_TYPE_FORWARD) {
320
+ //转发动态屏蔽
321
+ if (this.giConfig.filter.enable && this.giConfig.filter.forward)
322
+ throw new Error('已屏蔽转发动态');
320
323
  // User info
321
324
  const forward_module_author = dynamicMajorData.orig.modules.module_author;
322
325
  const forwardUserAvatarUrl = forward_module_author.face;
@@ -1365,9 +1368,10 @@ class GenerateImg extends koishi_1.Service {
1365
1368
  renderType: koishi_1.Schema.number(),
1366
1369
  filter: koishi_1.Schema.object({
1367
1370
  enable: koishi_1.Schema.boolean(),
1371
+ notify: koishi_1.Schema.boolean(),
1368
1372
  regex: koishi_1.Schema.string(),
1369
1373
  keywords: koishi_1.Schema.array(String),
1370
- notify: koishi_1.Schema.boolean(),
1374
+ forward: koishi_1.Schema.boolean()
1371
1375
  }),
1372
1376
  removeBorder: koishi_1.Schema.boolean(),
1373
1377
  cardColorStart: koishi_1.Schema.string(),
package/lib/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export interface Config {
8
8
  unlockSubLimits: boolean;
9
9
  renderType: 'render' | 'page';
10
10
  dynamic: {};
11
+ dynamicUrl: boolean;
11
12
  dynamicCheckNumber: number;
12
13
  dynamicLoopTime: '1分钟' | '2分钟' | '3分钟' | '5分钟';
13
14
  live: {};
package/lib/index.js CHANGED
@@ -55,6 +55,9 @@ exports.Config = koishi_1.Schema.object({
55
55
  .default('render')
56
56
  .description('渲染类型,默认为render模式,渲染速度更快,但会出现乱码问题,若出现乱码问题,请切换到page模式。若使用自定义字体,建议选择render模式'),
57
57
  dynamic: koishi_1.Schema.object({}).description('动态推送设置'),
58
+ dynamicUrl: koishi_1.Schema.boolean()
59
+ .default(false)
60
+ .description('发送动态时是否同时发送链接。注意:如果使用的是QQ官方机器人不能开启此项!'),
58
61
  dynamicCheckNumber: koishi_1.Schema.number()
59
62
  .min(2)
60
63
  .max(10)
@@ -78,11 +81,9 @@ exports.Config = koishi_1.Schema.object({
78
81
  .description('设定隔多长时间推送一次直播状态,单位为小时,默认为一小时'),
79
82
  customLiveStart: koishi_1.Schema.string()
80
83
  .default('-name开播啦')
81
- .experimental()
82
84
  .description('自定义开播提示语,-name代表UP昵称。例如-name开播啦,会发送为xxxUP开播啦'),
83
85
  customLiveEnd: koishi_1.Schema.string()
84
86
  .default('-name下播啦,本次直播了-time')
85
- .experimental()
86
87
  .description('自定义下播提示语,-name代表UP昵称,-time代表开播时长。例如-name下播啦,本次直播了-time,会发送为xxxUP下播啦,直播时长为xx小时xx分钟xx秒'),
87
88
  style: koishi_1.Schema.object({}).description('美化设置'),
88
89
  removeBorder: koishi_1.Schema.boolean()
@@ -105,18 +106,21 @@ exports.Config = koishi_1.Schema.object({
105
106
  koishi_1.Schema.object({
106
107
  enable: koishi_1.Schema.boolean()
107
108
  .default(false)
108
- .description('是否开启动态关键字屏蔽功能')
109
- .experimental()
109
+ .description('是否开启动态屏蔽功能')
110
110
  }).description('屏蔽设置'),
111
111
  koishi_1.Schema.union([
112
112
  koishi_1.Schema.object({
113
113
  enable: koishi_1.Schema.const(true).required().experimental(),
114
+ notify: koishi_1.Schema.boolean()
115
+ .default(false)
116
+ .description('动态被屏蔽是否发送提示'),
114
117
  regex: koishi_1.Schema.string()
115
118
  .description('正则表达式屏蔽'),
116
119
  keywords: koishi_1.Schema.array(String)
117
120
  .description('关键字屏蔽,一个关键字为一项'),
118
- notify: koishi_1.Schema.boolean()
119
- .description('动态被屏蔽是否发送提示')
121
+ forward: koishi_1.Schema.boolean()
122
+ .default(false)
123
+ .description("是否屏蔽转发动态"),
120
124
  }),
121
125
  koishi_1.Schema.object({})
122
126
  ])
@@ -165,6 +169,7 @@ function apply(ctx, config) {
165
169
  ctx.plugin(Database);
166
170
  // Regist server
167
171
  ctx.plugin(wbi_1.default, { key: config.key });
172
+ ctx.plugin(biliAPI_1.default);
168
173
  ctx.plugin(generateImg_1.default, {
169
174
  renderType,
170
175
  filter: config.filter,
@@ -174,9 +179,6 @@ function apply(ctx, config) {
174
179
  enableLargeFont: config.enableLargeFont,
175
180
  font: config.font
176
181
  });
177
- ctx.plugin(biliAPI_1.default);
178
- // load plugin
179
- // ctx.plugin(Authority)
180
182
  ctx.plugin(comRegister_1.default, {
181
183
  unlockSubLimits: config.unlockSubLimits,
182
184
  liveStartAtAll: config.liveStartAtAll,
@@ -185,6 +187,7 @@ function apply(ctx, config) {
185
187
  customLiveEnd: config.customLiveEnd,
186
188
  dynamicCheckNumber: config.dynamicCheckNumber,
187
189
  dynamicLoopTime,
190
+ dynamicUrl: config.dynamicUrl,
188
191
  filter: config.filter
189
192
  });
190
193
  // 当用户输入“恶魔兔,启动!”时,执行 help 指令
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.0-rc.5",
4
+ "version": "1.2.1",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
package/readme.md CHANGED
@@ -110,9 +110,11 @@
110
110
  - ver 1.2.0-rc.0 现已支持自定义开播和下播提示语(实验性)
111
111
  - ver 1.2.0-rc.1 现已支持Telegram平台(实验性)
112
112
  - ver 1.2.0-rc.2 添加更多日志输出
113
- - ver 1.2.0-rc.3 针对Telegram的Bug测试版本
114
- - ver 1.2.0-rc.4 修复了一个订阅指令的bug
113
+ - ver 1.2.0-rc.3 针对Telegram的bug测试版本
114
+ - ver 1.2.0-rc.4 修复了订阅指令的一个bug
115
115
  - ver 1.2.0-rc.5 屏蔽动态设置新增是否发送动态被屏蔽消息的选项
116
+ - ver 1.2.0 添加屏蔽转发动态功能,添加发送动态卡片时附带文本信息和动态链接功能,支持订阅哔哩哔哩番剧出差
117
+ - ver 1.2.1 现已支持Satori平台(实验性)
116
118
 
117
119
  ## 交流群
118
120
  801338523 使用问题或bug都可以在群里提出