koishi-plugin-bilibili-notify 3.3.11-alpha.4 → 3.3.12-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.
- package/lib/index.js +35 -20
- package/lib/index.mjs +35 -20
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -710,6 +710,7 @@ var ComRegister = class {
|
|
|
710
710
|
for (const uname of Object.keys(subs)) subs[uname].uname = uname;
|
|
711
711
|
}
|
|
712
712
|
async initAsyncPart(subs) {
|
|
713
|
+
this.ctx["bilibili-notify-live"].clearListeners();
|
|
713
714
|
this.logger.info("获取到订阅信息,开始加载订阅...");
|
|
714
715
|
const groupInfoResult = await this.getGroupInfo();
|
|
715
716
|
if (groupInfoResult.code !== 0) {
|
|
@@ -1244,25 +1245,29 @@ var ComRegister = class {
|
|
|
1244
1245
|
this.logger.info("正在获取前90热词");
|
|
1245
1246
|
const words = Object.entries(danmakuWeightRecord);
|
|
1246
1247
|
const danmaker = Object.entries(danmakuMakerRecord);
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
const
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1248
|
+
const img = (async () => {
|
|
1249
|
+
if (words.length < 50) {
|
|
1250
|
+
this.logger.info("热词不足50个,本次弹幕词云放弃");
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
const top90Words = words.sort((a, b) => b[1] - a[1]).slice(0, 90);
|
|
1254
|
+
this.logger.info("弹幕词云前90词及权重:");
|
|
1255
|
+
this.logger.info(top90Words);
|
|
1256
|
+
this.logger.info("正在准备生成弹幕词云");
|
|
1257
|
+
const buffer = await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(top90Words, masterInfo.username);
|
|
1258
|
+
return koishi.h.image(buffer, "image/jpeg");
|
|
1259
|
+
})();
|
|
1260
|
+
const summary = (() => {
|
|
1261
|
+
if (danmaker.length < 5) {
|
|
1262
|
+
this.logger.info("发言人数不足5位,本次弹幕词云放弃");
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
this.logger.info("开始构建弹幕发送排行榜消息");
|
|
1266
|
+
const danmakuMakerCount = Object.keys(danmakuMakerRecord).length;
|
|
1267
|
+
const danmakuCount = Object.values(danmakuMakerRecord).reduce((sum, val) => sum + val, 0);
|
|
1268
|
+
const top5DanmakuMaker = Object.entries(danmakuMakerRecord).sort((a, b) => b[1] - a[1]).slice(0, 5);
|
|
1269
|
+
return customLiveSummary.replace("-dmc", `${danmakuMakerCount}`).replace("-mdn", `${masterInfo.medalName}`).replace("-dca", `${danmakuCount}`).replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
|
|
1270
|
+
})();
|
|
1266
1271
|
await this.broadcastToTargets(sub.uid, [img, summary], PushType.WordCloudAndLiveSummary);
|
|
1267
1272
|
Object.keys(danmakuWeightRecord).forEach((key) => delete danmakuWeightRecord[key]);
|
|
1268
1273
|
Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
|
|
@@ -4164,9 +4169,13 @@ var BLive = class extends koishi.Service {
|
|
|
4164
4169
|
super(ctx, "bilibili-notify-live");
|
|
4165
4170
|
}
|
|
4166
4171
|
stop() {
|
|
4167
|
-
|
|
4172
|
+
this.clearListeners();
|
|
4168
4173
|
}
|
|
4169
4174
|
async startLiveRoomListener(roomId, handler) {
|
|
4175
|
+
if (this.listenerRecord[roomId]) {
|
|
4176
|
+
this.logger.warn(`[${roomId}]直播间连接已存在,无法重复创建!`);
|
|
4177
|
+
return;
|
|
4178
|
+
}
|
|
4170
4179
|
const cookiesStr = await this.ctx["bilibili-notify-api"].getCookiesForHeader();
|
|
4171
4180
|
const mySelfInfo = await this.ctx["bilibili-notify-api"].getMyselfInfo();
|
|
4172
4181
|
this.listenerRecord[roomId] = (0, blive_message_listener.startListen)(Number.parseInt(roomId), handler, { ws: {
|
|
@@ -4185,6 +4194,12 @@ var BLive = class extends koishi.Service {
|
|
|
4185
4194
|
}
|
|
4186
4195
|
this.logger.warn(`${roomId}直播间连接未成功关闭`);
|
|
4187
4196
|
}
|
|
4197
|
+
clearListeners() {
|
|
4198
|
+
for (const key of Object.keys(this.listenerRecord)) {
|
|
4199
|
+
this.closeListener(key);
|
|
4200
|
+
delete this.listenerRecord[key];
|
|
4201
|
+
}
|
|
4202
|
+
}
|
|
4188
4203
|
};
|
|
4189
4204
|
var bili_live_default = BLive;
|
|
4190
4205
|
|
package/lib/index.mjs
CHANGED
|
@@ -692,6 +692,7 @@ var ComRegister = class {
|
|
|
692
692
|
for (const uname of Object.keys(subs)) subs[uname].uname = uname;
|
|
693
693
|
}
|
|
694
694
|
async initAsyncPart(subs) {
|
|
695
|
+
this.ctx["bilibili-notify-live"].clearListeners();
|
|
695
696
|
this.logger.info("获取到订阅信息,开始加载订阅...");
|
|
696
697
|
const groupInfoResult = await this.getGroupInfo();
|
|
697
698
|
if (groupInfoResult.code !== 0) {
|
|
@@ -1226,25 +1227,29 @@ var ComRegister = class {
|
|
|
1226
1227
|
this.logger.info("正在获取前90热词");
|
|
1227
1228
|
const words = Object.entries(danmakuWeightRecord);
|
|
1228
1229
|
const danmaker = Object.entries(danmakuMakerRecord);
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
const
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1230
|
+
const img = (async () => {
|
|
1231
|
+
if (words.length < 50) {
|
|
1232
|
+
this.logger.info("热词不足50个,本次弹幕词云放弃");
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
const top90Words = words.sort((a, b) => b[1] - a[1]).slice(0, 90);
|
|
1236
|
+
this.logger.info("弹幕词云前90词及权重:");
|
|
1237
|
+
this.logger.info(top90Words);
|
|
1238
|
+
this.logger.info("正在准备生成弹幕词云");
|
|
1239
|
+
const buffer = await this.ctx["bilibili-notify-generate-img"].generateWordCloudImg(top90Words, masterInfo.username);
|
|
1240
|
+
return h.image(buffer, "image/jpeg");
|
|
1241
|
+
})();
|
|
1242
|
+
const summary = (() => {
|
|
1243
|
+
if (danmaker.length < 5) {
|
|
1244
|
+
this.logger.info("发言人数不足5位,本次弹幕词云放弃");
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
this.logger.info("开始构建弹幕发送排行榜消息");
|
|
1248
|
+
const danmakuMakerCount = Object.keys(danmakuMakerRecord).length;
|
|
1249
|
+
const danmakuCount = Object.values(danmakuMakerRecord).reduce((sum, val) => sum + val, 0);
|
|
1250
|
+
const top5DanmakuMaker = Object.entries(danmakuMakerRecord).sort((a, b) => b[1] - a[1]).slice(0, 5);
|
|
1251
|
+
return customLiveSummary.replace("-dmc", `${danmakuMakerCount}`).replace("-mdn", `${masterInfo.medalName}`).replace("-dca", `${danmakuCount}`).replace("-un1", `${top5DanmakuMaker[0][0]}`).replace("-dc1", `${top5DanmakuMaker[0][1]}`).replace("-un2", `${top5DanmakuMaker[1][0]}`).replace("-dc2", `${top5DanmakuMaker[1][1]}`).replace("-un3", `${top5DanmakuMaker[2][0]}`).replace("-dc3", `${top5DanmakuMaker[2][1]}`).replace("-un4", `${top5DanmakuMaker[3][0]}`).replace("-dc4", `${top5DanmakuMaker[3][1]}`).replace("-un5", `${top5DanmakuMaker[4][0]}`).replace("-dc5", `${top5DanmakuMaker[4][1]}`).replaceAll("\\n", "\n");
|
|
1252
|
+
})();
|
|
1248
1253
|
await this.broadcastToTargets(sub.uid, [img, summary], PushType.WordCloudAndLiveSummary);
|
|
1249
1254
|
Object.keys(danmakuWeightRecord).forEach((key) => delete danmakuWeightRecord[key]);
|
|
1250
1255
|
Object.keys(danmakuMakerRecord).forEach((key) => delete danmakuMakerRecord[key]);
|
|
@@ -4146,9 +4151,13 @@ var BLive = class extends Service {
|
|
|
4146
4151
|
super(ctx, "bilibili-notify-live");
|
|
4147
4152
|
}
|
|
4148
4153
|
stop() {
|
|
4149
|
-
|
|
4154
|
+
this.clearListeners();
|
|
4150
4155
|
}
|
|
4151
4156
|
async startLiveRoomListener(roomId, handler) {
|
|
4157
|
+
if (this.listenerRecord[roomId]) {
|
|
4158
|
+
this.logger.warn(`[${roomId}]直播间连接已存在,无法重复创建!`);
|
|
4159
|
+
return;
|
|
4160
|
+
}
|
|
4152
4161
|
const cookiesStr = await this.ctx["bilibili-notify-api"].getCookiesForHeader();
|
|
4153
4162
|
const mySelfInfo = await this.ctx["bilibili-notify-api"].getMyselfInfo();
|
|
4154
4163
|
this.listenerRecord[roomId] = startListen(Number.parseInt(roomId), handler, { ws: {
|
|
@@ -4167,6 +4176,12 @@ var BLive = class extends Service {
|
|
|
4167
4176
|
}
|
|
4168
4177
|
this.logger.warn(`${roomId}直播间连接未成功关闭`);
|
|
4169
4178
|
}
|
|
4179
|
+
clearListeners() {
|
|
4180
|
+
for (const key of Object.keys(this.listenerRecord)) {
|
|
4181
|
+
this.closeListener(key);
|
|
4182
|
+
delete this.listenerRecord[key];
|
|
4183
|
+
}
|
|
4184
|
+
}
|
|
4170
4185
|
};
|
|
4171
4186
|
var bili_live_default = BLive;
|
|
4172
4187
|
|