koishi-plugin-bilibili-notify 1.2.3-rc.9 → 1.2.3

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.
@@ -7,6 +7,8 @@ const jsx_runtime_1 = require("@satorijs/element/jsx-runtime");
7
7
  const koishi_1 = require("koishi");
8
8
  // 导入qrcode
9
9
  const qrcode_1 = __importDefault(require("qrcode"));
10
+ const axios_1 = __importDefault(require("axios"));
11
+ const sharp_1 = __importDefault(require("sharp"));
10
12
  var LiveType;
11
13
  (function (LiveType) {
12
14
  LiveType[LiveType["NotLiveBroadcast"] = 0] = "NotLiveBroadcast";
@@ -116,6 +118,8 @@ class ComRegister {
116
118
  .usage('测试图片生成')
117
119
  .example('test.gimg')
118
120
  .action(async ({ session }, uid, index) => {
121
+ // logger
122
+ this.logger.info('调用test gimg指令')
119
123
  // 获取用户空间动态数据
120
124
  const { data } = await ctx.biliAPI.getUserSpaceDynamic(uid)
121
125
  // 获取动态推送图片
@@ -155,12 +159,23 @@ class ComRegister {
155
159
  .usage('发送下播提示语测试')
156
160
  .example('test livestop')
157
161
  .action(async ({ session }) => {
162
+ // logger
163
+ this.logger.info('调用test gimg指令')
164
+ // 获取主播信息
158
165
  const { data } = await ctx.biliAPI.getMasterInfo('194484313')
159
- console.log(data);
166
+ // 获取图片二进制
167
+ const resp = await axios({
168
+ url: data.info.face,
169
+ method: 'GET',
170
+ responseType: 'arraybuffer'
171
+ })
172
+ // 使用sharp调整图片大小
173
+ const resizedImage = await sharp(resp.data)
174
+ .resize(100, 100)
175
+ .toBuffer()
176
+ // 发送下播提示语
160
177
  await session.send(
161
- <>
162
- <img width="10px" height="10px" src="https://koishi.chat/logo.png" />
163
- </>
178
+ <>{h.image(resizedImage, 'image/png')} 主播{data.info.uname}已下播</>
164
179
  )
165
180
  })
166
181
 
@@ -171,7 +186,7 @@ class ComRegister {
171
186
  .action(async ({ session }) => {
172
187
  // 获得对应bot
173
188
  const bot = this.getTheCorrespondingBotBasedOnTheSession(session)
174
- this.sendMsg(['all'], bot, 'Hello World')
189
+ // this.sendMsg(['all'], bot, 'Hello World')
175
190
  }) */
176
191
  const biliCom = ctx.command('bili', 'bili-notify插件相关指令', { permissions: ['authority:3'] });
177
192
  biliCom.subcommand('.login', '登录B站之后才可以进行之后的操作')
@@ -710,12 +725,18 @@ class ComRegister {
710
725
  }
711
726
  async sendPrivateMsgAndRebootService(ctx, bot, content) {
712
727
  await this.sendPrivateMsg(bot, content);
713
- // 停用插件
714
- ctx.sm.disposePlugin();
715
- // 隔一秒启动插件
716
- ctx.setTimeout(() => {
717
- ctx.sm.registerPlugin();
718
- }, 1000);
728
+ // 重启插件
729
+ const flag = ctx.sm.restartPlugin();
730
+ // 判断是否重启成功
731
+ if (flag) {
732
+ this.logger.info('重启插件成功');
733
+ }
734
+ else {
735
+ // 重启失败,发送消息
736
+ await this.sendPrivateMsg(bot, '已重启插件三次,请检查机器人状态后手动重启');
737
+ // 关闭插件
738
+ ctx.sm.disposePlugin();
739
+ }
719
740
  }
720
741
  async sendMsg(ctx, targets, bot, content) {
721
742
  // 定义需要发送的数组
@@ -782,6 +803,9 @@ class ComRegister {
782
803
  }
783
804
  // 取消订阅
784
805
  this.unsubSingle(ctx, uid, 1); /* 1为取消动态订阅 */
806
+ // 发送取消订阅消息
807
+ await this.sendPrivateMsg(bot, `UID:${uid},已取消订阅动态`);
808
+ // 结束循环
785
809
  return;
786
810
  }
787
811
  // 获取数据内容
@@ -977,8 +1001,18 @@ class ComRegister {
977
1001
  let liveEndMsg = this.config.customLiveEnd
978
1002
  .replace('-name', uData.info.uname)
979
1003
  .replace('-time', await ctx.gimg.getTimeDifference(liveTime));
1004
+ // 获取图片二进制
1005
+ const resp = await (0, axios_1.default)({
1006
+ url: uData.info.face,
1007
+ method: 'GET',
1008
+ responseType: 'arraybuffer'
1009
+ });
1010
+ // 使用sharp调整图片大小
1011
+ const resizedImage = await (0, sharp_1.default)(resp.data)
1012
+ .resize(100, 100)
1013
+ .toBuffer();
980
1014
  // 发送下播通知
981
- await this.sendMsg(ctx, guildId, bot, liveEndMsg);
1015
+ await this.sendMsg(ctx, guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(resizedImage, 'image/png'), " ", liveEndMsg] }));
982
1016
  }
983
1017
  // 未进循环,还未开播,继续循环
984
1018
  break;
@@ -1104,7 +1138,7 @@ class ComRegister {
1104
1138
  let subTableArray = subInfo.split('\n');
1105
1139
  subTableArray.splice(subTableArray.length - 1, 1);
1106
1140
  // 定义Table
1107
- 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 }))) }) });
1141
+ table = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("p", { children: "\u5F53\u524D\u8BA2\u9605\u5BF9\u8C61\uFF1A" }), (0, jsx_runtime_1.jsx)("ul", { children: subTableArray.map(str => ((0, jsx_runtime_1.jsx)("li", { children: str }))) })] });
1108
1142
  }
