koishi-plugin-bilibili-notify 1.2.0-alpha.4 → 1.2.0-rc.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.
@@ -38,6 +38,8 @@ declare namespace ComRegister {
38
38
  liveStartAtAll: boolean;
39
39
  pushTime: number;
40
40
  liveLoopTime: number;
41
+ customLiveStart: string;
42
+ customLiveEnd: string;
41
43
  dynamicLoopTime: number;
42
44
  dynamicCheckNumber: number;
43
45
  }
@@ -293,6 +293,14 @@ class ComRegister {
293
293
  .example('bili sub 1194210119 目标QQ群号(实验性) -l -d 订阅UID为1194210119的UP主的动态和直播')
294
294
  .action(async ({ session, options }, mid, ...guildId) => {
295
295
  this.logger.info('调用bili.sub指令');
296
+ // 检查是否是不支持的平台
297
+ switch (session.event.platform) {
298
+ case 'red':
299
+ case 'onebot':
300
+ case 'qq':
301
+ case 'qqguild': break;
302
+ default: return '暂不支持该平台';
303
+ }
296
304
  // 检查是否登录
297
305
  if (!(await this.checkIfIsLogin(ctx))) {
298
306
  // 未登录直接返回
@@ -660,8 +668,9 @@ class ComRegister {
660
668
  break;
661
669
  }
662
670
  catch (e) {
671
+ this.logger.error('dynamicDetect generateLiveImg() 推送卡片发送失败,原因:' + e.toString());
663
672
  if (i === attempts - 1) { // 如果已经尝试了三次,那么抛出错误
664
- throw e;
673
+ return this.sendMsg(guildId, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
665
674
  }
666
675
  }
667
676
  }
@@ -709,9 +718,9 @@ class ComRegister {
709
718
  break;
710
719
  }
711
720
  catch (e) {
712
- this.logger.error('liveDetect generateLiveImg() 推送卡片发送失败');
721
+ this.logger.error('liveDetect generateLiveImg() 推送卡片发送失败,原因:' + e.toString());
713
722
  if (i === attempts - 1) { // 已尝试三次
714
- return this.sendMsg(guildId, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然会发生该错误,请向作者反馈');
723
+ return this.sendMsg(guildId, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
715
724
  }
716
725
  }
717
726
  }
@@ -783,8 +792,12 @@ class ComRegister {
783
792
  open = false;
784
793
  // 下播了将定时器清零
785
794
  timer = 0;
795
+ // 定义下播通知消息
796
+ let liveEndMsg = this.config.customLiveEnd
797
+ .replace('-name', uData.info.uname)
798
+ .replace('-time', await ctx.gimg.getTimeDifference(liveTime));
786
799
  // 发送下播通知
787
- await this.sendMsg(guildId, bot, `${uData.info.uname}下播啦,本次直播了${await ctx.gimg.getTimeDifference(liveTime)}`);
800
+ await this.sendMsg(guildId, bot, liveEndMsg);
788
801
  }
789
802
  // 未进循环,还未开播,继续循环
790
803
  break;
@@ -815,12 +828,19 @@ class ComRegister {
815
828
  }
816
829
  // 主播信息不会变,开播时刷新一次即可
817
830
  uData = userData;
831
+ // 定义开播通知语
832
+ let liveStartMsg = this.config.customLiveStart
833
+ .replace('-name', uData.info.uname)
834
+ .replace('-time', await ctx.gimg.getTimeDifference(liveTime));
818
835
  // 发送直播通知卡片
819
836
  await sendLiveNotifyCard(data, uData, LiveType.StartBroadcasting);
820
837
  // 判断是否需要@全体成员
821
838
  if (this.config.liveStartAtAll) {
822
839
  // 发送@全体成员通知
823
- await this.sendMsg(guildId, bot, (0, jsx_runtime_1.jsx)("at", { type: "all" }));
840
+ await this.sendMsg(guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("at", { type: "all" }), " ", liveStartMsg, " "] }));
841
+ }
842
+ else {
843
+ await this.sendMsg(guildId, bot, liveStartMsg);
824
844
  }
825
845
  }
826
846
  else { // 还在直播
@@ -910,18 +930,23 @@ class ComRegister {
910
930
  }
911
931
  async getSubFromDatabase(ctx) {
912
932
  // 如果未登录,则直接返回
933
+ this.logger.info('Login info:', await this.checkIfIsLogin(ctx));
913
934
  if (!(await this.checkIfIsLogin(ctx)))
914
935
  return;
915
936
  // 已存在订阅管理对象,不再进行订阅操作
937
+ this.logger.info('Sub Manager num:', this.subManager.length);
916
938
  if (this.subManager.length !== 0)
917
939
  return;
918
940
  // 从数据库中获取数据
919
941
  const subData = await ctx.database.get('bilibili', { id: { $gt: 0 } });
942
+ this.logger.info('Sub object:');
943
+ this.logger.info(subData);
920
944
  // 设定订阅数量
921
945
  this.num = subData.length;
922
- // 如果订阅数量超过三个则被非法修改数据库
923
- // 在控制台提示重新订阅
946
+ this.logger.info('Sub number:' + this.num);
947
+ // 如果订阅数量超过三个则数据库被非法修改
924
948
  if (!this.config.unlockSubLimits && this.num > 3) {
949
+ // 在控制台提示重新订阅
925
950
  ctx.notifier.create({
926
951
  type: 'danger',
927
952
  content: '您未解锁订阅限制,且订阅数大于3人,请您手动删除bilibili表中多余的数据后重启本插件'
@@ -930,6 +955,8 @@ class ComRegister {
930
955
  }
931
956
  // 循环遍历
932
957
  for (const sub of subData) {
958
+ this.logger.info('Single sub obj:');
959
+ this.logger.info(sub);
933
960
  // 定义Bot
934
961
  let bot;
935
962
  // 判断是否存在没有任何订阅的数据
@@ -1118,6 +1145,8 @@ class ComRegister {
1118
1145
  liveStartAtAll: koishi_1.Schema.boolean().required(),
1119
1146
  pushTime: koishi_1.Schema.number().required(),
1120
1147
  liveLoopTime: koishi_1.Schema.number().default(10),
1148
+ customLiveStart: koishi_1.Schema.string().required(),
1149
+ customLiveEnd: koishi_1.Schema.string().required(),
1121
1150
  dynamicLoopTime: koishi_1.Schema.number().default(60),
1122
1151
  dynamicCheckNumber: koishi_1.Schema.number().required()
1123
1152
  });
package/lib/database.js CHANGED
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.apply = exports.name = void 0;
3
+ exports.name = void 0;
4
+ exports.apply = apply;
4
5
  exports.name = 'Database';
5
6
  function apply(ctx) {
6
7
  // 新增LoginBili表
7
8
  ctx.model.extend('loginBili', {
8
9
  id: 'unsigned',
9
- bili_cookies: 'string',
10
- bili_refresh_token: 'string'
10
+ bili_cookies: 'text',
11
+ bili_refresh_token: 'text'
11
12
  });
12
13
  // 新增Bilibili表
13
14
  ctx.model.extend('bilibili', {
@@ -22,4 +23,3 @@ function apply(ctx) {
22
23
  time: 'timestamp'
23
24
  }, { autoInc: true });
24
25
  }
25
- exports.apply = apply;
@@ -185,30 +185,41 @@ class GenerateImg extends koishi_1.Service {
185
185
  </body>
186
186
  </html>
187
187
  `;
188
- // 判断渲染方式
189
- if (this.giConfig.renderType) { // 为1则为真,进入page模式
190
- const htmlPath = 'file://' + __dirname.replaceAll('\\', '/') + '/page/0.html';
191
- const page = await this.ctx.puppeteer.page();
192
- await page.goto(htmlPath);
193
- await page.setContent(html, { waitUntil: 'networkidle0' });
194
- const elementHandle = await page.$('html');
195
- const boundingBox = await elementHandle.boundingBox();
196
- const buffer = await page.screenshot({
197
- type: 'png',
198
- clip: {
199
- x: boundingBox.x,
200
- y: boundingBox.y,
201
- width: boundingBox.width,
202
- height: boundingBox.height
188
+ // 多次尝试生成图片
189
+ let attempts = 3;
190
+ for (let i = 0; i < attempts; i++) {
191
+ try {
192
+ // 判断渲染方式
193
+ if (this.giConfig.renderType) { // 为1则为真,进入page模式
194
+ const htmlPath = 'file://' + __dirname.replaceAll('\\', '/') + '/page/0.html';
195
+ const page = await this.ctx.puppeteer.page();
196
+ await page.goto(htmlPath);
197
+ await page.setContent(html, { waitUntil: 'networkidle0' });
198
+ const elementHandle = await page.$('html');
199
+ const boundingBox = await elementHandle.boundingBox();
200
+ const buffer = await page.screenshot({
201
+ type: 'png',
202
+ clip: {
203
+ x: boundingBox.x,
204
+ y: boundingBox.y,
205
+ width: boundingBox.width,
206
+ height: boundingBox.height
207
+ }
208
+ });
209
+ await elementHandle.dispose();
210
+ await page.close();
211
+ return { buffer };
212
+ }
213
+ // 使用render模式渲染
214
+ const pic = await this.ctx.puppeteer.render(html);
215
+ return { pic };
216
+ }
217
+ catch (e) {
218
+ if (i === attempts - 1) { // 已尝试三次
219
+ throw new Error('生成图片失败!错误: ' + e.toString());
203
220
  }
204
- });
205
- await elementHandle.dispose();
206
- await page.close();
207
- return { buffer };
221
+ }
208
222
  }
209
- // 使用render模式渲染
210
- const pic = await this.ctx.puppeteer.render(html);
211
- return { pic };
212
223
  }
213
224
  async generateDynamicImg(data) {
214
225
  // module_author
@@ -1257,30 +1268,41 @@ class GenerateImg extends koishi_1.Service {
1257
1268
  </body>
1258
1269
  </html>
1259
1270
  `;
1260
- // 判断渲染方式
1261
- if (this.giConfig.renderType) { // 为1则为真,进入page模式
1262
- const htmlPath = 'file://' + __dirname.replaceAll('\\', '/') + '/page/0.html';
1263
- const page = await this.ctx.puppeteer.page();
1264
- await page.goto(htmlPath);
1265
- await page.setContent(html, { waitUntil: 'networkidle0' });
1266
- const elementHandle = await page.$('html');
1267
- const boundingBox = await elementHandle.boundingBox();
1268
- const buffer = await page.screenshot({
1269
- type: 'png',
1270
- clip: {
1271
- x: boundingBox.x,
1272
- y: boundingBox.y,
1273
- width: boundingBox.width,
1274
- height: boundingBox.height
1271
+ // 多次尝试生成图片
1272
+ let attempts = 3;
1273
+ for (let i = 0; i < attempts; i++) {
1274
+ try {
1275
+ // 判断渲染方式
1276
+ if (this.giConfig.renderType) { // 为1则为真,进入page模式
1277
+ const htmlPath = 'file://' + __dirname.replaceAll('\\', '/') + '/page/0.html';
1278
+ const page = await this.ctx.puppeteer.page();
1279
+ await page.goto(htmlPath);
1280
+ await page.setContent(html, { waitUntil: 'networkidle0' });
1281
+ const elementHandle = await page.$('html');
1282
+ const boundingBox = await elementHandle.boundingBox();
1283
+ const buffer = await page.screenshot({
1284
+ type: 'png',
1285
+ clip: {
1286
+ x: boundingBox.x,
1287
+ y: boundingBox.y,
1288
+ width: boundingBox.width,
1289
+ height: boundingBox.height
1290
+ }
1291
+ });
1292
+ await elementHandle.dispose();
1293
+ await page.close();
1294
+ return { buffer, link };
1295
+ }
1296
+ // 使用render模式渲染
1297
+ const pic = await this.ctx.puppeteer.render(html);
1298
+ return { pic, link };
1299
+ }
1300
+ catch (e) {
1301
+ if (i === attempts - 1) { // 已尝试三次
1302
+ throw new Error('生成图片失败!错误: ' + e.toString());
1275
1303
  }
1276
- });
1277
- await elementHandle.dispose();
1278
- await page.close();
1279
- return { buffer, link };
1304
+ }
1280
1305
  }
1281
- // 使用render模式渲染
1282
- const pic = await this.ctx.puppeteer.render(html);
1283
- return { pic, link };
1284
1306
  }
1285
1307
  async getLiveStatus(time, liveStatus) {
1286
1308
  let titleStatus;
package/lib/index.d.ts CHANGED
@@ -6,18 +6,22 @@ export interface Config {
6
6
  key: string;
7
7
  basicSettings: {};
8
8
  unlockSubLimits: boolean;
9
- liveStartAtAll: boolean;
10
- pushTime: number;
9
+ renderType: 'render' | 'page';
10
+ dynamic: {};
11
11
  dynamicCheckNumber: number;
12
12
  dynamicLoopTime: '1分钟' | '2分钟' | '3分钟' | '5分钟';
13
- renderType: 'render' | 'page';
14
- filter: {};
13
+ live: {};
14
+ pushTime: number;
15
+ liveStartAtAll: boolean;
16
+ customLiveStart: string;
17
+ customLiveEnd: string;
15
18
  style: {};
16
19
  removeBorder: boolean;
17
20
  cardColorStart: string;
18
21
  cardColorEnd: string;
19
22
  enableLargeFont: boolean;
20
23
  font: string;
24
+ filter: {};
21
25
  }
22
26
  export declare const Config: Schema<Config>;
23
27
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -26,7 +26,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.apply = exports.Config = exports.name = exports.inject = void 0;
29
+ exports.Config = exports.name = exports.inject = void 0;
30
+ exports.apply = apply;
30
31
  const koishi_1 = require("koishi");
31
32
  // import plugins
32
33
  // import Authority from './authority'
@@ -49,15 +50,11 @@ exports.Config = koishi_1.Schema.object({
49
50
  unlockSubLimits: koishi_1.Schema.boolean()
50
51
  .default(false)
51
52
  .description('解锁3个订阅限制,默认只允许订阅3位UP主。订阅过多用户可能有导致IP暂时被封禁的风险'),
52
- liveStartAtAll: koishi_1.Schema.boolean()
53
- .default(false)
54
- .description('直播开始时艾特全体成员,默认关闭'),
55
- pushTime: koishi_1.Schema.number()
56
- .min(0)
57
- .max(12)
58
- .step(0.5)
59
- .default(1)
60
- .description('设定隔多长时间推送一次直播状态,单位为小时,默认为一小时'),
53
+ renderType: koishi_1.Schema.union(['render', 'page'])
54
+ .role('')
55
+ .default('render')
56
+ .description('渲染类型,默认为render模式,渲染速度更快,但会出现乱码问题,若出现乱码问题,请切换到page模式。若使用自定义字体,建议选择render模式'),
57
+ dynamic: koishi_1.Schema.object({}).description('动态推送设置'),
61
58
  dynamicCheckNumber: koishi_1.Schema.number()
62
59
  .min(2)
63
60
  .max(10)
@@ -69,10 +66,41 @@ exports.Config = koishi_1.Schema.object({
69
66
  .role('')
70
67
  .default('2分钟')
71
68
  .description('设定多久检测一次动态。若需动态的时效性,可以设置为1分钟。若订阅的UP主经常在短时间内连着发多条动态应该将该值提高,否则会出现动态漏推送和晚推送的问题,默认值为2分钟'),
72
- renderType: koishi_1.Schema.union(['render', 'page'])
73
- .role('')
74
- .default('render')
75
- .description('渲染类型,默认为render模式,渲染速度更快,但会出现乱码问题,若出现乱码问题,请切换到page模式。若使用自定义字体,建议选择render模式'),
69
+ live: koishi_1.Schema.object({}).description('直播推送设置'),
70
+ liveStartAtAll: koishi_1.Schema.boolean()
71
+ .default(false)
72
+ .description('直播开始时艾特全体成员,默认关闭'),
73
+ pushTime: koishi_1.Schema.number()
74
+ .min(0)
75
+ .max(12)
76
+ .step(0.5)
77
+ .default(1)
78
+ .description('设定隔多长时间推送一次直播状态,单位为小时,默认为一小时'),
79
+ customLiveStart: koishi_1.Schema.string()
80
+ .default('-name开播啦')
81
+ .experimental()
82
+ .description('自定义开播提示语,-name代表UP昵称。例如-name开播啦,会发送为xxxUP开播啦'),
83
+ customLiveEnd: koishi_1.Schema.string()
84
+ .default('-name下播啦,本次直播了-time')
85
+ .experimental()
86
+ .description('自定义下播提示语,-name代表UP昵称,-time代表开播时长。例如-name下播啦,本次直播了-time,会发送为xxxUP下播啦,直播时长为xx小时xx分钟xx秒'),
87
+ style: koishi_1.Schema.object({}).description('美化设置'),
88
+ removeBorder: koishi_1.Schema.boolean()
89
+ .default(false)
90
+ .description('移除推送卡片边框'),
91
+ cardColorStart: koishi_1.Schema.string()
92
+ .pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
93
+ .default('#F38AB5')
94
+ .description('推送卡片的开始渐变背景色,请填入16进制颜色代码,参考网站:https://webkul.github.io/coolhue/'),
95
+ cardColorEnd: koishi_1.Schema.string()
96
+ .pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
97
+ .default('#F9CCDF')
98
+ .description('推送卡片的结束渐变背景色,请填入16进制颜色代码,参考网站:https://colorate.azurewebsites.net/'),
99
+ enableLargeFont: koishi_1.Schema.boolean()
100
+ .default(false)
101
+ .description('是否开启动态推送卡片大字体模式,默认为小字体。小字体更漂亮,但阅读比较吃力,大字体更易阅读,但相对没这么好看'),
102
+ font: koishi_1.Schema.string()
103
+ .description('推送卡片的字体样式,如果你想用你自己的字体可以在此填写,例如:Microsoft YaHei'),
76
104
  filter: koishi_1.Schema.intersect([
77
105
  koishi_1.Schema.object({
78
106
  enable: koishi_1.Schema.boolean()
@@ -91,23 +119,6 @@ exports.Config = koishi_1.Schema.object({
91
119
  koishi_1.Schema.object({})
92
120
  ])
93
121
  ]),
94
- style: koishi_1.Schema.object({}).description('美化设置'),
95
- removeBorder: koishi_1.Schema.boolean()
96
- .default(false)
97
- .description('移除推送卡片边框'),
98
- cardColorStart: koishi_1.Schema.string()
99
- .pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
100
- .default('#F38AB5')
101
- .description('推送卡片的开始渐变背景色,请填入16进制颜色代码,参考网站:https://webkul.github.io/coolhue/'),
102
- cardColorEnd: koishi_1.Schema.string()
103
- .pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
104
- .default('#F9CCDF')
105
- .description('推送卡片的结束渐变背景色,请填入16进制颜色代码,参考网站:https://colorate.azurewebsites.net/'),
106
- enableLargeFont: koishi_1.Schema.boolean()
107
- .default(false)
108
- .description('是否开启动态推送卡片大字体模式,默认为小字体。小字体更漂亮,但阅读比较吃力,大字体更易阅读,但相对没这么好看'),
109
- font: koishi_1.Schema.string()
110
- .description('推送卡片的字体样式,如果你想用你自己的字体可以在此填写,例如:Microsoft YaHei')
111
122
  });
112
123
  function apply(ctx, config) {
113
124
  // 设置提示
@@ -168,6 +179,8 @@ function apply(ctx, config) {
168
179
  unlockSubLimits: config.unlockSubLimits,
169
180
  liveStartAtAll: config.liveStartAtAll,
170
181
  pushTime: config.pushTime,
182
+ customLiveStart: config.customLiveStart,
183
+ customLiveEnd: config.customLiveEnd,
171
184
  dynamicCheckNumber: config.dynamicCheckNumber,
172
185
  dynamicLoopTime
173
186
  });
@@ -181,4 +194,3 @@ function apply(ctx, config) {
181
194
  }
182
195
  });
183
196
  }
184
- exports.apply = apply;
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-alpha.4",
4
+ "version": "1.2.0-rc.0",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
@@ -24,7 +24,7 @@
24
24
  "bilibili"
25
25
  ],
26
26
  "peerDependencies": {
27
- "koishi": "^4.17.1"
27
+ "koishi": "^4.17.2"
28
28
  },
29
29
  "dependencies": {
30
30
  "axios": "^1.6.7",
package/readme.md CHANGED
@@ -105,6 +105,8 @@
105
105
  - ver 1.2.0-alpha.2 支持QQ群多群推送(实验性),修复了一些bug
106
106
  - ver 1.2.0-alpha.3 修复了指定QQ群订阅时的一个bug
107
107
  - ver 1.2.0-alpha.4 对时间获取进行了优化,能够适应不同环境下的时间获取,修复了一些bug
108
+ - ver 1.2.0-alpha.5 修复了与PostgreSQL不兼容的问题,优化了图片推送,增强了推送容错
109
+ - ver 1.2.0-rc.0 现在可以自定义开播和下播提示语了(实验性)
108
110
 
109
111
  ## 感谢
110
112