koishi-plugin-bilibili-notify 3.4.0-alpha.1 → 3.4.0-alpha.2

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.
Files changed (3) hide show
  1. package/lib/index.cjs +121 -29
  2. package/lib/index.mjs +121 -29
  3. package/package.json +1 -1
package/lib/index.cjs CHANGED
@@ -1451,10 +1451,11 @@ var ComRegister = class {
1451
1451
  liveData.likedNum = body.count.toString();
1452
1452
  console.log(liveData.likedNum);
1453
1453
  },
1454
- onGuardBuy: ({ body }) => {
1454
+ onGuardBuy: async ({ body }) => {
1455
1455
  const guardImg = guardLevelImg[body.guard_level];
1456
- const content = (0, koishi.h)("message", [koishi.h.text(`【${masterInfo.username}的直播间】${body.user.uname}加入了大航海(${body.gift_name})`), koishi.h.image(guardImg)]);
1457
- this.broadcastToTargets(sub.uid, content, PushType.LiveGuardBuy);
1456
+ const buffer = await this.ctx["bilibili-notify-generate-img"].generateBoardingImg(guardImg, body.user.face, masterInfo.userface, body.user.uname, masterInfo.username);
1457
+ const img = koishi.h.image(buffer, "image/jpeg");
1458
+ this.broadcastToTargets(sub.uid, img, PushType.LiveGuardBuy);
1458
1459
  },
1459
1460
  onLiveStart: async () => {
1460
1461
  const now = Date.now();
@@ -2056,16 +2057,11 @@ var GenerateImg = class extends koishi.Service {
2056
2057
  <head>
2057
2058
  <title>直播通知</title>
2058
2059
  <style>
2059
- @font-face {
2060
- font-family: "Custom Font";
2061
- src: url(${(0, node_url.pathToFileURL)((0, node_path.resolve)(__dirname, "font/HYZhengYuan-75W.ttf"))});
2062
- }
2063
-
2064
2060
  * {
2065
2061
  margin: 0;
2066
2062
  padding: 0;
2067
2063
  box-sizing: border-box;
2068
- font-family: \"${this.giConfig.font}\", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2064
+ font-family: \"${this.giConfig.font}\", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2069
2065
  }
2070
2066
 
2071
2067
  html {
@@ -2198,6 +2194,119 @@ var GenerateImg = class extends koishi.Service {
2198
2194
  throw new Error(`生成图片失败!错误: ${e.toString()}`);
2199
2195
  });
2200
2196
  }
2197
+ async generateBoardingImg(captainImgUrl, userAvatarUrl, masterAvatarUrl, userName, masterName) {
2198
+ const html = `
2199
+ <!DOCTYPE html>
2200
+ <html>
2201
+
2202
+ <head>
2203
+ <title>上舰通知</title>
2204
+ <style>
2205
+ * {
2206
+ margin: 0;
2207
+ padding: 0;
2208
+ box-sizing: border-box;
2209
+ font-family: \"${this.giConfig.font}\", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2210
+ }
2211
+
2212
+ html {
2213
+ width: 400px;
2214
+ height: auto;
2215
+ }
2216
+
2217
+ .bg {
2218
+ display: flex;
2219
+ justify-content: center;
2220
+ align-items: center;
2221
+ width: 450px;
2222
+ height: 200px;
2223
+ background: linear-gradient(to right bottom, #F38AB5, #F9CCDF);
2224
+ }
2225
+
2226
+ .baseplate {
2227
+ display: flex;
2228
+ justify-content: space-between;
2229
+ border-radius: 10px;
2230
+ width: 430px;
2231
+ height: 180px;
2232
+ box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
2233
+ background-color: #FFF5EE;
2234
+ }
2235
+
2236
+ .info {
2237
+ flex: 1;
2238
+ display: flex;
2239
+ flex-direction: column;
2240
+ align-items: flex-start;
2241
+ justify-content: space-between;
2242
+ height: 160px;
2243
+ margin: 10px 0 10px 10px;
2244
+ }
2245
+
2246
+ .user {
2247
+ display: flex;
2248
+ align-items: center;
2249
+ gap: 5px;
2250
+ }
2251
+
2252
+ .avatar {
2253
+ height: 70px;
2254
+ width: 70px;
2255
+ border-radius: 50%;
2256
+ }
2257
+
2258
+ .avatar img {
2259
+ width: 100%;
2260
+ height: 100%;
2261
+ border-radius: 50%;
2262
+ }
2263
+
2264
+ .desc {
2265
+ margin-bottom: 10px;
2266
+ font-size: 16px;
2267
+ font-weight: bold;
2268
+ font-style: italic;
2269
+ color: #333;
2270
+ }
2271
+
2272
+ .captain {
2273
+ width: 180px;
2274
+ height: 180px;
2275
+ margin-left: 10px;
2276
+ background: url("${captainImgUrl}") no-repeat center;
2277
+ background-size: cover;
2278
+ }
2279
+ </style>
2280
+ </head>
2281
+
2282
+ <body>
2283
+ <div class="bg">
2284
+ <div class="baseplate">
2285
+ <div class="info">
2286
+ <div class="user">
2287
+ <div class="avatar">
2288
+ <img src="${userAvatarUrl}" alt="用户头像">
2289
+ </div>
2290
+ <div>&nbsp;&nbsp;&nbsp;🛳️🚩&nbsp;&nbsp;&nbsp;</div>
2291
+ <div class="avatar">
2292
+ <img src="${masterAvatarUrl}" alt="主播头像">
2293
+ </div>
2294
+ </div>
2295
+ <div class="desc">
2296
+ "${userName}"加入了"${masterName}"的大航海舰队!
2297
+ </div>
2298
+ </div>
2299
+ <div class="captain"></div>
2300
+ </div>
2301
+ </div>
2302
+ </body>
2303
+
2304
+ </html>
2305
+ `;
2306
+ return await withRetry(() => this.imgHandler(html)).catch((e) => {
2307
+ throw new Error(`生成图片失败!错误: ${e.toString()}`);
2308
+ });
2309
+ }
2201
2310
  richTextParser(rt, title) {
2202
2311
  const richText = rt.reduce((accumulator, currentValue) => {
2203
2312
  if (currentValue.emoji) return `${accumulator}<img style="width:28px; height:28px;" src="${currentValue.emoji.icon_url}"/>`;
@@ -2463,19 +2572,13 @@ var GenerateImg = class extends koishi.Service {
2463
2572
  return [main$1, forwardInfo];
2464
2573
  };
2465
2574
  const [main] = await getDynamicMajor(data, false);
2466
- const fontURL = (0, node_url.pathToFileURL)((0, node_path.resolve)(__dirname, "font/HYZhengYuan-75W.ttf"));
2467
2575
  let style;
2468
2576
  if (this.giConfig.enableLargeFont) style = `
2469
- @font-face {
2470
- font-family: "Custom Font";
2471
- src: url(${fontURL});
2472
- }
2473
-
2474
2577
  * {
2475
2578
  margin: 0;
2476
2579
  padding: 0;
2477
2580
  box-sizing: border-box;
2478
- font-family: \"${this.giConfig.font}\", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2581
+ font-family: \"${this.giConfig.font}\", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2479
2582
  }
2480
2583
 
2481
2584
  html {
@@ -2834,16 +2937,11 @@ var GenerateImg = class extends koishi.Service {
2834
2937
  }
2835
2938
  `;
2836
2939
  else style = `
2837
- @font-face {
2838
- font-family: "Custom Font";
2839
- src: url(${fontURL});
2840
- }
2841
-
2842
2940
  * {
2843
2941
  margin: 0;
2844
2942
  padding: 0;
2845
2943
  box-sizing: border-box;
2846
- font-family: \"${this.giConfig.font}\", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2944
+ font-family: \"${this.giConfig.font}\", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2847
2945
  }
2848
2946
 
2849
2947
  html {
@@ -3288,7 +3386,6 @@ var GenerateImg = class extends koishi.Service {
3288
3386
  });
3289
3387
  }
3290
3388
  async generateWordCloudImg(words, masterName) {
3291
- const fontURL = (0, node_url.pathToFileURL)((0, node_path.resolve)(__dirname, "font/HYZhengYuan-75W.ttf"));
3292
3389
  const wordcloudJS = (0, node_url.pathToFileURL)((0, node_path.resolve)(__dirname, "static/wordcloud2.min.js"));
3293
3390
  const renderFunc = (0, node_url.pathToFileURL)((0, node_path.resolve)(__dirname, "static/render.js"));
3294
3391
  const html = `
@@ -3299,16 +3396,11 @@ var GenerateImg = class extends koishi.Service {
3299
3396
  <meta charset="UTF-8">
3300
3397
  <title>高清词云展示</title>
3301
3398
  <style>
3302
- @font-face {
3303
- font-family: "Custom Font";
3304
- src: url(${fontURL});
3305
- }
3306
-
3307
3399
  * {
3308
3400
  margin: 0;
3309
3401
  padding: 0;
3310
3402
  box-sizing: border-box;
3311
- font-family: \"${this.giConfig.font}\", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
3403
+ font-family: \"${this.giConfig.font}\", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
3312
3404
  }
3313
3405
 
3314
3406
  html {
package/lib/index.mjs CHANGED
@@ -1426,10 +1426,11 @@ var ComRegister = class {
1426
1426
  liveData.likedNum = body.count.toString();
1427
1427
  console.log(liveData.likedNum);
1428
1428
  },
1429
- onGuardBuy: ({ body }) => {
1429
+ onGuardBuy: async ({ body }) => {
1430
1430
  const guardImg = guardLevelImg[body.guard_level];
1431
- const content = h("message", [h.text(`【${masterInfo.username}的直播间】${body.user.uname}加入了大航海(${body.gift_name})`), h.image(guardImg)]);
1432
- this.broadcastToTargets(sub.uid, content, PushType.LiveGuardBuy);
1431
+ const buffer = await this.ctx["bilibili-notify-generate-img"].generateBoardingImg(guardImg, body.user.face, masterInfo.userface, body.user.uname, masterInfo.username);
1432
+ const img = h.image(buffer, "image/jpeg");
1433
+ this.broadcastToTargets(sub.uid, img, PushType.LiveGuardBuy);
1433
1434
  },
1434
1435
  onLiveStart: async () => {
1435
1436
  const now = Date.now();
@@ -2031,16 +2032,11 @@ var GenerateImg = class extends Service {
2031
2032
  <head>
2032
2033
  <title>直播通知</title>
2033
2034
  <style>
2034
- @font-face {
2035
- font-family: "Custom Font";
2036
- src: url(${pathToFileURL(resolve(__dirname, "font/HYZhengYuan-75W.ttf"))});
2037
- }
2038
-
2039
2035
  * {
2040
2036
  margin: 0;
2041
2037
  padding: 0;
2042
2038
  box-sizing: border-box;
2043
- font-family: \"${this.giConfig.font}\", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2039
+ font-family: \"${this.giConfig.font}\", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2044
2040
  }
2045
2041
 
2046
2042
  html {
@@ -2173,6 +2169,119 @@ var GenerateImg = class extends Service {
2173
2169
  throw new Error(`生成图片失败!错误: ${e.toString()}`);
2174
2170
  });
2175
2171
  }
2172
+ async generateBoardingImg(captainImgUrl, userAvatarUrl, masterAvatarUrl, userName, masterName) {
2173
+ const html = `
2174
+ <!DOCTYPE html>
2175
+ <html>
2176
+
2177
+ <head>
2178
+ <title>上舰通知</title>
2179
+ <style>
2180
+ * {
2181
+ margin: 0;
2182
+ padding: 0;
2183
+ box-sizing: border-box;
2184
+ font-family: \"${this.giConfig.font}\", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2185
+ }
2186
+
2187
+ html {
2188
+ width: 400px;
2189
+ height: auto;
2190
+ }
2191
+
2192
+ .bg {
2193
+ display: flex;
2194
+ justify-content: center;
2195
+ align-items: center;
2196
+ width: 450px;
2197
+ height: 200px;
2198
+ background: linear-gradient(to right bottom, #F38AB5, #F9CCDF);
2199
+ }
2200
+
2201
+ .baseplate {
2202
+ display: flex;
2203
+ justify-content: space-between;
2204
+ border-radius: 10px;
2205
+ width: 430px;
2206
+ height: 180px;
2207
+ box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
2208
+ background-color: #FFF5EE;
2209
+ }
2210
+
2211
+ .info {
2212
+ flex: 1;
2213
+ display: flex;
2214
+ flex-direction: column;
2215
+ align-items: flex-start;
2216
+ justify-content: space-between;
2217
+ height: 160px;
2218
+ margin: 10px 0 10px 10px;
2219
+ }
2220
+
2221
+ .user {
2222
+ display: flex;
2223
+ align-items: center;
2224
+ gap: 5px;
2225
+ }
2226
+
2227
+ .avatar {
2228
+ height: 70px;
2229
+ width: 70px;
2230
+ border-radius: 50%;
2231
+ }
2232
+
2233
+ .avatar img {
2234
+ width: 100%;
2235
+ height: 100%;
2236
+ border-radius: 50%;
2237
+ }
2238
+
2239
+ .desc {
2240
+ margin-bottom: 10px;
2241
+ font-size: 16px;
2242
+ font-weight: bold;
2243
+ font-style: italic;
2244
+ color: #333;
2245
+ }
2246
+
2247
+ .captain {
2248
+ width: 180px;
2249
+ height: 180px;
2250
+ margin-left: 10px;
2251
+ background: url("${captainImgUrl}") no-repeat center;
2252
+ background-size: cover;
2253
+ }
2254
+ </style>
2255
+ </head>
2256
+
2257
+ <body>
2258
+ <div class="bg">
2259
+ <div class="baseplate">
2260
+ <div class="info">
2261
+ <div class="user">
2262
+ <div class="avatar">
2263
+ <img src="${userAvatarUrl}" alt="用户头像">
2264
+ </div>
2265
+ <div>&nbsp;&nbsp;&nbsp;🛳️🚩&nbsp;&nbsp;&nbsp;</div>
2266
+ <div class="avatar">
2267
+ <img src="${masterAvatarUrl}" alt="主播头像">
2268
+ </div>
2269
+ </div>
2270
+ <div class="desc">
2271
+ "${userName}"加入了"${masterName}"的大航海舰队!
2272
+ </div>
2273
+ </div>
2274
+ <div class="captain"></div>
2275
+ </div>
2276
+ </div>
2277
+ </body>
2278
+
2279
+ </html>
2280
+ `;
2281
+ return await withRetry(() => this.imgHandler(html)).catch((e) => {
2282
+ throw new Error(`生成图片失败!错误: ${e.toString()}`);
2283
+ });
2284
+ }
2176
2285
  richTextParser(rt, title) {
2177
2286
  const richText = rt.reduce((accumulator, currentValue) => {
2178
2287
  if (currentValue.emoji) return `${accumulator}<img style="width:28px; height:28px;" src="${currentValue.emoji.icon_url}"/>`;
@@ -2438,19 +2547,13 @@ var GenerateImg = class extends Service {
2438
2547
  return [main$1, forwardInfo];
2439
2548
  };
2440
2549
  const [main] = await getDynamicMajor(data, false);
2441
- const fontURL = pathToFileURL(resolve(__dirname, "font/HYZhengYuan-75W.ttf"));
2442
2550
  let style;
2443
2551
  if (this.giConfig.enableLargeFont) style = `
2444
- @font-face {
2445
- font-family: "Custom Font";
2446
- src: url(${fontURL});
2447
- }
2448
-
2449
2552
  * {
2450
2553
  margin: 0;
2451
2554
  padding: 0;
2452
2555
  box-sizing: border-box;
2453
- font-family: \"${this.giConfig.font}\", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2556
+ font-family: \"${this.giConfig.font}\", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2454
2557
  }
2455
2558
 
2456
2559
  html {
@@ -2809,16 +2912,11 @@ var GenerateImg = class extends Service {
2809
2912
  }
2810
2913
  `;
2811
2914
  else style = `
2812
- @font-face {
2813
- font-family: "Custom Font";
2814
- src: url(${fontURL});
2815
- }
2816
-
2817
2915
  * {
2818
2916
  margin: 0;
2819
2917
  padding: 0;
2820
2918
  box-sizing: border-box;
2821
- font-family: \"${this.giConfig.font}\", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2919
+ font-family: \"${this.giConfig.font}\", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
2822
2920
  }
2823
2921
 
2824
2922
  html {
@@ -3263,7 +3361,6 @@ var GenerateImg = class extends Service {
3263
3361
  });
3264
3362
  }
3265
3363
  async generateWordCloudImg(words, masterName) {
3266
- const fontURL = pathToFileURL(resolve(__dirname, "font/HYZhengYuan-75W.ttf"));
3267
3364
  const wordcloudJS = pathToFileURL(resolve(__dirname, "static/wordcloud2.min.js"));
3268
3365
  const renderFunc = pathToFileURL(resolve(__dirname, "static/render.js"));
3269
3366
  const html = `
@@ -3274,16 +3371,11 @@ var GenerateImg = class extends Service {
3274
3371
  <meta charset="UTF-8">
3275
3372
  <title>高清词云展示</title>
3276
3373
  <style>
3277
- @font-face {
3278
- font-family: "Custom Font";
3279
- src: url(${fontURL});
3280
- }
3281
-
3282
3374
  * {
3283
3375
  margin: 0;
3284
3376
  padding: 0;
3285
3377
  box-sizing: border-box;
3286
- font-family: \"${this.giConfig.font}\", "Custom Font", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
3378
+ font-family: \"${this.giConfig.font}\", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK", sans-serif;
3287
3379
  }
3288
3380
 
3289
3381
  html {
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": "3.4.0-alpha.1",
4
+ "version": "3.4.0-alpha.2",
5
5
  "main": "./lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [