koishi-plugin-bilibili-notify 1.2.16 → 1.3.0-alpha.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.
@@ -50,7 +50,9 @@ declare namespace ComRegister {
50
50
  masterAccountGuildId: string;
51
51
  };
52
52
  unlockSubLimits: boolean;
53
+ changeMasterInfoApi: boolean;
53
54
  liveStartAtAll: boolean;
55
+ pushUrl: boolean;
54
56
  pushTime: number;
55
57
  liveLoopTime: number;
56
58
  customLiveStart: string;
@@ -619,7 +619,7 @@ class ComRegister {
619
619
  }
620
620
  return;
621
621
  }
622
- const { pic, buffer } = await ctx.gi.generateLiveImg(data, userData, data.live_status !== 1 ?
622
+ const { pic, buffer } = await ctx.gi.generateLiveImg(data, userData.info.uname, userData.info.face, data.live_status !== 1 ?
623
623
  LiveType.NotLiveBroadcast :
624
624
  LiveType.LiveBroadcast);
625
625
  // pic 存在,使用的是render模式
@@ -1086,47 +1086,103 @@ class ComRegister {
1086
1086
  let timer = 0;
1087
1087
  let open = false;
1088
1088
  let liveTime;
1089
- let uData;
1089
+ let username;
1090
+ let userface;
1090
1091
  // 相当于锁的作用,防止上一个循环没处理完
1091
1092
  let flag = true;
1092
- const sendLiveNotifyCard = async (data, uData, liveType, liveStartMsg, atAll) => {
1093
- // 定义变量
1094
- let pic;
1095
- let buffer;
1096
- // 多次尝试生成图片
1097
- let attempts = 3;
1098
- for (let i = 0; i < attempts; i++) {
1099
- try {
1100
- // 获取直播通知卡片
1101
- const { pic: picv, buffer: bufferv } = await ctx.gi.generateLiveImg(data, uData, liveType);
1102
- // 赋值
1103
- pic = picv;
1104
- buffer = bufferv;
1105
- // 成功则跳出循环
1106
- break;
1093
+ // 定义发送直播通知卡片方法
1094
+ let sendLiveNotifyCard;
1095
+ // 判断直播是否需要@全体成员
1096
+ if (this.config.pushUrl) {
1097
+ sendLiveNotifyCard = async (data, liveType, liveStartMsg, atAll) => {
1098
+ // 定义变量
1099
+ let pic;
1100
+ let buffer;
1101
+ // 多次尝试生成图片
1102
+ let attempts = 3;
1103
+ for (let i = 0; i < attempts; i++) {
1104
+ try {
1105
+ // 获取直播通知卡片
1106
+ const { pic: picv, buffer: bufferv } = await ctx.gi.generateLiveImg(data, username, userface, liveType);
1107
+ // 赋值
1108
+ pic = picv;
1109
+ buffer = bufferv;
1110
+ // 成功则跳出循环
1111
+ break;
1112
+ }
1113
+ catch (e) {
1114
+ if (i === attempts - 1) { // 已尝试三次
1115
+ this.logger.error('liveDetect generateLiveImg() 推送卡片生成失败,原因:' + e.message);
1116
+ return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
1117
+ }
1118
+ }
1107
1119
  }
1108
- catch (e) {
1109
- if (i === attempts - 1) { // 已尝试三次
1110
- this.logger.error('liveDetect generateLiveImg() 推送卡片生成失败,原因:' + e.message);
1111
- return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
1120
+ // 推送直播信息
1121
+ // pic 存在,使用的是render模式
1122
+ if (pic) {
1123
+ let msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg, `https://live.bilibili.com/${roomId}`] });
1124
+ return await this.sendMsg(ctx, guildId, bot, pic + msg);
1125
+ }
1126
+ // pic不存在,说明使用的是page模式
1127
+ await this.sendMsg(ctx, guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg, `https://live.bilibili.com/${roomId}`] }));
1128
+ };
1129
+ }
1130
+ else {
1131
+ sendLiveNotifyCard = async (data, liveType, liveStartMsg, atAll) => {
1132
+ // 定义变量
1133
+ let pic;
1134
+ let buffer;
1135
+ // 多次尝试生成图片
1136
+ let attempts = 3;
1137
+ for (let i = 0; i < attempts; i++) {
1138
+ try {
1139
+ // 获取直播通知卡片
1140
+ const { pic: picv, buffer: bufferv } = await ctx.gi.generateLiveImg(data, username, userface, liveType);
1141
+ // 赋值
1142
+ pic = picv;
1143
+ buffer = bufferv;
1144
+ // 成功则跳出循环
1145
+ break;
1146
+ }
1147
+ catch (e) {
1148
+ if (i === attempts - 1) { // 已尝试三次
1149
+ this.logger.error('liveDetect generateLiveImg() 推送卡片生成失败,原因:' + e.message);
1150
+ return await this.sendPrivateMsgAndRebootService(ctx, bot, '插件可能出现某些未知错误,请尝试重启插件,如果仍然发生该错误,请带着日志向作者反馈');
1151
+ }
1112
1152
  }
1113
1153
  }
1114
- }
1115
- // 推送直播信息
1116
- // pic 存在,使用的是render模式
1117
- if (pic) {
1118
- let msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg] });
1119
- return await this.sendMsg(ctx, guildId, bot, pic + msg);
1120
- }
1121
- // pic不存在,说明使用的是page模式
1122
- await this.sendMsg(ctx, guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg] }));
1123
- };
1154
+ // 推送直播信息
1155
+ // pic 存在,使用的是render模式
1156
+ if (pic) {
1157
+ let msg = (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg] });
1158
+ return await this.sendMsg(ctx, guildId, bot, pic + msg);
1159
+ }
1160
+ // pic不存在,说明使用的是page模式
1161
+ await this.sendMsg(ctx, guildId, bot, (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [koishi_1.h.image(buffer, 'image/png'), atAll && (0, jsx_runtime_1.jsx)("at", { type: "all" }), liveStartMsg && liveStartMsg] }));
1162
+ };
1163
+ }
1164
+ // 定义获取主播信息方法
1165
+ let useMasterInfo;
1166
+ if (this.config.changeMasterInfoApi) {
1167
+ useMasterInfo = async (uid) => {
1168
+ const { data } = await ctx.ba.getUserInfo(uid);
1169
+ username = data.name;
1170
+ userface = data.face;
1171
+ };
1172
+ }
1173
+ else {
1174
+ useMasterInfo = async (uid) => {
1175
+ const { data: { info } } = await ctx.ba.getMasterInfo(uid);
1176
+ username = info.uname;
1177
+ userface = info.face;
1178
+ };
1179
+ }
1124
1180
  return async () => {
1125
1181
  try {
1126
1182
  // 如果flag为false则说明前面的代码还未执行完,则直接返回
1127
1183
  if (!flag)
1128
1184
  return;
1129
- flag && (flag = false);
1185
+ flag = false;
1130
1186
  // 发送请求检测直播状态
1131
1187
  let content;
1132
1188
  let attempts = 3;
@@ -1149,13 +1205,11 @@ class ComRegister {
1149
1205
  if (firstSubscription) {
1150
1206
  firstSubscription = false;
1151
1207
  // 获取主播信息
1152
- let userData;
1153
1208
  let attempts = 3;
1154
1209
  for (let i = 0; i < attempts; i++) {
1155
1210
  try {
1156
1211
  // 发送请求获取主播信息
1157
- const { data: userInfo } = await ctx.ba.getMasterInfo(data.uid);
1158
- userData = userInfo;
1212
+ await useMasterInfo(data.uid);
1159
1213
  // 成功则跳出循环
1160
1214
  break;
1161
1215
  }
@@ -1166,14 +1220,12 @@ class ComRegister {
1166
1220
  }
1167
1221
  }
1168
1222
  }
1169
- // 主播信息不会变,请求一次即可
1170
- uData = userData;
1171
1223
  // 判断直播状态
1172
1224
  if (data.live_status === 1) { // 当前正在直播
1173
1225
  // 设置开播时间
1174
1226
  liveTime = data.live_time;
1175
1227
  // 发送直播通知卡片
1176
- sendLiveNotifyCard(data, uData, LiveType.LiveBroadcast);
1228
+ sendLiveNotifyCard(data, LiveType.LiveBroadcast);
1177
1229
  // 改变开播状态
1178
1230
  open = true;
1179
1231
  } // 未开播,直接返回
@@ -1190,13 +1242,13 @@ class ComRegister {
1190
1242
  timer = 0;
1191
1243
  // 定义下播通知消息
1192
1244
  let liveEndMsg = this.config.customLiveEnd
1193
- .replace('-name', uData.info.uname)
1245
+ .replace('-name', username)
1194
1246
  .replace('-time', await ctx.gi.getTimeDifference(liveTime));
1195
1247
  // 获取头像并缩放
1196
1248
  let resizedImage;
1197
1249
  // Jimp无法处理Webp格式,直接跳过
1198
1250
  try {
1199
- resizedImage = await jimp_1.default.read(uData.info.face).then(async (image) => {
1251
+ resizedImage = await jimp_1.default.read(userface).then(async (image) => {
1200
1252
  return await image.resize(100, 100).getBufferAsync(jimp_1.default.MIME_PNG);
1201
1253
  });
1202
1254
  }
@@ -1219,13 +1271,12 @@ class ComRegister {
1219
1271
  // 设置开播时间
1220
1272
  liveTime = data.live_time;
1221
1273
  // 获取主播信息
1222
- let userData;
1223
1274
  let attempts = 3;
1224
1275
  for (let i = 0; i < attempts; i++) {
1225
1276
  try {
1226
- // 获取主播信息
1227
- const { data: userInfo } = await ctx.ba.getMasterInfo(data.uid);
1228
- userData = userInfo;
1277
+ // 主播信息不会变,开播时刷新一次即可
1278
+ // 发送请求获取主播信息
1279
+ await useMasterInfo(data.uid);
1229
1280
  // 成功则跳出循环
1230
1281
  break;
1231
1282
  }
@@ -1236,21 +1287,19 @@ class ComRegister {
1236
1287
  }
1237
1288
  }
1238
1289
  }
1239
- // 主播信息不会变,开播时刷新一次即可
1240
- uData = userData;
1241
1290
  // 定义开播通知语
1242
1291
  let liveStartMsg = this.config.customLiveStart
1243
- .replace('-name', uData.info.uname)
1292
+ .replace('-name', username)
1244
1293
  .replace('-time', await ctx.gi.getTimeDifference(liveTime))
1245
1294
  .replace('-link', `https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`);
1246
1295
  // 判断是否需要@全体成员
1247
1296
  if (this.config.liveStartAtAll) {
1248
1297
  // 发送@全体成员通知
1249
- await sendLiveNotifyCard(data, uData, LiveType.StartBroadcasting, liveStartMsg, true);
1298
+ await sendLiveNotifyCard(data, LiveType.StartBroadcasting, liveStartMsg, true);
1250
1299
  }
1251
1300
  else {
1252
1301
  // 发送直播通知卡片
1253
- await sendLiveNotifyCard(data, uData, LiveType.StartBroadcasting, liveStartMsg);
1302
+ await sendLiveNotifyCard(data, LiveType.StartBroadcasting, liveStartMsg);
1254
1303
  }
1255
1304
  }
1256
1305
  else { // 还在直播
@@ -1261,7 +1310,7 @@ class ComRegister {
1261
1310
  // 到时间重新计时
1262
1311
  timer = 0;
1263
1312
  // 发送直播通知卡片
1264
- sendLiveNotifyCard(data, uData, LiveType.LiveBroadcast);
1313
+ sendLiveNotifyCard(data, LiveType.LiveBroadcast);
1265
1314
  }
1266
1315
  }
1267
1316
  // 否则继续循环
@@ -1619,7 +1668,9 @@ class ComRegister {
1619
1668
  masterAccountGuildId: koishi_1.Schema.string()
1620
1669
  }),
1621
1670
  unlockSubLimits: koishi_1.Schema.boolean().required(),
1671
+ changeMasterInfoApi: koishi_1.Schema.boolean().required(),
1622
1672
  liveStartAtAll: koishi_1.Schema.boolean().required(),
1673
+ pushUrl: koishi_1.Schema.boolean().required(),
1623
1674
  pushTime: koishi_1.Schema.number().required(),
1624
1675
  liveLoopTime: koishi_1.Schema.number().default(10),
1625
1676
  customLiveStart: koishi_1.Schema.string().required(),
package/lib/database.js CHANGED
@@ -1,6 +1,7 @@
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表
@@ -22,4 +23,3 @@ function apply(ctx) {
22
23
  time: 'timestamp'
23
24
  }, { autoInc: true });
24
25
  }
25
- exports.apply = apply;
Binary file
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Context, Schema, Service } from "koishi";
3
2
  declare module 'koishi' {
4
3
  interface Context {
@@ -9,7 +8,7 @@ declare class GenerateImg extends Service {
9
8
  static inject: string[];
10
9
  giConfig: GenerateImg.Config;
11
10
  constructor(ctx: Context, config: GenerateImg.Config);
12
- generateLiveImg(data: any, userData: any, liveStatus: number): Promise<{
11
+ generateLiveImg(data: any, username: string, userface: string, liveStatus: number): Promise<{
13
12
  buffer: Buffer;
14
13
  pic?: undefined;
15
14
  } | {
@@ -50,7 +50,7 @@ class GenerateImg extends koishi_1.Service {
50
50
  protected stop(): void | Promise<void> {
51
51
  this.logger.info('已停止工作')
52
52
  } */
53
- async generateLiveImg(data, userData, liveStatus /*0未开播 1刚开播 2已开播 */) {
53
+ async generateLiveImg(data, username, userface, liveStatus /*0未开播 1刚开播 2已开播 */) {
54
54
  const [titleStatus, liveTime, cover] = await this.getLiveStatus(data.live_time, liveStatus);
55
55
  // 加载字体
56
56
  const fontURL = (0, url_1.pathToFileURL)((0, path_1.resolve)(__dirname, 'font/HYZhengYuan-75W.ttf'));
@@ -176,8 +176,8 @@ class GenerateImg extends koishi_1.Service {
176
176
  <div class="live-broadcast-info">
177
177
  <!-- 主播头像 -->
178
178
  <img style="border-radius: 10px; margin-left: 10px" class="anchor-avatar"
179
- src="${userData.info.face}" alt="主播头像">
180
- <span class="broadcast-message">${userData.info.uname}${titleStatus}</span>
179
+ src="${userface}" alt="主播头像">
180
+ <span class="broadcast-message">${username}${titleStatus}</span>
181
181
  </div>
182
182
  </div>
183
183
  ${this.giConfig.hideDesc ? '' : `<p class="card-text">${data.description ? data.description : '这个主播很懒,什么都简介都没写'}</p>`}
package/lib/index.d.ts CHANGED
@@ -19,8 +19,10 @@ export interface Config {
19
19
  dynamicCheckNumber: number;
20
20
  dynamicLoopTime: '1分钟' | '2分钟' | '3分钟' | '5分钟';
21
21
  live: {};
22
- pushTime: number;
22
+ changeMasterInfoApi: boolean;
23
23
  liveStartAtAll: boolean;
24
+ pushUrl: boolean;
25
+ pushTime: number;
24
26
  customLiveStart: string;
25
27
  customLiveEnd: string;
26
28
  hideDesc: boolean;
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'
@@ -93,9 +94,17 @@ exports.Config = koishi_1.Schema.object({
93
94
  .default('2分钟')
94
95
  .description('设定多久检测一次动态。若需动态的时效性,可以设置为1分钟。若订阅的UP主经常在短时间内连着发多条动态应该将该值提高,否则会出现动态漏推送和晚推送的问题,默认值为2分钟'),
95
96
  live: koishi_1.Schema.object({}).description('直播推送设置'),
97
+ changeMasterInfoApi: koishi_1.Schema.boolean()
98
+ .default(false)
99
+ .description('是否切换获取主播信息API,在遇到错误getMasterInfo()时可以尝试切换')
100
+ .experimental(),
96
101
  liveStartAtAll: koishi_1.Schema.boolean()
97
102
  .default(false)
98
103
  .description('直播开始时艾特全体成员,默认关闭'),
104
+ pushUrl: koishi_1.Schema.boolean()
105
+ .default(false)
106
+ .description('推送直播状态时是否同时发送链接。注意:如果使用的是QQ官方机器人不能开启此项!')
107
+ .experimental(),
99
108
  pushTime: koishi_1.Schema.number()
100
109
  .min(0)
101
110
  .max(12)
@@ -257,7 +266,9 @@ class ServerManager extends koishi_1.Service {
257
266
  const cr = this.ctx.plugin(comRegister_1.default, {
258
267
  master: globalConfig.master,
259
268
  unlockSubLimits: globalConfig.unlockSubLimits,
269
+ changeMasterInfoApi: globalConfig.changeMasterInfoApi,
260
270
  liveStartAtAll: globalConfig.liveStartAtAll,
271
+ pushUrl: globalConfig.pushUrl,
261
272
  pushTime: globalConfig.pushTime,
262
273
  customLiveStart: globalConfig.customLiveStart,
263
274
  customLiveEnd: globalConfig.customLiveEnd,
@@ -347,4 +358,3 @@ function apply(ctx, config) {
347
358
  }
348
359
  });
349
360
  }
350
- 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.16",
4
+ "version": "1.3.0-alpha.0",
5
5
  "contributors": [
6
6
  "Akokko <admin@akokko.com>"
7
7
  ],
@@ -24,17 +24,17 @@
24
24
  "bilibili"
25
25
  ],
26
26
  "peerDependencies": {
27
- "koishi": "^4.17.4"
27
+ "koishi": "^4.17.5"
28
28
  },
29
29
  "dependencies": {
30
- "axios": "^1.6.8",
31
- "axios-cookiejar-support": "^5.0.1",
30
+ "axios": "^1.7.0-beta.1",
31
+ "axios-cookiejar-support": "^5.0.2",
32
32
  "jimp": "^0.22.12",
33
33
  "jsdom": "^24.0.0",
34
34
  "luxon": "^3.4.4",
35
35
  "md5": "^2.3.0",
36
36
  "qrcode": "^1.5.3",
37
- "tough-cookie": "^4.1.3"
37
+ "tough-cookie": "^4.1.4"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/luxon": "^3",
package/readme.md CHANGED
@@ -160,6 +160,7 @@
160
160
  - ver 1.2.14 优化调试模式输出,直播推送卡片添加分区信息
161
161
  - ver 1.2.15 新增直播推送卡片简介隐藏选项
162
162
  - ver 1.2.16 当存储在数据库中的登录信息被篡改时,新增控制台提示
163
+ - ver 1.3.0-alpha.0 对直播推送逻辑进行小型重构,优化了性能。新增功能:定时推送直播卡片可选是否发送直播链接;在遇到getMasterInfo()错误时,可切换获取主播信息Api
163
164
 
164
165
  ## 交流群
165
166