1109
1143
  // 设置更新后的提示
1110
1144
  this.subNotifier = ctx.notifier.create(table);
@@ -68,40 +68,38 @@ class GenerateImg extends koishi_1.Service {
68
68
  * {
69
69
  margin: 0;
70
70
  padding: 0;
71
+ box-sizing: border-box;
71
72
  font-family: "${this.giConfig.font}", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
72
73
  }
73
-
74
+
74
75
  html {
75
- width: 770px;
76
+ width: 800px;
76
77
  height: auto;
77
78
  }
78
-
79
+
79
80
  .background {
80
- width: 770px;
81
+ width: 100%;
81
82
  height: auto;
83
+ padding: 15px;
82
84
  background: linear-gradient(to right bottom, ${this.giConfig.cardColorStart}, ${this.giConfig.cardColorEnd});
83
85
  overflow: hidden;
84
86
  }
85
-
86
- .card {
87
- width: 740px;
87
+
88
+ .base-plate {
89
+ width: 100%;
88
90
  height: auto;
89
91
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
90
- border-radius: 5px;
91
- margin: 15px auto;
92
- overflow: hidden;
92
+ padding: 15px;
93
+ border-radius: 10px;
93
94
  background-color: #FFF5EE;
94
95
  }
95
-
96
- .base-plate {
97
- ${this.giConfig.removeBorder ? `
98
- width: 740px;
99
- ` : `
100
- width: 704px;
101
- margin: 20px auto;
102
- `}
96
+
97
+ .card {
98
+ width: 100%;
103
99
  height: auto;
104
- border-radius: 10px;
100
+ border-radius: 5px;
101
+ padding: 15px;
102
+ overflow: hidden;
105
103
  background-color: #fff;
106
104
  }
107
105
 
@@ -165,8 +163,8 @@ class GenerateImg extends koishi_1.Service {
165
163
  </head>
166
164
  <body>
167
165
  <div class="background">
168
- <div class="card">
169
- <div class="base-plate">
166
+ <div ${this.giConfig.removeBorder ? '' : 'class="base-plate"'}>
167
+ <div class="card">
170
168
  <img src="${cover ? data.user_cover : data.keyframe}"
171
169
  alt="封面">
172
170
  <div class="card-body">
@@ -321,8 +319,9 @@ class GenerateImg extends koishi_1.Service {
321
319
  // 转发动态
322
320
  if (dynamicMajorData.type === DYNAMIC_TYPE_FORWARD) {
323
321
  //转发动态屏蔽
324
- if (this.giConfig.filter.enable && this.giConfig.filter.forward)
322
+ if (this.giConfig.filter.enable && this.giConfig.filter.forward) {
325
323
  throw new Error('已屏蔽转发动态');
324
+ }
326
325
  // User info
327
326
  const forward_module_author = dynamicMajorData.orig.modules.module_author;
328
327
  const forwardUserAvatarUrl = forward_module_author.face;
@@ -333,7 +332,7 @@ class GenerateImg extends koishi_1.Service {
333
332
  main += `
334
333
  <div class="card-forward">
335
334
  <div class="forward-userinfo">
336
- <img class="forward-avatar" src="${forwardUserAvatarUrl}" alt="">
335
+ <img class="forward-avatar" src="${forwardUserAvatarUrl}" alt="avatar">
337
336
  <span class="forward-username">${forwardUserName} ${forwardInfo ? forwardInfo : ''}</span>
338
337
  </div>
339
338
  <div class="forward-main">
@@ -548,38 +547,35 @@ class GenerateImg extends koishi_1.Service {
548
547
  box-sizing: border-box;
549
548
  font-family: "${this.giConfig.font}", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
550
549
  }
551
-
550
+
552
551
  html {
553
- width: 770px;
552
+ width: 800px;
554
553
  height: auto;
555
554
  }
556
-
555
+
557
556
  .background {
558
- width: 770px;
557
+ width: 100%;
559
558
  height: auto;
559
+ padding: 15px;
560
560
  background: linear-gradient(to right bottom, ${this.giConfig.cardColorStart}, ${this.giConfig.cardColorEnd});
561
561
  overflow: hidden;
562
562
  }
563
-
564
- .card {
565
- width: 740px;
563
+
564
+ .base-plate {
565
+ width: 100%;
566
566
  height: auto;
567
567
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
568
- border-radius: 5px;
569
- margin: 15px auto;
570
- overflow: hidden;
568
+ padding: 15px;
569
+ border-radius: 10px;
571
570
  background-color: #FFF5EE;
572
571
  }
573
-
574
- .base-plate {
575
- ${this.giConfig.removeBorder ? `
576
- width: 740px;
577
- ` : `
578
- width: 704px;
579
- margin: 20px auto;
580
- `}
572
+
573
+ .card {
574
+ width: 100%;
581
575
  height: auto;
582
- border-radius: 10px;
576
+ border-radius: 5px;
577
+ padding: 15px;
578
+ overflow: hidden;
583
579
  background-color: #fff;
584
580
  }
585
581
 
@@ -785,8 +781,8 @@ class GenerateImg extends koishi_1.Service {
785
781
  }
786
782
 
787
783
  .card .card-forward {
788
- margin: 0 -15px 0 -105px;
789
- padding: 12px 15px 14px 105px;
784
+ border-radius: 5px;
785
+ padding: 12px 10px 14px 10px;
790
786
  background-color: #F6F7F8;
791
787
  }
792
788
 
@@ -876,36 +872,38 @@ class GenerateImg extends koishi_1.Service {
876
872
  * {
877
873
  margin: 0;
878
874
  padding: 0;
875
+ box-sizing: border-box;
879
876
  font-family: "${this.giConfig.font}", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
880
877
  }
881
878
 
882
879
  html {
883
- width: 770px;
880
+ width: 800px;
884
881
  height: auto;
885
882
  }
886
883
 
887
884
  .background {
888
- width: 770px;
885
+ width: 100%;
889
886
  height: auto;
887
+ padding: 15px;
890
888
  background: linear-gradient(to right bottom, ${this.giConfig.cardColorStart}, ${this.giConfig.cardColorEnd});
891
889
  overflow: hidden;
892
890
  }
893
-
894
- .card {
895
- width: 740px;
891
+
892
+ .base-plate {
893
+ width: 100%;
896
894
  height: auto;
897
895
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
898
- border-radius: 5px;
899
- margin: 15px auto;
900
- overflow: hidden;
896
+ padding: 15px;
897
+ border-radius: 10px;
901
898
  background-color: #FFF5EE;
902
899
  }
903
900
 
904
- .base-plate {
905
- width: 704px;
901
+ .card {
902
+ width: 100%;
906
903
  height: auto;
907
- margin: 20px auto;
908
- border-radius: 10px;
904
+ border-radius: 5px;
905
+ padding: 15px;
906
+ overflow: hidden;
909
907
  background-color: #fff;
910
908
  }
911
909
 
@@ -1112,8 +1110,8 @@ class GenerateImg extends koishi_1.Service {
1112
1110
  }
1113
1111
 
1114
1112
  .card .card-forward {
1115
- margin: 0 -15px 0 -85px;
1116
- padding: 12px 15px 14px 85px;
1113
+ border-radius: 5px;
1114
+ padding: 12px 10px 14px 10px;
1117
1115
  background-color: #F6F7F8;
1118
1116
  }
1119
1117
 
@@ -1205,8 +1203,8 @@ class GenerateImg extends koishi_1.Service {
1205
1203
  </head>
1206
1204
  <body>
1207
1205
  <div class="background">
1208
- <div class="card">
1209
- <div class="base-plate">
1206
+ <div ${this.giConfig.removeBorder ? '' : 'class="base-plate"'}>
1207
+ <div class="card">
1210
1208
  <div class="card-body">
1211
1209
  <!-- 主播头像 -->
1212
1210
  <img class="anchor-avatar"
package/lib/index.d.ts CHANGED
@@ -34,10 +34,12 @@ export declare const Config: Schema<Config>;
34
34
  declare class ServerManager extends Service {
35
35
  servers: ForkScope[];
36
36
  renderType: number;
37
+ restartCount: number;
37
38
  constructor(ctx: Context);
38
39
  protected start(): void | Promise<void>;
39
40
  registerPlugin: () => void;
40
41
  disposePlugin: () => void;
42
+ restartPlugin: () => boolean;
41
43
  }
42
44
  export declare function apply(ctx: Context, config: Config): void;
43
45
  export {};
package/lib/index.js CHANGED
@@ -148,9 +148,12 @@ exports.Config = koishi_1.Schema.object({
148
148
  ]),
149
149
  });
150
150
  class ServerManager extends koishi_1.Service {
151
+ // 服务
151
152
  servers = [];
152
153
  // 渲染模式
153
154
  renderType;
155
+ // 重启次数
156
+ restartCount = 0;
154
157
  constructor(ctx) {
155
158
  super(ctx, 'sm');
156
159
  }
@@ -184,6 +187,21 @@ class ServerManager extends koishi_1.Service {
184
187
  fork.dispose();
185
188
  });
186
189
  };
190
+ restartPlugin = () => {
191
+ // 重启次数大于等于3次
192
+ if (this.restartCount >= 3)
193
+ return false;
194
+ // 重启次数+1
195
+ this.restartCount++;
196
+ // 停用插件
197
+ this.disposePlugin();
198
+ // 隔一秒启动插件
199
+ this.ctx.setTimeout(() => {
200
+ this.registerPlugin();
201
+ }, 1000);
202
+ // 返回true
203
+ return true;
204
+ };
187
205
  }
188
206
  function apply(ctx, config) {
189
207
  // 设置config
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.3-rc.9",
4
+ "version": "1.2.3",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
@@ -33,6 +33,7 @@
33
33
  "luxon": "^3.4.4",
34
34
  "md5": "^2.3.0",
35
35
  "qrcode": "^1.5.3",
36
+ "sharp": "^0.33.3",
36
37
  "tough-cookie": "^4.1.3"
37
38
  },
38
39
  "devDependencies": {
package/readme.md CHANGED
@@ -134,6 +134,9 @@
134
134
  - ver 1.2.3-rc.7 尝试修复多群推送时部分群未推送的bug
135
135
  - ver 1.2.3-rc.8 修复在 `1.2.3-rc.7` 版本引入的连续推送三次的bug
136
136
  - ver 1.2.3-rc.9 完善了插件出错时的日志输出
137
+ - ver 1.2.3-rc.10 修复不能移除边框的bug,对图片布局进行了调整,新增下播消息发送主播头像
138
+ - ver 1.2.3-rc.11 测试版本,请跳过
139
+ - ver 1.2.3 完善主播下播消息发送头像功能,优化控制台订阅信息显示
137
140
 
138
141
  ## 交流群
139
142