floating-live 0.12.0 → 0.12.1
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/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/plugin/acfun/acfunLive.d.ts +1 -1
- package/plugin/acfun/acfunLive.js +4 -4
- package/plugin/bilibili/bilibiliLive.js +34 -20
- package/plugin/chatPrint/chatPrint.js +15 -5
- package/src/enum.d.ts +4 -2
- package/src/enum.js +9 -7
- package/src/types/message/AttributeInfo.d.ts +3 -3
- package/src/types/message/MessageData.d.ts +3 -2
- package/src/utils.d.ts +2 -0
- package/src/{tool.js → utils.js} +4 -4
- package/src/tool.d.ts +0 -2
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -21,4 +21,4 @@ __exportStar(require("./src/types"), exports);
|
|
|
21
21
|
__exportStar(require("./src/enum"), exports);
|
|
22
22
|
__exportStar(require("./src/lib/LiveRoom"), exports);
|
|
23
23
|
__exportStar(require("./src/lib/Reglist"), exports);
|
|
24
|
-
__exportStar(require("./src/
|
|
24
|
+
__exportStar(require("./src/utils"), exports);
|
package/package.json
CHANGED
|
@@ -162,19 +162,19 @@ class acfunLive extends __1.LiveRoom {
|
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
getUser(user) {
|
|
165
|
-
let identity =
|
|
165
|
+
let identity = 0;
|
|
166
166
|
if (user.userIdentity?.managerType == 1) {
|
|
167
|
-
identity = __2.
|
|
167
|
+
identity = __2.UserType.admin;
|
|
168
168
|
}
|
|
169
169
|
else if (parseInt(user.userId) == this.anchor.id) {
|
|
170
|
-
identity = __2.
|
|
170
|
+
identity = __2.UserType.anchor;
|
|
171
171
|
}
|
|
172
172
|
return {
|
|
173
173
|
name: user.nickname,
|
|
174
174
|
id: parseInt(user.userId),
|
|
175
175
|
medal: this.getMedal(user.badge),
|
|
176
176
|
avatar: user.avatar[0].url,
|
|
177
|
-
|
|
177
|
+
type: identity,
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
180
|
/** 文本信息(Comment) */
|
|
@@ -170,7 +170,7 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
170
170
|
membership: info[3][10] || 0,
|
|
171
171
|
}
|
|
172
172
|
: null;
|
|
173
|
-
let identity =
|
|
173
|
+
let identity = 0;
|
|
174
174
|
let emoticon = undefined;
|
|
175
175
|
if (extra.emots) {
|
|
176
176
|
emoticon = {};
|
|
@@ -184,10 +184,10 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
if (info[2][2]) {
|
|
187
|
-
identity = __1.
|
|
187
|
+
identity = __1.UserType.admin;
|
|
188
188
|
}
|
|
189
189
|
else if (uid == this.anchor.id) {
|
|
190
|
-
identity = __1.
|
|
190
|
+
identity = __1.UserType.anchor;
|
|
191
191
|
}
|
|
192
192
|
let danmaku = {
|
|
193
193
|
platform: "bilibili",
|
|
@@ -215,10 +215,11 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
215
215
|
id: uid,
|
|
216
216
|
medal: medal,
|
|
217
217
|
membership: guard_level,
|
|
218
|
-
|
|
218
|
+
type: identity,
|
|
219
219
|
},
|
|
220
220
|
},
|
|
221
221
|
};
|
|
222
|
+
danmaku.id ?? (danmaku.id = (0, __1.generateId)(danmaku));
|
|
222
223
|
this.emitMsg(danmaku);
|
|
223
224
|
}
|
|
224
225
|
/** 获取互动消息 */
|
|
@@ -243,7 +244,7 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
243
244
|
room: this.id,
|
|
244
245
|
type: type,
|
|
245
246
|
id: msg_id,
|
|
246
|
-
timestamp: send_time,
|
|
247
|
+
timestamp: send_time || Math.floor(data.trigger_time / 1000000),
|
|
247
248
|
info: {
|
|
248
249
|
user: {
|
|
249
250
|
name: data.uname,
|
|
@@ -259,6 +260,7 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
259
260
|
},
|
|
260
261
|
},
|
|
261
262
|
};
|
|
263
|
+
interact.id ?? (interact.id = (0, __1.generateId)(interact));
|
|
262
264
|
this.emitMsg(interact);
|
|
263
265
|
}
|
|
264
266
|
/** 获取礼物消息 */
|
|
@@ -268,8 +270,8 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
268
270
|
platform: "bilibili",
|
|
269
271
|
room: this.id,
|
|
270
272
|
type: "gift",
|
|
271
|
-
id: msg_id,
|
|
272
|
-
timestamp: send_time,
|
|
273
|
+
id: msg_id || data.combo_id,
|
|
274
|
+
timestamp: send_time || data.timestamp * 1000,
|
|
273
275
|
info: {
|
|
274
276
|
user: {
|
|
275
277
|
name: data.uname,
|
|
@@ -296,6 +298,7 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
296
298
|
},
|
|
297
299
|
},
|
|
298
300
|
};
|
|
301
|
+
gift.id ?? (gift.id = (0, __1.generateId)(gift));
|
|
299
302
|
this.emitMsg(gift);
|
|
300
303
|
}
|
|
301
304
|
/** 获取舰长开通消息 */
|
|
@@ -306,7 +309,7 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
306
309
|
room: this.id,
|
|
307
310
|
type: "membership",
|
|
308
311
|
id: msg_id,
|
|
309
|
-
timestamp: send_time,
|
|
312
|
+
timestamp: send_time || data.start_time * 1000,
|
|
310
313
|
info: {
|
|
311
314
|
user: {
|
|
312
315
|
name: data.username,
|
|
@@ -325,6 +328,7 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
325
328
|
duration: data.num * 30,
|
|
326
329
|
},
|
|
327
330
|
};
|
|
331
|
+
gift.id ?? (gift.id = (0, __1.generateId)(gift));
|
|
328
332
|
this.emitMsg(gift);
|
|
329
333
|
}
|
|
330
334
|
/** 获取醒目留言消息 */
|
|
@@ -335,7 +339,7 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
335
339
|
room: this.id,
|
|
336
340
|
type: "superchat",
|
|
337
341
|
id: msg_id,
|
|
338
|
-
timestamp: send_time,
|
|
342
|
+
timestamp: send_time || data.ts * 1000,
|
|
339
343
|
info: {
|
|
340
344
|
id: data.id,
|
|
341
345
|
user: {
|
|
@@ -364,6 +368,7 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
364
368
|
},
|
|
365
369
|
},
|
|
366
370
|
};
|
|
371
|
+
sc.id ?? (sc.id = (0, __1.generateId)(sc));
|
|
367
372
|
this.emitMsg(sc);
|
|
368
373
|
}
|
|
369
374
|
/** 观看数变化 */
|
|
@@ -374,11 +379,12 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
374
379
|
room: this.id,
|
|
375
380
|
type: "live_stats",
|
|
376
381
|
id: msg_id,
|
|
377
|
-
timestamp: send_time,
|
|
382
|
+
timestamp: send_time || getDateTimestamp(),
|
|
378
383
|
info: {
|
|
379
384
|
watch: data.num,
|
|
380
385
|
},
|
|
381
386
|
};
|
|
387
|
+
stats.id ?? (stats.id = (0, __1.generateId)(stats));
|
|
382
388
|
this.emitMsg(stats);
|
|
383
389
|
}
|
|
384
390
|
/** 点赞数变化 */
|
|
@@ -389,11 +395,12 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
389
395
|
room: this.id,
|
|
390
396
|
type: "live_stats",
|
|
391
397
|
id: msg_id,
|
|
392
|
-
timestamp: send_time,
|
|
398
|
+
timestamp: send_time || getDateTimestamp(),
|
|
393
399
|
info: {
|
|
394
400
|
like: data.click_count,
|
|
395
401
|
},
|
|
396
402
|
};
|
|
403
|
+
stats.id ?? (stats.id = (0, __1.generateId)(stats));
|
|
397
404
|
this.emitMsg(stats);
|
|
398
405
|
}
|
|
399
406
|
msg_ONLINE_RANK_COUNT(msg) {
|
|
@@ -403,12 +410,14 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
403
410
|
room: this.id,
|
|
404
411
|
type: "live_stats",
|
|
405
412
|
id: msg_id,
|
|
406
|
-
timestamp: send_time,
|
|
413
|
+
timestamp: send_time || getDateTimestamp(),
|
|
407
414
|
info: {
|
|
408
|
-
online: data.
|
|
415
|
+
online: data.online_count,
|
|
409
416
|
},
|
|
410
417
|
};
|
|
411
|
-
|
|
418
|
+
stats.id ?? (stats.id = (0, __1.generateId)(stats));
|
|
419
|
+
if (data.online_count != null)
|
|
420
|
+
this.emitMsg(stats);
|
|
412
421
|
}
|
|
413
422
|
msg_ROOM_BLOCK_MSG(msg) {
|
|
414
423
|
// 禁言
|
|
@@ -418,17 +427,18 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
418
427
|
room: this.id,
|
|
419
428
|
type: "block",
|
|
420
429
|
id: msg_id,
|
|
421
|
-
timestamp: send_time,
|
|
430
|
+
timestamp: send_time || getDateTimestamp(),
|
|
422
431
|
info: {
|
|
423
432
|
user: {
|
|
424
433
|
id: data.uid,
|
|
425
434
|
name: data.uname,
|
|
426
435
|
},
|
|
427
436
|
operator: {
|
|
428
|
-
|
|
437
|
+
type: data.operator == 2 ? __1.UserType.anchor : __1.UserType.admin,
|
|
429
438
|
},
|
|
430
439
|
},
|
|
431
440
|
};
|
|
441
|
+
block.id ?? (block.id = (0, __1.generateId)(block));
|
|
432
442
|
this.emitMsg(block);
|
|
433
443
|
}
|
|
434
444
|
msg_LIVE(msg) {
|
|
@@ -440,11 +450,12 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
440
450
|
room: this.id,
|
|
441
451
|
type: "live_start",
|
|
442
452
|
id: msg_id,
|
|
443
|
-
timestamp: send_time,
|
|
453
|
+
timestamp: send_time || msg.live_time * 1000,
|
|
444
454
|
info: {
|
|
445
455
|
id: msg.live_key.toString(),
|
|
446
456
|
},
|
|
447
457
|
};
|
|
458
|
+
live.id ?? (live.id = (0, __1.generateId)(live));
|
|
448
459
|
this.emitMsg(live);
|
|
449
460
|
}
|
|
450
461
|
}
|
|
@@ -456,11 +467,12 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
456
467
|
room: this.id,
|
|
457
468
|
type: "live_cut",
|
|
458
469
|
id: msg_id,
|
|
459
|
-
timestamp: send_time,
|
|
470
|
+
timestamp: send_time || getDateTimestamp(),
|
|
460
471
|
info: {
|
|
461
472
|
message: msg.msg,
|
|
462
473
|
},
|
|
463
474
|
};
|
|
475
|
+
cut.id ?? (cut.id = (0, __1.generateId)(cut));
|
|
464
476
|
this.emitMsg(cut);
|
|
465
477
|
}
|
|
466
478
|
msg_PREPARING(msg) {
|
|
@@ -470,11 +482,12 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
470
482
|
room: this.id,
|
|
471
483
|
type: "live_end",
|
|
472
484
|
id: msg_id,
|
|
473
|
-
timestamp: send_time,
|
|
485
|
+
timestamp: send_time || getDateTimestamp(),
|
|
474
486
|
info: {
|
|
475
487
|
status: msg.round ? __1.RoomStatus.round : __1.RoomStatus.off,
|
|
476
488
|
},
|
|
477
489
|
};
|
|
490
|
+
off.id ?? (off.id = (0, __1.generateId)(off));
|
|
478
491
|
this.emitMsg(off);
|
|
479
492
|
}
|
|
480
493
|
msg_ROOM_CHANGE(msg) {
|
|
@@ -484,12 +497,13 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
484
497
|
room: this.id,
|
|
485
498
|
type: "live_detail",
|
|
486
499
|
id: msg_id,
|
|
487
|
-
timestamp: send_time,
|
|
500
|
+
timestamp: send_time || getDateTimestamp(),
|
|
488
501
|
info: {
|
|
489
502
|
title: data.title,
|
|
490
503
|
area: [data.parent_area_name, data.area_name],
|
|
491
504
|
},
|
|
492
505
|
};
|
|
506
|
+
change.id ?? (change.id = (0, __1.generateId)(change));
|
|
493
507
|
this.emitMsg(change);
|
|
494
508
|
}
|
|
495
509
|
}
|
|
@@ -7,15 +7,23 @@ class chatPrint {
|
|
|
7
7
|
this.main = main;
|
|
8
8
|
let hidden = [];
|
|
9
9
|
this.hideType = new Set(hidden); // 隐藏类型
|
|
10
|
-
this.main.on("live_message", (msg) => {
|
|
10
|
+
this.main.on("live_message", (msg) => {
|
|
11
|
+
this.log(msg);
|
|
12
|
+
});
|
|
11
13
|
}
|
|
12
14
|
/** 获取用户信息 */
|
|
13
15
|
getUserInfo(message) {
|
|
14
16
|
let user = message.info.user; // 用户信息
|
|
15
17
|
let name = `${"\x1b[33m"}${user.name}`; // 用户名
|
|
16
|
-
let medal = user.medal
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
let medal = user.medal
|
|
19
|
+
? `${"\x1b[32m"}[${user.medal.name}(${user.medal.level})] `
|
|
20
|
+
: ""; // 粉丝牌
|
|
21
|
+
let membership = user.membership
|
|
22
|
+
? `${"\x1b[36m"}[${this.getPriviliegeName(message.platform, user.membership)}]`
|
|
23
|
+
: ""; // 特权粉丝
|
|
24
|
+
let admin = user.type
|
|
25
|
+
? `${"\x1b[95m"}[${{ [__1.UserType.admin]: "房管", [__1.UserType.anchor]: "主播" }[user.type]}]`
|
|
26
|
+
: ""; // 房管
|
|
19
27
|
return `${medal}${membership}${admin}${name}${"\x1b[0m"}`; //[粉丝牌(等级)] [特权][房管]用户名
|
|
20
28
|
}
|
|
21
29
|
/** 获取特权粉丝名称 */
|
|
@@ -81,7 +89,9 @@ class chatPrint {
|
|
|
81
89
|
}
|
|
82
90
|
case "block": {
|
|
83
91
|
let user = this.getUserInfo(message);
|
|
84
|
-
let operator = message.info.operator.
|
|
92
|
+
let operator = message.info.operator.type
|
|
93
|
+
? { [__1.UserType.admin]: "房管", [__1.UserType.anchor]: "主播" }[message.info.operator.type]
|
|
94
|
+
: "管理员";
|
|
85
95
|
console.log(`${user} 已被${operator}禁言`);
|
|
86
96
|
break;
|
|
87
97
|
}
|
package/src/enum.d.ts
CHANGED
package/src/enum.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.UserType = exports.DanmakuMode = exports.ImageSize = exports.RoomStatus = void 0;
|
|
4
4
|
/** 直播间状态 */
|
|
5
5
|
var RoomStatus;
|
|
6
6
|
(function (RoomStatus) {
|
|
@@ -31,11 +31,13 @@ var DanmakuMode;
|
|
|
31
31
|
DanmakuMode[DanmakuMode["top"] = 5] = "top";
|
|
32
32
|
DanmakuMode[DanmakuMode["right"] = 6] = "right";
|
|
33
33
|
})(DanmakuMode = exports.DanmakuMode || (exports.DanmakuMode = {}));
|
|
34
|
-
/**
|
|
35
|
-
var
|
|
36
|
-
(function (
|
|
34
|
+
/** 用户类型 */
|
|
35
|
+
var UserType;
|
|
36
|
+
(function (UserType) {
|
|
37
|
+
/** 普通观众 */
|
|
38
|
+
UserType[UserType["normal"] = 0] = "normal";
|
|
37
39
|
/** 房管 */
|
|
38
|
-
|
|
40
|
+
UserType[UserType["admin"] = 1] = "admin";
|
|
39
41
|
/** 主播 */
|
|
40
|
-
|
|
41
|
-
})(
|
|
42
|
+
UserType[UserType["anchor"] = 2] = "anchor";
|
|
43
|
+
})(UserType = exports.UserType || (exports.UserType = {}));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageSize,
|
|
1
|
+
import { ImageSize, UserType } from "../../enum";
|
|
2
2
|
/** 用户信息 */
|
|
3
3
|
export interface UserInfo {
|
|
4
4
|
/** 用户名 */
|
|
@@ -9,8 +9,8 @@ export interface UserInfo {
|
|
|
9
9
|
avatar?: string;
|
|
10
10
|
/** 粉丝勋章 */
|
|
11
11
|
medal?: MedalInfo | null;
|
|
12
|
-
/**
|
|
13
|
-
|
|
12
|
+
/** 用户类型 */
|
|
13
|
+
type?: UserType | null;
|
|
14
14
|
/** 粉丝vip等级 */
|
|
15
15
|
membership?: boolean | number;
|
|
16
16
|
/** vip等级 */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { UserType } from "./../../enum";
|
|
1
2
|
import { RoomInfo } from "./../../lib/LiveRoom";
|
|
2
|
-
import { DanmakuMode, RoomStatus
|
|
3
|
+
import { DanmakuMode, RoomStatus } from "../../enum";
|
|
3
4
|
import { RoomDetail, RoomStatsInfo } from "../../lib/LiveRoom";
|
|
4
5
|
import { UserInfo, GiftInfo, ImageInfo } from "./AttributeInfo";
|
|
5
6
|
declare type MessageBase = {
|
|
@@ -115,7 +116,7 @@ export interface MessageBlock extends MessageBase {
|
|
|
115
116
|
user: UserInfo;
|
|
116
117
|
/** 操作者 */
|
|
117
118
|
operator: UserInfo | {
|
|
118
|
-
|
|
119
|
+
type: null | UserType;
|
|
119
120
|
};
|
|
120
121
|
};
|
|
121
122
|
}
|
package/src/utils.d.ts
ADDED
package/src/{tool.js → utils.js}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
function
|
|
3
|
+
exports.generateId = void 0;
|
|
4
|
+
function generateId(msg) {
|
|
5
5
|
switch (msg.type) {
|
|
6
6
|
case "gift":
|
|
7
|
-
return `gift:${msg.info.
|
|
7
|
+
return `gift:${msg.info.user.id}-${msg.timestamp}`;
|
|
8
8
|
case "superchat":
|
|
9
9
|
return `superchat:${msg.info.id}`;
|
|
10
10
|
case "membership":
|
|
@@ -18,4 +18,4 @@ function generateKey(msg) {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
exports.
|
|
21
|
+
exports.generateId = generateId;
|
package/src/tool.d.ts
DELETED