koishi-plugin-bilibili-notify 3.4.0-alpha.3 → 3.4.0-alpha.4

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 +104 -20
  2. package/lib/index.mjs +104 -20
  3. package/package.json +1 -1
package/lib/index.cjs CHANGED
@@ -713,6 +713,19 @@ var ComRegister = class ComRegister {
713
713
  this.logger.info("AI 生成完毕,结果为:");
714
714
  this.logger.info(res.choices[0].message.content);
715
715
  });
716
+ biliCom.subcommand(".img").action(async ({ session }) => {
717
+ const guardImg = ComRegister.GUARD_LEVEL_IMG[blive_message_listener.GuardLevel.Jianzhang];
718
+ const buffer = await this.ctx["bilibili-notify-generate-img"].generateBoardingImg(guardImg, {
719
+ guardLevel: blive_message_listener.GuardLevel.Jianzhang,
720
+ face: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQSESgEED4WoyK9O5FFgrV8cHZPM4w4JgleZQ&s",
721
+ uname: "恶魔兔",
722
+ accompany: 56
723
+ }, {
724
+ masterName: "籽岷",
725
+ masterAvatarUrl: "https://img.touxiangkong.com/uploads/allimg/20203301251/2020/3/BjEbyu.jpg"
726
+ });
727
+ await session.send(koishi.h.image(buffer, "image/jpeg"));
728
+ });
716
729
  }
717
730
  async init(config) {
718
731
  this.logger = this.ctx.logger("bilibili-notify-core");
@@ -1447,13 +1460,24 @@ var ComRegister = class ComRegister {
1447
1460
  liveData.watchedNum = body.text_small;
1448
1461
  },
1449
1462
  onLikedChange: ({ body }) => {
1450
- console.log(body.count);
1451
1463
  liveData.likedNum = body.count.toString();
1452
- console.log(liveData.likedNum);
1453
1464
  },
1454
1465
  onGuardBuy: async ({ body }) => {
1455
1466
  const guardImg = ComRegister.GUARD_LEVEL_IMG[body.guard_level];
1456
- const buffer = await this.ctx["bilibili-notify-generate-img"].generateBoardingImg(guardImg, body, {
1467
+ const data = await this.ctx["bilibili-notify-api"].getUserInfoInLive(body.user.uid.toString(), sub.uid);
1468
+ if (data.code !== 0) {
1469
+ const content = (0, koishi.h)("message", [koishi.h.text(`【${masterInfo.username}的直播间】${body.user.uname}加入了大航海(${body.gift_name})`), koishi.h.image(guardImg)]);
1470
+ return this.broadcastToTargets(sub.uid, content, PushType.LiveGuardBuy);
1471
+ }
1472
+ console.log(data);
1473
+ const userInfo = data.data;
1474
+ console.log(userInfo);
1475
+ const buffer = await this.ctx["bilibili-notify-generate-img"].generateBoardingImg(guardImg, {
1476
+ guardLevel: body.guard_level,
1477
+ uname: userInfo.uname,
1478
+ face: userInfo.face,
1479
+ accompany: userInfo.guard.accompany
1480
+ }, {
1457
1481
  masterName: masterInfo.username,
1458
1482
  masterAvatarUrl: masterInfo.userface
1459
1483
  });
@@ -2203,8 +2227,20 @@ var GenerateImg = class GenerateImg extends koishi.Service {
2203
2227
  [blive_message_listener.GuardLevel.Tidu]: ["#d8a0e6", "#b494e5"],
2204
2228
  [blive_message_listener.GuardLevel.Zongdu]: ["#f2a053", "#ef5f5f"]
2205
2229
  };
2206
- async generateBoardingImg(captainImgUrl, { guard_level, user: { face, uname, badge: { name: name$2, level, color } } }, { masterAvatarUrl, masterName }) {
2207
- const bgColor = GenerateImg.BG_COLOR[guard_level];
2230
+ async generateBoardingImg(captainImgUrl, { guardLevel, uname, face, accompany }, { masterAvatarUrl, masterName }) {
2231
+ const bgColor = GenerateImg.BG_COLOR[guardLevel];
2232
+ const desc = {
2233
+ [blive_message_listener.GuardLevel.Jianzhang]: () => {
2234
+ if (accompany && accompany > 0) return `"${uname}号"继续在<br/>"${masterName}"大航海舰队服役!`;
2235
+ return `"${uname}号"加入<br/>"${masterName}"大航海舰队!`;
2236
+ },
2237
+ [blive_message_listener.GuardLevel.Tidu]: () => {
2238
+ return `"${uname}"就任<br/>"${masterName}"大航海舰队提督!`;
2239
+ },
2240
+ [blive_message_listener.GuardLevel.Zongdu]: () => {
2241
+ return `"${uname}"上任<br/>"${masterName}"大航海舰队总督!`;
2242
+ }
2243
+ };
2208
2244
  const html = `
2209
2245
  <!DOCTYPE html>
2210
2246
  <html>
@@ -2256,7 +2292,6 @@ var GenerateImg = class GenerateImg extends koishi.Service {
2256
2292
 
2257
2293
  .user {
2258
2294
  display: flex;
2259
- align-items: center;
2260
2295
  gap: 10px;
2261
2296
  }
2262
2297
 
@@ -2272,31 +2307,50 @@ var GenerateImg = class GenerateImg extends koishi.Service {
2272
2307
  border-radius: 50%;
2273
2308
  }
2274
2309
 
2275
- .badge {
2310
+ .user-info {
2311
+ display: flex;
2312
+ flex-direction: column;
2313
+ align-items: flex-start;
2314
+ gap: 5px;
2315
+ margin-top: 10px;
2316
+ }
2317
+
2318
+ .name-badge {
2276
2319
  display: flex;
2277
2320
  align-items: center;
2278
- height: 25px;
2279
- background-color: ${color};
2321
+ height: 30px;
2322
+ background-color: ${bgColor[0]};
2280
2323
  border-radius: 25px;
2281
2324
  color: white;
2282
- font-size: 12px;
2283
- padding: 5px 0;
2325
+ padding: 0 10px;
2326
+ border: solid 2px white;
2327
+ overflow: hidden;
2328
+ font-weight: bold;
2329
+ font-size: 14px;
2330
+ }
2331
+
2332
+ .accompany {
2333
+ display: flex;
2334
+ gap: 5px;
2335
+ align-items: center;
2336
+ height: 25px;
2337
+ background-color: ${bgColor[0]};
2338
+ border-radius: 25px;
2284
2339
  border: solid 1px white;
2285
2340
  overflow: hidden;
2286
2341
  }
2287
2342
 
2288
- .badge-avatar {
2343
+ .master-avatar {
2289
2344
  width: 25px;
2290
2345
  height: 25px;
2291
2346
  border-radius: 50%;
2292
2347
  background: url("${masterAvatarUrl}") no-repeat center;
2293
2348
  background-size: cover;
2294
- margin-right: 5px;
2295
2349
  }
2296
2350
 
2297
- .badge span {
2298
- font-weight: bold;
2299
- font-size: 14px;
2351
+ .accompany span {
2352
+ color: white;
2353
+ font-size: 11px;
2300
2354
  margin-right: 5px;
2301
2355
  }
2302
2356
 
@@ -2325,13 +2379,17 @@ var GenerateImg = class GenerateImg extends koishi.Service {
2325
2379
  <div class="avatar">
2326
2380
  <img src="${face}" alt="用户头像">
2327
2381
  </div>
2328
- <div class="badge">
2329
- <div class="badge-avatar"></div>${name$2} &nbsp; <span>${level}</span>
2382
+ <div class="user-info">
2383
+ <div class="name-badge">
2384
+ ${uname}
2385
+ </div>
2386
+ <div class="accompany">
2387
+ <div class="master-avatar"></div><span>已陪伴主播 ${accompany} 天</span>
2388
+ </div>
2330
2389
  </div>
2331
2390
  </div>
2332
2391
  <div class="desc">
2333
- <p>"${guard_level === blive_message_listener.GuardLevel.Jianzhang ? `${uname}号` : uname}"${guard_level === blive_message_listener.GuardLevel.Jianzhang ? "加入" : guard_level === blive_message_listener.GuardLevel.Tidu ? "就任" : "上任"}</p>
2334
- "${masterName}"的大航海舰队${guard_level === blive_message_listener.GuardLevel.Tidu ? "提督" : ""}${guard_level === blive_message_listener.GuardLevel.Zongdu ? "总督" : ""}!
2392
+ ${desc[guardLevel]()}
2335
2393
  </div>
2336
2394
  </div>
2337
2395
  <div class="captain"></div>
@@ -3692,6 +3750,8 @@ const GET_MASTER_INFO = "https://api.live.bilibili.com/live_user/v1/Master/info"
3692
3750
  const GET_TIME_NOW = "https://api.bilibili.com/x/report/click/now";
3693
3751
  const GET_SERVER_UTC_TIME = "https://interface.bilibili.com/serverdate.js";
3694
3752
  const GET_LATEST_UPDATED_UPS = "https://api.bilibili.com/x/polymer/web-dynamic/v1/portal";
3753
+ const GET_ONLINE_GOLD_RANK = "https://api.live.bilibili.com//xlive/general-interface/v1/rank/getOnlineGoldRank";
3754
+ const GET_USER_INFO_IN_LIVE = "https://api.live.bilibili.com/xlive/app-ucenter/v2/card/user";
3695
3755
  const MODIFY_RELATION = "https://api.bilibili.com/x/relation/modify";
3696
3756
  const CREATE_GROUP = "https://api.bilibili.com/x/relation/tag/create";
3697
3757
  const MODIFY_GROUP_MEMBER = "https://api.bilibili.com/x/relation/tags/addUsers";
@@ -4085,6 +4145,30 @@ var BiliAPI = class extends koishi.Service {
4085
4145
  retries: 3
4086
4146
  });
4087
4147
  }
4148
+ async getOnlineGoldRank(roomId, ruid, page = 1, pageSize = 20) {
4149
+ const run = async () => {
4150
+ const { data } = await this.client.get(`${GET_ONLINE_GOLD_RANK}?room_id=${roomId}&ruid=${ruid}&page=${page}&page_size=${pageSize}`);
4151
+ return data;
4152
+ };
4153
+ return await this.pRetry(run, {
4154
+ onFailedAttempt: (error) => {
4155
+ this.logger.error(`getOnlineGoldRank() 第${error.attemptNumber}次失败: ${error.message}`);
4156
+ },
4157
+ retries: 3
4158
+ });
4159
+ }
4160
+ async getUserInfoInLive(uid, ruid) {
4161
+ const run = async () => {
4162
+ const { data } = await this.client.get(`${GET_USER_INFO_IN_LIVE}?uid=${uid}&ruid=${ruid}`);
4163
+ return data;
4164
+ };
4165
+ return await this.pRetry(run, {
4166
+ onFailedAttempt: (error) => {
4167
+ this.logger.error(`getUserInfoInLive() 第${error.attemptNumber}次失败: ${error.message}`);
4168
+ },
4169
+ retries: 3
4170
+ });
4171
+ }
4088
4172
  async chatWithAI(content) {
4089
4173
  return await this.aiClient.chat.completions.create({
4090
4174
  model: this.apiConfig.ai.model,
package/lib/index.mjs CHANGED
@@ -688,6 +688,19 @@ var ComRegister = class ComRegister {
688
688
  this.logger.info("AI 生成完毕,结果为:");
689
689
  this.logger.info(res.choices[0].message.content);
690
690
  });
691
+ biliCom.subcommand(".img").action(async ({ session }) => {
692
+ const guardImg = ComRegister.GUARD_LEVEL_IMG[GuardLevel.Jianzhang];
693
+ const buffer = await this.ctx["bilibili-notify-generate-img"].generateBoardingImg(guardImg, {
694
+ guardLevel: GuardLevel.Jianzhang,
695
+ face: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQSESgEED4WoyK9O5FFgrV8cHZPM4w4JgleZQ&s",
696
+ uname: "恶魔兔",
697
+ accompany: 56
698
+ }, {
699
+ masterName: "籽岷",
700
+ masterAvatarUrl: "https://img.touxiangkong.com/uploads/allimg/20203301251/2020/3/BjEbyu.jpg"
701
+ });
702
+ await session.send(h.image(buffer, "image/jpeg"));
703
+ });
691
704
  }
692
705
  async init(config) {
693
706
  this.logger = this.ctx.logger("bilibili-notify-core");
@@ -1422,13 +1435,24 @@ var ComRegister = class ComRegister {
1422
1435
  liveData.watchedNum = body.text_small;
1423
1436
  },
1424
1437
  onLikedChange: ({ body }) => {
1425
- console.log(body.count);
1426
1438
  liveData.likedNum = body.count.toString();
1427
- console.log(liveData.likedNum);
1428
1439
  },
1429
1440
  onGuardBuy: async ({ body }) => {
1430
1441
  const guardImg = ComRegister.GUARD_LEVEL_IMG[body.guard_level];
1431
- const buffer = await this.ctx["bilibili-notify-generate-img"].generateBoardingImg(guardImg, body, {
1442
+ const data = await this.ctx["bilibili-notify-api"].getUserInfoInLive(body.user.uid.toString(), sub.uid);
1443
+ if (data.code !== 0) {
1444
+ const content = h("message", [h.text(`【${masterInfo.username}的直播间】${body.user.uname}加入了大航海(${body.gift_name})`), h.image(guardImg)]);
1445
+ return this.broadcastToTargets(sub.uid, content, PushType.LiveGuardBuy);
1446
+ }
1447
+ console.log(data);
1448
+ const userInfo = data.data;
1449
+ console.log(userInfo);
1450
+ const buffer = await this.ctx["bilibili-notify-generate-img"].generateBoardingImg(guardImg, {
1451
+ guardLevel: body.guard_level,
1452
+ uname: userInfo.uname,
1453
+ face: userInfo.face,
1454
+ accompany: userInfo.guard.accompany
1455
+ }, {
1432
1456
  masterName: masterInfo.username,
1433
1457
  masterAvatarUrl: masterInfo.userface
1434
1458
  });
@@ -2178,8 +2202,20 @@ var GenerateImg = class GenerateImg extends Service {
2178
2202
  [GuardLevel.Tidu]: ["#d8a0e6", "#b494e5"],
2179
2203
  [GuardLevel.Zongdu]: ["#f2a053", "#ef5f5f"]
2180
2204
  };
2181
- async generateBoardingImg(captainImgUrl, { guard_level, user: { face, uname, badge: { name: name$2, level, color } } }, { masterAvatarUrl, masterName }) {
2182
- const bgColor = GenerateImg.BG_COLOR[guard_level];
2205
+ async generateBoardingImg(captainImgUrl, { guardLevel, uname, face, accompany }, { masterAvatarUrl, masterName }) {
2206
+ const bgColor = GenerateImg.BG_COLOR[guardLevel];
2207
+ const desc = {
2208
+ [GuardLevel.Jianzhang]: () => {
2209
+ if (accompany && accompany > 0) return `"${uname}号"继续在<br/>"${masterName}"大航海舰队服役!`;
2210
+ return `"${uname}号"加入<br/>"${masterName}"大航海舰队!`;
2211
+ },
2212
+ [GuardLevel.Tidu]: () => {
2213
+ return `"${uname}"就任<br/>"${masterName}"大航海舰队提督!`;
2214
+ },
2215
+ [GuardLevel.Zongdu]: () => {
2216
+ return `"${uname}"上任<br/>"${masterName}"大航海舰队总督!`;
2217
+ }
2218
+ };
2183
2219
  const html = `
2184
2220
  <!DOCTYPE html>
2185
2221
  <html>
@@ -2231,7 +2267,6 @@ var GenerateImg = class GenerateImg extends Service {
2231
2267
 
2232
2268
  .user {
2233
2269
  display: flex;
2234
- align-items: center;
2235
2270
  gap: 10px;
2236
2271
  }
2237
2272
 
@@ -2247,31 +2282,50 @@ var GenerateImg = class GenerateImg extends Service {
2247
2282
  border-radius: 50%;
2248
2283
  }
2249
2284
 
2250
- .badge {
2285
+ .user-info {
2286
+ display: flex;
2287
+ flex-direction: column;
2288
+ align-items: flex-start;
2289
+ gap: 5px;
2290
+ margin-top: 10px;
2291
+ }
2292
+
2293
+ .name-badge {
2251
2294
  display: flex;
2252
2295
  align-items: center;
2253
- height: 25px;
2254
- background-color: ${color};
2296
+ height: 30px;
2297
+ background-color: ${bgColor[0]};
2255
2298
  border-radius: 25px;
2256
2299
  color: white;
2257
- font-size: 12px;
2258
- padding: 5px 0;
2300
+ padding: 0 10px;
2301
+ border: solid 2px white;
2302
+ overflow: hidden;
2303
+ font-weight: bold;
2304
+ font-size: 14px;
2305
+ }
2306
+
2307
+ .accompany {
2308
+ display: flex;
2309
+ gap: 5px;
2310
+ align-items: center;
2311
+ height: 25px;
2312
+ background-color: ${bgColor[0]};
2313
+ border-radius: 25px;
2259
2314
  border: solid 1px white;
2260
2315
  overflow: hidden;
2261
2316
  }
2262
2317
 
2263
- .badge-avatar {
2318
+ .master-avatar {
2264
2319
  width: 25px;
2265
2320
  height: 25px;
2266
2321
  border-radius: 50%;
2267
2322
  background: url("${masterAvatarUrl}") no-repeat center;
2268
2323
  background-size: cover;
2269
- margin-right: 5px;
2270
2324
  }
2271
2325
 
2272
- .badge span {
2273
- font-weight: bold;
2274
- font-size: 14px;
2326
+ .accompany span {
2327
+ color: white;
2328
+ font-size: 11px;
2275
2329
  margin-right: 5px;
2276
2330
  }
2277
2331
 
@@ -2300,13 +2354,17 @@ var GenerateImg = class GenerateImg extends Service {
2300
2354
  <div class="avatar">
2301
2355
  <img src="${face}" alt="用户头像">
2302
2356
  </div>
2303
- <div class="badge">
2304
- <div class="badge-avatar"></div>${name$2} &nbsp; <span>${level}</span>
2357
+ <div class="user-info">
2358
+ <div class="name-badge">
2359
+ ${uname}
2360
+ </div>
2361
+ <div class="accompany">
2362
+ <div class="master-avatar"></div><span>已陪伴主播 ${accompany} 天</span>
2363
+ </div>
2305
2364
  </div>
2306
2365
  </div>
2307
2366
  <div class="desc">
2308
- <p>"${guard_level === GuardLevel.Jianzhang ? `${uname}号` : uname}"${guard_level === GuardLevel.Jianzhang ? "加入" : guard_level === GuardLevel.Tidu ? "就任" : "上任"}</p>
2309
- "${masterName}"的大航海舰队${guard_level === GuardLevel.Tidu ? "提督" : ""}${guard_level === GuardLevel.Zongdu ? "总督" : ""}!
2367
+ ${desc[guardLevel]()}
2310
2368
  </div>
2311
2369
  </div>
2312
2370
  <div class="captain"></div>
@@ -3667,6 +3725,8 @@ const GET_MASTER_INFO = "https://api.live.bilibili.com/live_user/v1/Master/info"
3667
3725
  const GET_TIME_NOW = "https://api.bilibili.com/x/report/click/now";
3668
3726
  const GET_SERVER_UTC_TIME = "https://interface.bilibili.com/serverdate.js";
3669
3727
  const GET_LATEST_UPDATED_UPS = "https://api.bilibili.com/x/polymer/web-dynamic/v1/portal";
3728
+ const GET_ONLINE_GOLD_RANK = "https://api.live.bilibili.com//xlive/general-interface/v1/rank/getOnlineGoldRank";
3729
+ const GET_USER_INFO_IN_LIVE = "https://api.live.bilibili.com/xlive/app-ucenter/v2/card/user";
3670
3730
  const MODIFY_RELATION = "https://api.bilibili.com/x/relation/modify";
3671
3731
  const CREATE_GROUP = "https://api.bilibili.com/x/relation/tag/create";
3672
3732
  const MODIFY_GROUP_MEMBER = "https://api.bilibili.com/x/relation/tags/addUsers";
@@ -4060,6 +4120,30 @@ var BiliAPI = class extends Service {
4060
4120
  retries: 3
4061
4121
  });
4062
4122
  }
4123
+ async getOnlineGoldRank(roomId, ruid, page = 1, pageSize = 20) {
4124
+ const run = async () => {
4125
+ const { data } = await this.client.get(`${GET_ONLINE_GOLD_RANK}?room_id=${roomId}&ruid=${ruid}&page=${page}&page_size=${pageSize}`);
4126
+ return data;
4127
+ };
4128
+ return await this.pRetry(run, {
4129
+ onFailedAttempt: (error) => {
4130
+ this.logger.error(`getOnlineGoldRank() 第${error.attemptNumber}次失败: ${error.message}`);
4131
+ },
4132
+ retries: 3
4133
+ });
4134
+ }
4135
+ async getUserInfoInLive(uid, ruid) {
4136
+ const run = async () => {
4137
+ const { data } = await this.client.get(`${GET_USER_INFO_IN_LIVE}?uid=${uid}&ruid=${ruid}`);
4138
+ return data;
4139
+ };
4140
+ return await this.pRetry(run, {
4141
+ onFailedAttempt: (error) => {
4142
+ this.logger.error(`getUserInfoInLive() 第${error.attemptNumber}次失败: ${error.message}`);
4143
+ },
4144
+ retries: 3
4145
+ });
4146
+ }
4063
4147
  async chatWithAI(content) {
4064
4148
  return await this.aiClient.chat.completions.create({
4065
4149
  model: this.apiConfig.ai.model,
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.3",
4
+ "version": "3.4.0-alpha.4",
5
5
  "main": "./lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [