koishi-plugin-bilibili-notify 3.0.0-alpha.17 → 3.0.0-alpha.19
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/comRegister.d.ts +1 -0
- package/lib/comRegister.js +52 -352
- package/lib/generateImg.d.ts +0 -1
- package/lib/generateImg.js +3 -32
- package/lib/index.js +14 -14
- package/package.json +1 -1
- package/readme.md +5 -1
package/lib/comRegister.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ declare class ComRegister {
|
|
|
21
21
|
constructor(ctx: Context, config: ComRegister.Config);
|
|
22
22
|
init(config: ComRegister.Config): Promise<void>;
|
|
23
23
|
getBot(pf: string): Bot<Context, any>;
|
|
24
|
+
test_wordCloud(): Promise<void>;
|
|
24
25
|
sendPrivateMsg(content: string): Promise<void>;
|
|
25
26
|
sendPrivateMsgAndRebootService(): Promise<void>;
|
|
26
27
|
sendPrivateMsgAndStopService(): Promise<void>;
|
package/lib/comRegister.js
CHANGED
|
@@ -4,13 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const jsx_runtime_1 = require("@satorijs/element/jsx-runtime");
|
|
7
|
+
// Koishi核心依赖
|
|
7
8
|
const koishi_1 = require("koishi");
|
|
8
|
-
//
|
|
9
|
+
// 外部依赖:qrcode
|
|
9
10
|
const qrcode_1 = __importDefault(require("qrcode"));
|
|
11
|
+
// Types
|
|
10
12
|
const type_1 = require("./type");
|
|
11
|
-
// 弹幕词云
|
|
12
|
-
// TODO:WorlCloud
|
|
13
|
-
// import { Segment } from "segmentit";
|
|
14
13
|
class ComRegister {
|
|
15
14
|
// 必须服务
|
|
16
15
|
static inject = ["ba", "gi", "database", "bl", "sm"];
|
|
@@ -284,8 +283,33 @@ class ComRegister {
|
|
|
284
283
|
this.checkIfDynamicDetectIsNeeded();
|
|
285
284
|
// 在控制台中显示订阅对象
|
|
286
285
|
this.updateSubNotifier();
|
|
287
|
-
|
|
288
|
-
|
|
286
|
+
}
|
|
287
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
288
|
+
getBot(pf) {
|
|
289
|
+
return this.ctx.bots.find((bot) => bot.platform === pf);
|
|
290
|
+
}
|
|
291
|
+
// TODO:WordCloud
|
|
292
|
+
async test_wordCloud() {
|
|
293
|
+
/* const currentLiveDanmakuArr = []
|
|
294
|
+
// 定义获取弹幕权重Record函数
|
|
295
|
+
const getDanmakuWeightRecord = (): Record<string, number> => {
|
|
296
|
+
// 创建segmentit
|
|
297
|
+
const segmentit = useDefault(new Segment());
|
|
298
|
+
// 创建Record
|
|
299
|
+
const danmakuWeightRecord: Record<string, number> = {};
|
|
300
|
+
// 循环遍历currentLiveDanmakuArr
|
|
301
|
+
for (const danmaku of currentLiveDanmakuArr) {
|
|
302
|
+
// 遍历结果
|
|
303
|
+
segmentit.doSegment(danmaku).map((word: { w: string; p: number }) => {
|
|
304
|
+
// 定义权重
|
|
305
|
+
danmakuWeightRecord[word.w] = (danmakuWeightRecord[word.w] || 0) + 1;
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
// 返回Record
|
|
309
|
+
return danmakuWeightRecord;
|
|
310
|
+
}; */
|
|
311
|
+
// Test
|
|
312
|
+
const testTarget = [
|
|
289
313
|
{
|
|
290
314
|
channelIdArr: [
|
|
291
315
|
{
|
|
@@ -299,13 +323,6 @@ class ComRegister {
|
|
|
299
323
|
platform: "qqguild",
|
|
300
324
|
},
|
|
301
325
|
];
|
|
302
|
-
|
|
303
|
-
const buffer = await this.ctx.gi.generateWordCloudImg();
|
|
304
|
-
this.sendMsg(testTarget, h.image(buffer, "image/png")); */
|
|
305
|
-
}
|
|
306
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
307
|
-
getBot(pf) {
|
|
308
|
-
return this.ctx.bots.find((bot) => bot.platform === pf);
|
|
309
326
|
}
|
|
310
327
|
async sendPrivateMsg(content) {
|
|
311
328
|
if (this.config.master.enable) {
|
|
@@ -911,323 +928,6 @@ class ComRegister {
|
|
|
911
928
|
}
|
|
912
929
|
return content.data;
|
|
913
930
|
}
|
|
914
|
-
/* async liveDetectWithAPI() {
|
|
915
|
-
// 定义变量:第一次订阅
|
|
916
|
-
let liveDetectSetup = true;
|
|
917
|
-
// 定义变量:timer计时器
|
|
918
|
-
let timer = 0;
|
|
919
|
-
// 相当于锁的作用,防止上一个循环没处理完
|
|
920
|
-
let flag = true;
|
|
921
|
-
// 定义订阅对象Record 0未开播 1正在直播 2轮播中
|
|
922
|
-
const liveRecord: Record<
|
|
923
|
-
number,
|
|
924
|
-
{
|
|
925
|
-
liveStatus: number;
|
|
926
|
-
liveTime: string;
|
|
927
|
-
target: Target;
|
|
928
|
-
}
|
|
929
|
-
> = {};
|
|
930
|
-
|
|
931
|
-
// 定义函数: 发送请求获取直播状态
|
|
932
|
-
const useLiveStatus = async (roomId: string) => {
|
|
933
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
934
|
-
let content: any;
|
|
935
|
-
const attempts = 3;
|
|
936
|
-
for (let i = 0; i < attempts; i++) {
|
|
937
|
-
try {
|
|
938
|
-
// 发送请求获取room信息
|
|
939
|
-
content = await this.ctx.ba.getLiveRoomInfo(roomId);
|
|
940
|
-
// 成功则跳出循环
|
|
941
|
-
break;
|
|
942
|
-
} catch (e) {
|
|
943
|
-
this.logger.error(
|
|
944
|
-
`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`,
|
|
945
|
-
);
|
|
946
|
-
if (i === attempts - 1) {
|
|
947
|
-
// 已尝试三次
|
|
948
|
-
// 发送私聊消息并重启服务
|
|
949
|
-
return await this.sendPrivateMsgAndStopService();
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
// 返回data
|
|
954
|
-
return content.data;
|
|
955
|
-
};
|
|
956
|
-
|
|
957
|
-
return async () => {
|
|
958
|
-
// 如果flag为false则说明前面的代码还未执行完,则直接返回
|
|
959
|
-
if (!flag) return;
|
|
960
|
-
// 将标志位置为false
|
|
961
|
-
flag = false;
|
|
962
|
-
try {
|
|
963
|
-
// 获取正在直播对象
|
|
964
|
-
const liveUsers = await this.ctx.ba.getTheUserWhoIsLiveStreaming();
|
|
965
|
-
// 判断是否是初始化直播监测
|
|
966
|
-
if (liveDetectSetup) {
|
|
967
|
-
// 将第一次订阅置为false
|
|
968
|
-
liveDetectSetup = false;
|
|
969
|
-
// 初始化subRecord
|
|
970
|
-
for (const sub of this.subManager) {
|
|
971
|
-
// 判断是否订阅直播
|
|
972
|
-
if (sub.live) {
|
|
973
|
-
// 将该订阅添加到subRecord中
|
|
974
|
-
liveRecord[sub.uid] = {
|
|
975
|
-
liveStatus: 0,
|
|
976
|
-
liveTime: "",
|
|
977
|
-
target: sub.target,
|
|
978
|
-
};
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
// 先判断是否有UP主正在直播
|
|
982
|
-
if (liveUsers.count > 0) {
|
|
983
|
-
// 遍历liveUsers
|
|
984
|
-
for (const item of liveUsers.items) {
|
|
985
|
-
// 判断是否有订阅对象正在直播
|
|
986
|
-
if (liveRecord[item.mid]) {
|
|
987
|
-
// 获取当前用户直播间信息
|
|
988
|
-
const data = await useLiveStatus(item.room_id.toString());
|
|
989
|
-
// 设置开播时间
|
|
990
|
-
liveRecord[item.mid].liveTime = data.live_time;
|
|
991
|
-
// 改变开播状态
|
|
992
|
-
liveRecord[item.mid].liveStatus = 1;
|
|
993
|
-
// 设置直播中消息
|
|
994
|
-
const liveMsg = this.config.customLive
|
|
995
|
-
? this.config.customLive
|
|
996
|
-
.replace("-name", item.uname)
|
|
997
|
-
.replace(
|
|
998
|
-
"-time",
|
|
999
|
-
await this.ctx.gi.getTimeDifference(
|
|
1000
|
-
liveRecord[item.mid].liveTime,
|
|
1001
|
-
),
|
|
1002
|
-
)
|
|
1003
|
-
.replace(
|
|
1004
|
-
"-link",
|
|
1005
|
-
`https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`,
|
|
1006
|
-
)
|
|
1007
|
-
: null;
|
|
1008
|
-
// 发送直播通知卡片
|
|
1009
|
-
if (this.config.restartPush)
|
|
1010
|
-
this.sendLiveNotifyCard(
|
|
1011
|
-
{
|
|
1012
|
-
username: item.uname,
|
|
1013
|
-
userface: item.face,
|
|
1014
|
-
target: liveRecord[item.mid].target,
|
|
1015
|
-
data,
|
|
1016
|
-
},
|
|
1017
|
-
LiveType.LiveBroadcast,
|
|
1018
|
-
liveMsg,
|
|
1019
|
-
);
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
// 没有正在直播的订阅对象,直接返回
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
// 获取当前订阅直播的数量
|
|
1027
|
-
const currentLiveSubs = this.subManager.filter((sub) => sub.live);
|
|
1028
|
-
// 获取当前liveRecord里的订阅数量
|
|
1029
|
-
const currentLiveRecordKeys = Object.keys(liveRecord);
|
|
1030
|
-
// 判断是否能匹配双方数量
|
|
1031
|
-
if (currentLiveRecordKeys.length < currentLiveSubs.length) {
|
|
1032
|
-
// 遍历currentLiveSubs
|
|
1033
|
-
for (const sub of currentLiveSubs) {
|
|
1034
|
-
// 判断liveRecord中缺少了哪些订阅
|
|
1035
|
-
if (!liveRecord[sub.uid]) {
|
|
1036
|
-
// 获取当前用户直播间信息
|
|
1037
|
-
const data = await useLiveStatus(sub.roomId.toString());
|
|
1038
|
-
switch (data.live_status) {
|
|
1039
|
-
case 0:
|
|
1040
|
-
case 2: {
|
|
1041
|
-
// 未开播
|
|
1042
|
-
// 添加到liveRecord中
|
|
1043
|
-
liveRecord[sub.uid] = {
|
|
1044
|
-
liveStatus: 0,
|
|
1045
|
-
liveTime: "",
|
|
1046
|
-
target: sub.target,
|
|
1047
|
-
};
|
|
1048
|
-
// break
|
|
1049
|
-
break;
|
|
1050
|
-
}
|
|
1051
|
-
case 1: {
|
|
1052
|
-
//正在直播
|
|
1053
|
-
// 添加到liveRecord中
|
|
1054
|
-
liveRecord[sub.uid] = {
|
|
1055
|
-
liveStatus: 1,
|
|
1056
|
-
liveTime: data.live_time,
|
|
1057
|
-
target: sub.target,
|
|
1058
|
-
};
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
if (currentLiveRecordKeys.length > currentLiveSubs.length) {
|
|
1065
|
-
// 创建Set
|
|
1066
|
-
const setCurrentLiveSubs = new Set(
|
|
1067
|
-
currentLiveSubs.map((sub) => sub.uid),
|
|
1068
|
-
);
|
|
1069
|
-
// 找出 currentLiveRecordKeys中比currentLiveSubs 多的元素
|
|
1070
|
-
const extraInCurrentLiveSubs = currentLiveRecordKeys.filter(
|
|
1071
|
-
(key) => !setCurrentLiveSubs.has(key),
|
|
1072
|
-
);
|
|
1073
|
-
// 遍历 extraInCurrentLiveSubs
|
|
1074
|
-
for (const subUID of extraInCurrentLiveSubs) {
|
|
1075
|
-
// 删除记录
|
|
1076
|
-
delete liveRecord[subUID];
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
// 数量没有差异,则不进行其他操作
|
|
1080
|
-
// 遍历liveUsers
|
|
1081
|
-
for (const item of liveUsers.items) {
|
|
1082
|
-
// 判断是否有正在直播的订阅对象
|
|
1083
|
-
if (liveRecord[item.mid]) {
|
|
1084
|
-
// 有正在直播的订阅对象
|
|
1085
|
-
// 获取当前用户直播间信息
|
|
1086
|
-
const data = await useLiveStatus(item.room_id.toString());
|
|
1087
|
-
// 判断开播状态
|
|
1088
|
-
switch (liveRecord[item.mid].liveStatus) {
|
|
1089
|
-
case 0: {
|
|
1090
|
-
// 之前未开播,现在开播了
|
|
1091
|
-
// 设置开播时间
|
|
1092
|
-
liveRecord[item.mid].liveTime = data.live_time;
|
|
1093
|
-
// 定义开播通知语
|
|
1094
|
-
const liveStartMsg = this.config.customLiveStart
|
|
1095
|
-
? this.config.customLiveStart
|
|
1096
|
-
.replace("-name", item.uname)
|
|
1097
|
-
.replace(
|
|
1098
|
-
"-time",
|
|
1099
|
-
await this.ctx.gi.getTimeDifference(
|
|
1100
|
-
liveRecord[item.mid].liveTime,
|
|
1101
|
-
),
|
|
1102
|
-
)
|
|
1103
|
-
.replace(
|
|
1104
|
-
"-link",
|
|
1105
|
-
`https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`,
|
|
1106
|
-
)
|
|
1107
|
-
: null;
|
|
1108
|
-
// 发送直播通知卡片
|
|
1109
|
-
await this.sendLiveNotifyCard(
|
|
1110
|
-
{
|
|
1111
|
-
username: item.uname,
|
|
1112
|
-
userface: item.face,
|
|
1113
|
-
target: liveRecord[item.mid].target,
|
|
1114
|
-
data,
|
|
1115
|
-
},
|
|
1116
|
-
LiveType.LiveBroadcast,
|
|
1117
|
-
liveStartMsg,
|
|
1118
|
-
);
|
|
1119
|
-
// 改变开播状态
|
|
1120
|
-
liveRecord[item.mid].liveStatus = 1;
|
|
1121
|
-
// 结束
|
|
1122
|
-
break;
|
|
1123
|
-
}
|
|
1124
|
-
case 1: {
|
|
1125
|
-
// 仍在直播
|
|
1126
|
-
if (this.config.pushTime > 0) {
|
|
1127
|
-
timer++;
|
|
1128
|
-
// 开始记录时间
|
|
1129
|
-
if (timer >= 6 * 60 * this.config.pushTime) {
|
|
1130
|
-
// 到时间推送直播消息
|
|
1131
|
-
// 到时间重新计时
|
|
1132
|
-
timer = 0;
|
|
1133
|
-
// 定义直播中通知消息
|
|
1134
|
-
const liveMsg = this.config.customLive
|
|
1135
|
-
? this.config.customLive
|
|
1136
|
-
.replace("-name", item.uname)
|
|
1137
|
-
.replace(
|
|
1138
|
-
"-time",
|
|
1139
|
-
await this.ctx.gi.getTimeDifference(
|
|
1140
|
-
liveRecord[item.mid].liveTime,
|
|
1141
|
-
),
|
|
1142
|
-
)
|
|
1143
|
-
.replace(
|
|
1144
|
-
"-link",
|
|
1145
|
-
`https://live.bilibili.com/${data.short_id === 0 ? data.room_id : data.short_id}`,
|
|
1146
|
-
)
|
|
1147
|
-
: null;
|
|
1148
|
-
// 发送直播通知卡片
|
|
1149
|
-
this.sendLiveNotifyCard(
|
|
1150
|
-
{
|
|
1151
|
-
username: item.uname,
|
|
1152
|
-
userface: item.face,
|
|
1153
|
-
target: liveRecord[item.mid].target,
|
|
1154
|
-
data,
|
|
1155
|
-
},
|
|
1156
|
-
LiveType.LiveBroadcast,
|
|
1157
|
-
liveMsg,
|
|
1158
|
-
);
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
// 找出liveRecord中liveStatus为1但liveUsers中没有的元素
|
|
1166
|
-
const extraInLiveRecord = currentLiveRecordKeys.filter(
|
|
1167
|
-
(key) => !liveUsers.items.some((item) => item.mid === Number(key)),
|
|
1168
|
-
);
|
|
1169
|
-
// 遍历 extraInLiveRecord
|
|
1170
|
-
for (const subUID of extraInLiveRecord) {
|
|
1171
|
-
// 下播的主播
|
|
1172
|
-
// 获取主播信息
|
|
1173
|
-
const masterInfo = await this.useMasterInfo(subUID);
|
|
1174
|
-
// 获取直播间消息
|
|
1175
|
-
const liveRoomInfo = await this.useLiveRoomInfo(
|
|
1176
|
-
masterInfo.roomId.toString(),
|
|
1177
|
-
);
|
|
1178
|
-
// 设置开播时间
|
|
1179
|
-
liveRoomInfo.live_time = liveRecord[subUID].liveTime;
|
|
1180
|
-
// 定义下播播通知语
|
|
1181
|
-
const liveEndMsg = this.config.customLiveEnd
|
|
1182
|
-
? this.config.customLiveEnd
|
|
1183
|
-
.replace("-name", masterInfo.username)
|
|
1184
|
-
.replace(
|
|
1185
|
-
"-time",
|
|
1186
|
-
await this.ctx.gi.getTimeDifference(
|
|
1187
|
-
liveRecord[subUID].liveTime,
|
|
1188
|
-
),
|
|
1189
|
-
)
|
|
1190
|
-
.replace(
|
|
1191
|
-
"-link",
|
|
1192
|
-
`https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`,
|
|
1193
|
-
)
|
|
1194
|
-
: null;
|
|
1195
|
-
// 发送下播通知
|
|
1196
|
-
this.sendLiveNotifyCard(
|
|
1197
|
-
{
|
|
1198
|
-
username: masterInfo.username,
|
|
1199
|
-
userface: masterInfo.userface,
|
|
1200
|
-
target: liveRecord[subUID].target,
|
|
1201
|
-
data: liveRoomInfo,
|
|
1202
|
-
},
|
|
1203
|
-
LiveType.StopBroadcast,
|
|
1204
|
-
liveEndMsg,
|
|
1205
|
-
);
|
|
1206
|
-
}
|
|
1207
|
-
} finally {
|
|
1208
|
-
// 执行完方法体不论如何都把flag设置为true
|
|
1209
|
-
flag = true;
|
|
1210
|
-
}
|
|
1211
|
-
};
|
|
1212
|
-
} */
|
|
1213
|
-
// TODO:WordCloud
|
|
1214
|
-
/* // 定义获取弹幕权重Record函数
|
|
1215
|
-
const getDanmakuWeightRecord = (): Record<string, number> => {
|
|
1216
|
-
// 创建segmentit
|
|
1217
|
-
const segmentit = useDefault(new Segment());
|
|
1218
|
-
// 创建Record
|
|
1219
|
-
const danmakuWeightRecord: Record<string, number> = {};
|
|
1220
|
-
// 循环遍历currentLiveDanmakuArr
|
|
1221
|
-
for (const danmaku of currentLiveDanmakuArr) {
|
|
1222
|
-
// 遍历结果
|
|
1223
|
-
segmentit.doSegment(danmaku).map((word: { w: string; p: number }) => {
|
|
1224
|
-
// 定义权重
|
|
1225
|
-
danmakuWeightRecord[word.w] = (danmakuWeightRecord[word.w] || 0) + 1;
|
|
1226
|
-
});
|
|
1227
|
-
}
|
|
1228
|
-
// 返回Record
|
|
1229
|
-
return danmakuWeightRecord;
|
|
1230
|
-
}; */
|
|
1231
931
|
async liveDetectWithListener(roomId, target) {
|
|
1232
932
|
// 定义开播时间
|
|
1233
933
|
let liveTime;
|
|
@@ -1267,7 +967,7 @@ class ComRegister {
|
|
|
1267
967
|
// 设置开播时间
|
|
1268
968
|
liveTime = liveRoomInfo.live_time;
|
|
1269
969
|
// 获取watched
|
|
1270
|
-
const watched = watchedNum
|
|
970
|
+
const watched = watchedNum || "暂未获取到";
|
|
1271
971
|
// 设置直播中消息
|
|
1272
972
|
const liveMsg = this.config.customLive
|
|
1273
973
|
? this.config.customLive
|
|
@@ -1324,7 +1024,7 @@ class ComRegister {
|
|
|
1324
1024
|
},
|
|
1325
1025
|
onWatchedChange: ({ body }) => {
|
|
1326
1026
|
// 保存观看人数到变量
|
|
1327
|
-
watchedNum = body.
|
|
1027
|
+
watchedNum = body.text_small;
|
|
1328
1028
|
},
|
|
1329
1029
|
onGuardBuy: ({ body }) => {
|
|
1330
1030
|
// 定义消息
|
|
@@ -1348,7 +1048,9 @@ class ComRegister {
|
|
|
1348
1048
|
// 设置开播时间
|
|
1349
1049
|
liveTime = liveRoomInfo.live_time;
|
|
1350
1050
|
// 获取当前粉丝数
|
|
1351
|
-
const follower = masterInfo.liveOpenFollowerNum
|
|
1051
|
+
const follower = masterInfo.liveOpenFollowerNum >= 10_000
|
|
1052
|
+
? `${(masterInfo.liveOpenFollowerNum / 10000).toFixed(1)}万`
|
|
1053
|
+
: masterInfo.liveOpenFollowerNum.toString();
|
|
1352
1054
|
// 定义开播通知语
|
|
1353
1055
|
const liveStartMsg = this.config.customLiveStart
|
|
1354
1056
|
? this.config.customLiveStart
|
|
@@ -1381,7 +1083,21 @@ class ComRegister {
|
|
|
1381
1083
|
// 更改直播时长
|
|
1382
1084
|
liveRoomInfo.live_time = liveTime;
|
|
1383
1085
|
// 获取粉丝数变化
|
|
1384
|
-
const followerChange =
|
|
1086
|
+
const followerChange = (() => {
|
|
1087
|
+
// 获取直播关注变化值
|
|
1088
|
+
const liveFollowerChangeNum = masterInfo.liveFollowerChange;
|
|
1089
|
+
// 判断是否大于0
|
|
1090
|
+
if (liveFollowerChangeNum > 0) {
|
|
1091
|
+
// 大于0则加+
|
|
1092
|
+
return liveFollowerChangeNum >= 10_000
|
|
1093
|
+
? `+${liveFollowerChangeNum.toFixed(1)}万`
|
|
1094
|
+
: `+${liveFollowerChangeNum}`;
|
|
1095
|
+
}
|
|
1096
|
+
// 小于0
|
|
1097
|
+
return liveFollowerChangeNum <= -10_000
|
|
1098
|
+
? `${liveFollowerChangeNum.toFixed(1)}万`
|
|
1099
|
+
: liveFollowerChangeNum.toString();
|
|
1100
|
+
})();
|
|
1385
1101
|
// 定义下播播通知语
|
|
1386
1102
|
const liveEndMsg = this.config.customLiveEnd
|
|
1387
1103
|
? this.config.customLiveEnd
|
|
@@ -1414,7 +1130,7 @@ class ComRegister {
|
|
|
1414
1130
|
// 设置开播时间
|
|
1415
1131
|
liveTime = liveRoomInfo.live_time;
|
|
1416
1132
|
// 获取当前累计观看人数
|
|
1417
|
-
const watched = watchedNum
|
|
1133
|
+
const watched = watchedNum || "暂未获取到";
|
|
1418
1134
|
// 定义直播中通知消息
|
|
1419
1135
|
const liveMsg = this.config.customLive
|
|
1420
1136
|
? this.config.customLive
|
|
@@ -1631,26 +1347,10 @@ class ComRegister {
|
|
|
1631
1347
|
// 发送提示
|
|
1632
1348
|
this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
|
|
1633
1349
|
}
|
|
1634
|
-
// 直播类型模式匹配
|
|
1635
|
-
const liveDetectModeSelector = {
|
|
1636
|
-
API: async () => {
|
|
1637
|
-
// 判断是否已开启直播检测
|
|
1638
|
-
if (!this.liveDispose) {
|
|
1639
|
-
// 未开启直播检测
|
|
1640
|
-
// 开启直播检测并保存销毁函数
|
|
1641
|
-
// this.liveDispose = await this.liveDetectWithAPI();
|
|
1642
|
-
this.logger.warn("API模式暂时不可用");
|
|
1643
|
-
}
|
|
1644
|
-
},
|
|
1645
|
-
WS: async () => {
|
|
1646
|
-
// 连接到服务器
|
|
1647
|
-
await this.liveDetectWithListener(data.live_room.roomid, sub.target);
|
|
1648
|
-
},
|
|
1649
|
-
};
|
|
1650
1350
|
// 判断是否订阅直播
|
|
1651
1351
|
if (sub.live) {
|
|
1652
1352
|
// 启动直播监测
|
|
1653
|
-
await
|
|
1353
|
+
await this.liveDetectWithListener(data.live_room.roomid, sub.target);
|
|
1654
1354
|
}
|
|
1655
1355
|
}
|
|
1656
1356
|
// 在B站中订阅该对象
|
package/lib/generateImg.d.ts
CHANGED
|
@@ -24,7 +24,6 @@ declare class GenerateImg extends Service {
|
|
|
24
24
|
link: string;
|
|
25
25
|
buffer?: undefined;
|
|
26
26
|
}>;
|
|
27
|
-
generateWordCloudImg(): Promise<Buffer<ArrayBufferLike>>;
|
|
28
27
|
getLiveStatus(time: string, liveStatus: number): Promise<[string, string, boolean]>;
|
|
29
28
|
getTimeDifference(dateString: string): Promise<string>;
|
|
30
29
|
unixTimestampToString(timestamp: number): string;
|
package/lib/generateImg.js
CHANGED
|
@@ -171,11 +171,11 @@ class GenerateImg extends koishi_1.Service {
|
|
|
171
171
|
? /* html */ `
|
|
172
172
|
<span>
|
|
173
173
|
${liveStatus === 1
|
|
174
|
-
?
|
|
174
|
+
? `当前粉丝数:${followerDisplay}`
|
|
175
175
|
: liveStatus === 2
|
|
176
|
-
?
|
|
176
|
+
? `累计观看人数:${followerDisplay}`
|
|
177
177
|
: liveStatus === 3
|
|
178
|
-
?
|
|
178
|
+
? `粉丝数变化:${followerDisplay}`
|
|
179
179
|
: ""}
|
|
180
180
|
</span>`
|
|
181
181
|
: ""}
|
|
@@ -1429,35 +1429,6 @@ class GenerateImg extends koishi_1.Service {
|
|
|
1429
1429
|
}
|
|
1430
1430
|
}
|
|
1431
1431
|
}
|
|
1432
|
-
async generateWordCloudImg() {
|
|
1433
|
-
const page = await this.ctx.puppeteer.page();
|
|
1434
|
-
// 创建HTML内容
|
|
1435
|
-
const htmlContent = /* html */ `
|
|
1436
|
-
<!DOCTYPE html>
|
|
1437
|
-
<html>
|
|
1438
|
-
<head>
|
|
1439
|
-
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.0/dist/echarts.min.js"></script>
|
|
1440
|
-
</head>
|
|
1441
|
-
<body>
|
|
1442
|
-
<div id="chart" style="width:800px;height:600px;"></div>
|
|
1443
|
-
<script>
|
|
1444
|
-
const chart = echarts.init(document.getElementById('chart'));
|
|
1445
|
-
chart.setOption({
|
|
1446
|
-
title: { text: 'Node.js ECharts示例' },
|
|
1447
|
-
tooltip: {},
|
|
1448
|
-
xAxis: { data: ['A', 'B', 'C', 'D', 'E'] },
|
|
1449
|
-
yAxis: {},
|
|
1450
|
-
series: [{ name: '数据', type: 'bar', data: [5, 20, 36, 10, 15] }]
|
|
1451
|
-
});
|
|
1452
|
-
</script>
|
|
1453
|
-
</body>
|
|
1454
|
-
</html>
|
|
1455
|
-
`;
|
|
1456
|
-
// 加载HTML并截图
|
|
1457
|
-
await page.setContent(htmlContent);
|
|
1458
|
-
const buffer = await page.screenshot({ path: "output.png" });
|
|
1459
|
-
return buffer;
|
|
1460
|
-
}
|
|
1461
1432
|
async getLiveStatus(time, liveStatus) {
|
|
1462
1433
|
let titleStatus;
|
|
1463
1434
|
let liveTime;
|
package/lib/index.js
CHANGED
|
@@ -237,7 +237,7 @@ function apply(ctx, config) {
|
|
|
237
237
|
});
|
|
238
238
|
ctx.notifier.create({
|
|
239
239
|
type: "warning",
|
|
240
|
-
content: "请使用Auth
|
|
240
|
+
content: "请使用Auth插件创建超级管理员账号,没有权限将无法使用该插件提供的指令",
|
|
241
241
|
});
|
|
242
242
|
// load database
|
|
243
243
|
ctx.plugin(Database);
|
|
@@ -302,18 +302,18 @@ exports.Config = koishi_1.Schema.object({
|
|
|
302
302
|
.description("设置请求头User-Agen,请求出现-352时可以尝试修改,UA获取方法可参考:https://blog.csdn.net/qq_44503987/article/details/104929111"),
|
|
303
303
|
subTitle: koishi_1.Schema.object({}).description("订阅配置"),
|
|
304
304
|
sub: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
305
|
-
uid: koishi_1.Schema.string().description("订阅用户UID"),
|
|
306
|
-
dynamic: koishi_1.Schema.boolean().description("是否订阅用户动态"),
|
|
307
|
-
live: koishi_1.Schema.boolean().description("是否订阅用户直播"),
|
|
305
|
+
uid: koishi_1.Schema.string().required().description("订阅用户UID"),
|
|
306
|
+
dynamic: koishi_1.Schema.boolean().required().description("是否订阅用户动态"),
|
|
307
|
+
live: koishi_1.Schema.boolean().required().description("是否订阅用户直播"),
|
|
308
308
|
target: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
309
309
|
channelIdArr: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
310
|
-
channelId: koishi_1.Schema.string().description("频道/群组号"),
|
|
311
|
-
dynamic: koishi_1.Schema.boolean().description("该频道/群组是否推送动态信息"),
|
|
312
|
-
live: koishi_1.Schema.boolean().description("该频道/群组是否推送直播通知"),
|
|
313
|
-
liveGuardBuy: koishi_1.Schema.boolean().description("该频道/群组是否推送上舰消息"),
|
|
314
|
-
atAll: koishi_1.Schema.boolean().description("推送开播通知时是否艾特全体成员"),
|
|
315
|
-
})).description("需推送的频道/群组详细设置"),
|
|
316
|
-
platform: koishi_1.Schema.string().description("推送平台"),
|
|
310
|
+
channelId: koishi_1.Schema.string().required().description("频道/群组号"),
|
|
311
|
+
dynamic: koishi_1.Schema.boolean().required().description("该频道/群组是否推送动态信息"),
|
|
312
|
+
live: koishi_1.Schema.boolean().required().description("该频道/群组是否推送直播通知"),
|
|
313
|
+
liveGuardBuy: koishi_1.Schema.boolean().required().description("该频道/群组是否推送上舰消息"),
|
|
314
|
+
atAll: koishi_1.Schema.boolean().required().description("推送开播通知时是否艾特全体成员"),
|
|
315
|
+
})).required().description("需推送的频道/群组详细设置"),
|
|
316
|
+
platform: koishi_1.Schema.string().required().description("推送平台"),
|
|
317
317
|
})).description("订阅用户需要发送的平台和频道/群组信息(一个平台下可以推送多个频道/群组)"),
|
|
318
318
|
}))
|
|
319
319
|
.role("table")
|
|
@@ -338,7 +338,7 @@ exports.Config = koishi_1.Schema.object({
|
|
|
338
338
|
koishi_1.Schema.const("WS").description("WebSocket模式:连接到对应的直播间,可推送弹幕消息,开播下播响应最快,但对订阅数有限制"),
|
|
339
339
|
koishi_1.Schema.const("API")
|
|
340
340
|
.description("API模式:请求对应直播间API,无法获取弹幕消息,开播下播响应慢,理论可无限订阅")
|
|
341
|
-
.
|
|
341
|
+
.deprecated(),
|
|
342
342
|
])
|
|
343
343
|
.role("radio")
|
|
344
344
|
.description("直播检测模式")
|
|
@@ -356,10 +356,10 @@ exports.Config = koishi_1.Schema.object({
|
|
|
356
356
|
.default("-name开播啦,当前粉丝数为-follower -link")
|
|
357
357
|
.description("自定义开播提示语,-name代表UP昵称,-follower代表当前粉丝数,-link代表直播间链接(如果使用的是QQ官方机器人,请不要使用)。例如-name开播啦,会发送为xxxUP开播啦"),
|
|
358
358
|
customLive: koishi_1.Schema.string()
|
|
359
|
-
.default("-name正在直播,目前已播-time
|
|
359
|
+
.default("-name正在直播,目前已播-time。累计看过人数:-watched,-link")
|
|
360
360
|
.description("自定义直播中提示语,-name代表UP昵称,-time代表开播时长,-watched代表累计看过人数,-link代表直播间链接(如果使用的是QQ官方机器人,请不要使用)。例如-name正在直播,会发送为xxxUP正在直播xxx"),
|
|
361
361
|
customLiveEnd: koishi_1.Schema.string()
|
|
362
|
-
.default("-name下播啦,本次直播了-time
|
|
362
|
+
.default("-name下播啦,本次直播了-time。粉丝数变化-follower_change")
|
|
363
363
|
.description("自定义下播提示语,-name代表UP昵称,-follower_change代表本场直播粉丝数变,-time代表开播时长。例如-name下播啦,本次直播了-time,会发送为xxxUP下播啦,直播时长为xx小时xx分钟xx秒"),
|
|
364
364
|
followerDisplay: koishi_1.Schema.boolean()
|
|
365
365
|
.default(true)
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -197,6 +197,8 @@
|
|
|
197
197
|
- ver 3.0.0-alpha.15 修复:启动插件提示发送群组消息失败、直播推送时间显示为负数(不用再特别设置系统时区为UTC+8)
|
|
198
198
|
- ver 3.0.0-alpha.16 重大更新:订阅不再依赖数据库,从指令订阅全面迁移到配置订阅; 修复:直播时长有误; 优化:`bili show` 指令更改为 `bili list`
|
|
199
199
|
- ver 3.0.0-alpha.17 新增:更多的提示语变量,开播,当前粉丝数。正在直播,累计观看人数。下播,粉丝数变化。选项,新增的提示语变量是否展示到推送卡片中
|
|
200
|
+
- ver 3.0.0-alpha.18 移除:直播检测API模式已被废弃; 优化:更多提示语数据显示优化
|
|
201
|
+
- ver 3.0.0-alpha.19 修复:开播提示语粉丝数单位错误; 优化:订阅配置中所有配置项改为必填项
|
|
200
202
|
|
|
201
203
|
## 交流群
|
|
202
204
|
|
|
@@ -204,7 +206,9 @@
|
|
|
204
206
|
|
|
205
207
|
## 感谢
|
|
206
208
|
|
|
207
|
-
|
|
209
|
+
[koishijs](https://github.com/koishijs/koishi) 感谢官方提供的插件开发框架, 以及技术指导
|
|
210
|
+
[blive-message-listener](https://github.com/ddiu8081/blive-message-listener) 感谢 `ddiu8081` 提供简单方便的B站直播监听依赖
|
|
211
|
+
[bilibili-API-collect](https://github.com/SocialSisterYi/bilibili-API-collect) 感谢 `SocialSisterYi` 提供B站API参考
|
|
208
212
|
|
|
209
213
|
## License
|
|
210
214
|
|