floating-live 0.14.11 → 0.15.0-beta.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/LICENSE +5 -670
- package/{src/abstract → dist/core}/LiveRoom.d.ts +1 -1
- package/{src/abstract → dist/core}/LiveRoom.js +6 -6
- package/{src/abstract → dist/core}/Reglist.d.ts +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +18 -0
- package/dist/index.d.ts +6 -0
- package/{index.js → dist/index.js} +7 -7
- package/{src → dist}/module/ModAuth.d.ts +2 -2
- package/{src → dist}/module/ModAuth.js +1 -1
- package/{src → dist}/module/ModCommand.d.ts +2 -2
- package/{src → dist}/module/ModCommand.js +1 -1
- package/{src → dist}/module/ModMessage.d.ts +2 -2
- package/{src → dist}/module/ModMessage.js +1 -1
- package/{src → dist}/module/ModPlugin.d.ts +1 -1
- package/{src → dist}/module/ModRoom.d.ts +3 -3
- package/{src → dist}/module/ModRoom.js +1 -1
- package/{src → dist}/module/ModState.d.ts +2 -2
- package/{src → dist}/module/ModState.js +1 -1
- package/{src → dist}/types/message.d.ts +2 -2
- package/{src → dist}/types/plugin.d.ts +1 -1
- package/{src → dist}/types/room.d.ts +1 -1
- package/package.json +26 -5
- package/index.d.ts +0 -6
- package/plugin/acfun/acfunLive.d.ts +0 -74
- package/plugin/acfun/acfunLive.js +0 -279
- package/plugin/acfun/index.d.ts +0 -3
- package/plugin/acfun/index.js +0 -16
- package/plugin/bilibili/index.d.ts +0 -6
- package/plugin/bilibili/index.js +0 -45
- package/plugin/bilibili/parser.d.ts +0 -6
- package/plugin/bilibili/parser.js +0 -397
- package/plugin/bilibili/room.d.ts +0 -77
- package/plugin/bilibili/room.js +0 -261
- package/plugin/bilibili/types.d.ts +0 -424
- package/plugin/bilibili/types.js +0 -2
- package/plugin/bilibili/utils.d.ts +0 -17
- package/plugin/bilibili/utils.js +0 -137
- package/plugin/chatPrint/chatPrint.d.ts +0 -20
- package/plugin/chatPrint/chatPrint.js +0 -116
- package/plugin/chatPrint/index.d.ts +0 -7
- package/plugin/chatPrint/index.js +0 -10
- package/plugin/consoleEvent/index.d.ts +0 -6
- package/plugin/consoleEvent/index.js +0 -51
- package/plugin/msgSave/index.d.ts +0 -10
- package/plugin/msgSave/index.js +0 -81
- package/plugin/msgSave/msgSave.d.ts +0 -83
- package/plugin/msgSave/msgSave.js +0 -168
- package/test/type/bilibili_getInfoByRoom.d.ts +0 -492
- /package/{src/abstract → dist/core}/Reglist.js +0 -0
- /package/{src/enum.d.ts → dist/enums.d.ts} +0 -0
- /package/{src/enum.js → dist/enums.js} +0 -0
- /package/{src/index.d.ts → dist/live.d.ts} +0 -0
- /package/{src/index.js → dist/live.js} +0 -0
- /package/{src → dist}/module/ModPlugin.js +0 -0
- /package/{src → dist}/types/auth.d.ts +0 -0
- /package/{src → dist}/types/auth.js +0 -0
- /package/{src → dist}/types/index.d.ts +0 -0
- /package/{src → dist}/types/index.js +0 -0
- /package/{src → dist}/types/message.js +0 -0
- /package/{src → dist}/types/plugin.js +0 -0
- /package/{src → dist}/types/room.js +0 -0
- /package/{src → dist}/utils.d.ts +0 -0
- /package/{src → dist}/utils.js +0 -0
package/plugin/bilibili/utils.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.checkLoginQRcode = exports.printQRcode = exports.generateLoginQRcode = exports.getKey = exports.getBuvid = exports.getLoginUid = exports.parseCookieString = exports.getCookie = void 0;
|
|
7
|
-
const qrcode_1 = __importDefault(require("qrcode"));
|
|
8
|
-
const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.36";
|
|
9
|
-
/** API-当前登录用户信息 */
|
|
10
|
-
const UID_INIT_URL = "https://api.bilibili.com/x/web-interface/nav";
|
|
11
|
-
/** API-获取BUVID */
|
|
12
|
-
const BUVID_INIT_URL = "https://data.bilibili.com/v/";
|
|
13
|
-
const ROOM_INIT_URL = "https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom";
|
|
14
|
-
const DANMAKU_SERVER_CONF_URL = "https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo";
|
|
15
|
-
function getCookie(headers) {
|
|
16
|
-
const cookies = [];
|
|
17
|
-
headers.forEach((val, key) => {
|
|
18
|
-
if (key == "set-cookie") {
|
|
19
|
-
const [c] = val.split(";");
|
|
20
|
-
cookies.push(c);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
const cookie = cookies.join("; ");
|
|
24
|
-
return cookie;
|
|
25
|
-
}
|
|
26
|
-
exports.getCookie = getCookie;
|
|
27
|
-
function parseCookieString(str) {
|
|
28
|
-
const cookie = {};
|
|
29
|
-
str.split(";").forEach((item) => {
|
|
30
|
-
if (!item) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const arr = item.split("=");
|
|
34
|
-
const key = arr[0]?.trim();
|
|
35
|
-
const val = arr[1]?.trim();
|
|
36
|
-
cookie[key] = val;
|
|
37
|
-
});
|
|
38
|
-
return cookie;
|
|
39
|
-
}
|
|
40
|
-
exports.parseCookieString = parseCookieString;
|
|
41
|
-
/** 获取登录用户的uid */
|
|
42
|
-
async function getLoginUid(cookie = "") {
|
|
43
|
-
// cookie若缺少SESSDATA,一定属于未登录状态,uid返回0
|
|
44
|
-
if (!parseCookieString(cookie)["SESSDATA"])
|
|
45
|
-
return 0;
|
|
46
|
-
const res = await fetch(UID_INIT_URL, {
|
|
47
|
-
headers: {
|
|
48
|
-
Cookie: cookie,
|
|
49
|
-
"User-Agent": USER_AGENT,
|
|
50
|
-
},
|
|
51
|
-
}).then((res) => res.json());
|
|
52
|
-
if (res.code == 0) {
|
|
53
|
-
return res.data.mid;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
// code = -101 => 账号未登录
|
|
57
|
-
return 0;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.getLoginUid = getLoginUid;
|
|
61
|
-
/** 获取buvid */
|
|
62
|
-
async function getBuvid(cookie = "") {
|
|
63
|
-
const res = await fetch(BUVID_INIT_URL, {
|
|
64
|
-
headers: {
|
|
65
|
-
Cookie: cookie,
|
|
66
|
-
"User-Agent": USER_AGENT,
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
const resCookie = getCookie(res.headers);
|
|
70
|
-
if (!resCookie)
|
|
71
|
-
return;
|
|
72
|
-
return parseCookieString(resCookie)["buvid2"];
|
|
73
|
-
}
|
|
74
|
-
exports.getBuvid = getBuvid;
|
|
75
|
-
/** 获取直播间弹幕token */
|
|
76
|
-
async function getKey(roomId, cookie = "") {
|
|
77
|
-
const res = await fetch(`${DANMAKU_SERVER_CONF_URL}?id=${roomId}`, {
|
|
78
|
-
headers: {
|
|
79
|
-
Cookie: cookie,
|
|
80
|
-
"User-Agent": USER_AGENT,
|
|
81
|
-
},
|
|
82
|
-
}).then((res) => res.json());
|
|
83
|
-
return res.data.token;
|
|
84
|
-
}
|
|
85
|
-
exports.getKey = getKey;
|
|
86
|
-
/** 生成登录二维码 */
|
|
87
|
-
async function generateLoginQRcode() {
|
|
88
|
-
const res = await fetch("https://passport.bilibili.com/x/passport-login/web/qrcode/generate", {
|
|
89
|
-
headers: {
|
|
90
|
-
"User-Agent": USER_AGENT,
|
|
91
|
-
},
|
|
92
|
-
}).then((res) => res.json());
|
|
93
|
-
return {
|
|
94
|
-
url: res.data.url,
|
|
95
|
-
key: res.data.qrcode_key,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
exports.generateLoginQRcode = generateLoginQRcode;
|
|
99
|
-
/** 在终端打印登录二维码 */
|
|
100
|
-
function printQRcode(url) {
|
|
101
|
-
qrcode_1.default.toString(url, { type: "terminal" }, function (err, qr) {
|
|
102
|
-
console.log(qr);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
exports.printQRcode = printQRcode;
|
|
106
|
-
/** 检测登录二维码 */
|
|
107
|
-
async function checkLoginQRcode(key) {
|
|
108
|
-
const res = await fetch(`https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=${key}`, {
|
|
109
|
-
headers: {
|
|
110
|
-
"User-Agent": USER_AGENT,
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
const { code, message } = (await res.json()).data;
|
|
114
|
-
if (code == 86101) {
|
|
115
|
-
// 未扫码
|
|
116
|
-
return [1];
|
|
117
|
-
}
|
|
118
|
-
else if (code == 86090) {
|
|
119
|
-
// 等待确认
|
|
120
|
-
return [2];
|
|
121
|
-
}
|
|
122
|
-
else if (code == 0) {
|
|
123
|
-
const cookie = getCookie(res.headers);
|
|
124
|
-
console.log(cookie);
|
|
125
|
-
return [0, cookie];
|
|
126
|
-
}
|
|
127
|
-
else if (code == 86038) {
|
|
128
|
-
// 二维码失效
|
|
129
|
-
return [-1];
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
// 其他错误
|
|
133
|
-
console.log(`${code} ${message}`);
|
|
134
|
-
throw message;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
exports.checkLoginQRcode = checkLoginQRcode;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { FloatingLive } from "../..";
|
|
2
|
-
import { UserInfo } from "../..";
|
|
3
|
-
import { Message } from "../..";
|
|
4
|
-
export declare class chatPrint {
|
|
5
|
-
/** 主模块 */
|
|
6
|
-
main: FloatingLive;
|
|
7
|
-
hideType: Set<string>;
|
|
8
|
-
constructor(main: FloatingLive);
|
|
9
|
-
/** 获取用户信息 */
|
|
10
|
-
getUserInfo(message: {
|
|
11
|
-
platform: string;
|
|
12
|
-
info: {
|
|
13
|
-
user: UserInfo;
|
|
14
|
-
};
|
|
15
|
-
}): string;
|
|
16
|
-
/** 获取特权粉丝名称 */
|
|
17
|
-
getPriviliegeName(platform: string, level: number | boolean): string | number | boolean;
|
|
18
|
-
/** 记录在控制台上 */
|
|
19
|
-
log(message: Message.All): void;
|
|
20
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.chatPrint = void 0;
|
|
4
|
-
const __1 = require("../..");
|
|
5
|
-
class chatPrint {
|
|
6
|
-
constructor(main) {
|
|
7
|
-
this.main = main;
|
|
8
|
-
let hidden = [];
|
|
9
|
-
this.hideType = new Set(hidden); // 隐藏类型
|
|
10
|
-
this.main.on("live:message", (msg) => {
|
|
11
|
-
this.log(msg);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
/** 获取用户信息 */
|
|
15
|
-
getUserInfo(message) {
|
|
16
|
-
let user = message.info.user; // 用户信息
|
|
17
|
-
let name = `${"\x1b[33m"}${user.name}`; // 用户名
|
|
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
|
-
: ""; // 房管
|
|
27
|
-
return `${medal}${membership}${admin}${name}${"\x1b[0m"}`; //[粉丝牌(等级)] [特权][房管]用户名
|
|
28
|
-
}
|
|
29
|
-
/** 获取特权粉丝名称 */
|
|
30
|
-
getPriviliegeName(platform, level) {
|
|
31
|
-
switch (platform) {
|
|
32
|
-
case "bilibili":
|
|
33
|
-
return `${"\x1b[36m"}${["", "总督", "提督", "舰长"][Number(level)]}`;
|
|
34
|
-
default:
|
|
35
|
-
return level;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/** 记录在控制台上 */
|
|
39
|
-
log(message) {
|
|
40
|
-
if (this.hideType.has(message.type)) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
switch (message.type) {
|
|
44
|
-
case "chat": {
|
|
45
|
-
let user = this.getUserInfo(message);
|
|
46
|
-
let content = message.info.content;
|
|
47
|
-
console.log(`${user}: ${message.info.image ? "[img]" : ""}${content}`);
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
case "like": {
|
|
51
|
-
let user = this.getUserInfo(message);
|
|
52
|
-
console.log(`${user} 点赞了`);
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
case "gift": {
|
|
56
|
-
let user = this.getUserInfo(message);
|
|
57
|
-
let action = message.info.gift.action || "送出";
|
|
58
|
-
let name = message.info.gift.name;
|
|
59
|
-
let num = message.info.gift.num;
|
|
60
|
-
console.log(`${user}${"\x1b[0m"} ${action} ${"\x1b[40;33m"}${name} x${num}${"\x1b[0m"}`);
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
case "membership": {
|
|
64
|
-
let user = this.getUserInfo(message);
|
|
65
|
-
let name = message.info.name;
|
|
66
|
-
console.log(`${user}${"\x1b[1;31m"} 开通了主播的${"\x1b[33m"}${name}${"\x1b[0m"}`);
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
case "superchat": {
|
|
70
|
-
let user = this.getUserInfo(message);
|
|
71
|
-
let second = Math.round(message.info.duration / 1000);
|
|
72
|
-
console.log(`${"\x1b[1;36m"}SC(${second}s) ${user}${"\x1b[0m"}: ${message.info.content}`);
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
case "entry": {
|
|
76
|
-
let user = this.getUserInfo(message);
|
|
77
|
-
console.log(`${user} 进入直播间`);
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
case "follow": {
|
|
81
|
-
let user = this.getUserInfo(message);
|
|
82
|
-
console.log(`${user} 关注了主播`);
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
case "share": {
|
|
86
|
-
let user = this.getUserInfo(message);
|
|
87
|
-
console.log(`${user} 分享了直播间`);
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
case "block": {
|
|
91
|
-
let user = this.getUserInfo(message);
|
|
92
|
-
let operator = message.info.operator.type
|
|
93
|
-
? { [__1.UserType.admin]: "房管", [__1.UserType.anchor]: "主播" }[message.info.operator.type]
|
|
94
|
-
: "";
|
|
95
|
-
console.log(`${user} 已被${operator}禁言`);
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
case "live_start": {
|
|
99
|
-
let roomKey = `${message.platform}:${message.room}`;
|
|
100
|
-
console.log(`[+] 直播间${"\x1b[40;33m"} ${roomKey} ${"\x1b[0m"}已开播`);
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
case "live_cut": {
|
|
104
|
-
let roomKey = `${message.platform}:${message.room}`;
|
|
105
|
-
let msg = message.info.message;
|
|
106
|
-
console.log(`[!] ${"\x1b[1;31m"}直播间${"\x1b[40;33m"} ${roomKey} ${"\x1b[1;31m"}被管理员切断${"\x1b[0m"}: ${msg}`);
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
case "live_end": {
|
|
110
|
-
let roomKey = `${message.platform}:${message.room}`;
|
|
111
|
-
console.log(`[-] ${"\x1b[1;31m"}直播间${"\x1b[40;33m"} ${roomKey} ${"\x1b[1;31m"}已结束直播${"\x1b[0m"}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
exports.chatPrint = chatPrint;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const initEventConsole = (ctx) => {
|
|
3
|
-
ctx.on("room:connect", (key) => {
|
|
4
|
-
console.log(`[${key}]已连接到直播服务器`);
|
|
5
|
-
});
|
|
6
|
-
ctx.on("room:disconnect", (key) => {
|
|
7
|
-
console.log(`[${key}]与直播服务器的连接已断开`);
|
|
8
|
-
});
|
|
9
|
-
ctx.on("room:info", (key) => {
|
|
10
|
-
console.log(`[${key}]已获取到房间信息`);
|
|
11
|
-
});
|
|
12
|
-
ctx.on("room:update", (key) => {
|
|
13
|
-
console.log(`[${key}]直播间信息更新`);
|
|
14
|
-
});
|
|
15
|
-
ctx.on("room:open", (key) => {
|
|
16
|
-
console.log(`[${key}]房间已打开`);
|
|
17
|
-
});
|
|
18
|
-
ctx.on("room:close", (key) => {
|
|
19
|
-
console.log(`[${key}]房间已关闭`);
|
|
20
|
-
});
|
|
21
|
-
ctx.on("room:add", (key) => {
|
|
22
|
-
console.log(`[room]已添加房间: ${key}`);
|
|
23
|
-
});
|
|
24
|
-
ctx.on("room:remove", (key) => {
|
|
25
|
-
console.log(`[room]已移除房间: ${key}`);
|
|
26
|
-
});
|
|
27
|
-
ctx.on("room:exist", (key) => {
|
|
28
|
-
console.log(`[room]房间已存在: ${key}`);
|
|
29
|
-
});
|
|
30
|
-
ctx.on("room:unexist", (key) => {
|
|
31
|
-
console.log(`[room]房间不存在: ${key}`);
|
|
32
|
-
});
|
|
33
|
-
ctx.on("plugin:add", (name) => {
|
|
34
|
-
console.log(`[plugin]已添加插件: ${name}`);
|
|
35
|
-
});
|
|
36
|
-
ctx.on("plugin:remove", (name) => {
|
|
37
|
-
console.log(`[plugin]已移除插件: ${name}`);
|
|
38
|
-
});
|
|
39
|
-
ctx.on("plugin:unexist", (name) => {
|
|
40
|
-
console.log(`[plugin]插件不存在: ${name}`);
|
|
41
|
-
});
|
|
42
|
-
ctx.on("plugin:duplicate", (name) => {
|
|
43
|
-
console.log(`[plugin]插件名称重复: ${name}`);
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
module.exports = () => {
|
|
47
|
-
return {
|
|
48
|
-
name: "consoleEvent",
|
|
49
|
-
register: initEventConsole,
|
|
50
|
-
};
|
|
51
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { FloatingLive } from "../..";
|
|
2
|
-
import MsgSave from "./msgSave";
|
|
3
|
-
export declare const messageSave: () => {
|
|
4
|
-
name: string;
|
|
5
|
-
register: (ctx: FloatingLive) => MsgSave;
|
|
6
|
-
};
|
|
7
|
-
export declare const messageSaveRaw: () => {
|
|
8
|
-
name: string;
|
|
9
|
-
register: (ctx: FloatingLive) => MsgSave;
|
|
10
|
-
};
|
package/plugin/msgSave/index.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.messageSaveRaw = exports.messageSave = void 0;
|
|
7
|
-
const msgSave_1 = __importDefault(require("./msgSave"));
|
|
8
|
-
const messageSave = () => {
|
|
9
|
-
return {
|
|
10
|
-
name: "messageSave",
|
|
11
|
-
register: (ctx) => {
|
|
12
|
-
const saveMessage = new msgSave_1.default(ctx, {
|
|
13
|
-
filePath: `./save`,
|
|
14
|
-
sliceByStatus: true,
|
|
15
|
-
});
|
|
16
|
-
// 直播状态改变时,更新保存信息
|
|
17
|
-
ctx.on("room:status", (roomKey, status, { timestamp }) => {
|
|
18
|
-
const { platform, id } = ctx.room.get(roomKey).info;
|
|
19
|
-
saveMessage.setSaveInfo({
|
|
20
|
-
platform,
|
|
21
|
-
room: id,
|
|
22
|
-
status,
|
|
23
|
-
timestamp,
|
|
24
|
-
statusChanged: true,
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
// 打开直播间时,设置保存信息
|
|
28
|
-
ctx.on("room:open", (roomKey, roomInfo) => {
|
|
29
|
-
const { platform, id, status } = roomInfo;
|
|
30
|
-
saveMessage.setSaveInfo({
|
|
31
|
-
platform,
|
|
32
|
-
room: id,
|
|
33
|
-
status,
|
|
34
|
-
timestamp: Date.now(),
|
|
35
|
-
statusChanged: false,
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
// 关闭直播间时,移除保存信息
|
|
39
|
-
ctx.on("room:close", (roomKey, roomInfo) => {
|
|
40
|
-
saveMessage.removeSaveInfo(roomKey);
|
|
41
|
-
});
|
|
42
|
-
ctx.on("live:message", (msg) => {
|
|
43
|
-
saveMessage.write(msg, msg);
|
|
44
|
-
});
|
|
45
|
-
return saveMessage;
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
exports.messageSave = messageSave;
|
|
50
|
-
const messageSaveRaw = () => {
|
|
51
|
-
return {
|
|
52
|
-
name: "messageSaveRaw",
|
|
53
|
-
register: (ctx) => {
|
|
54
|
-
const saveRaw = new msgSave_1.default(ctx, {
|
|
55
|
-
filePath: `./save`,
|
|
56
|
-
suffix: `.raw`,
|
|
57
|
-
});
|
|
58
|
-
// 打开直播间时,设置保存信息
|
|
59
|
-
ctx.on("room:open", (roomKey, roomInfo) => {
|
|
60
|
-
const { platform, id, status } = roomInfo;
|
|
61
|
-
saveRaw.setSaveInfo({
|
|
62
|
-
platform,
|
|
63
|
-
room: id,
|
|
64
|
-
status,
|
|
65
|
-
timestamp: Date.now(),
|
|
66
|
-
statusChanged: false,
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
// 关闭直播间时,移除保存信息
|
|
70
|
-
ctx.on("room:close", (roomKey, roomInfo) => {
|
|
71
|
-
saveRaw.removeSaveInfo(roomKey);
|
|
72
|
-
});
|
|
73
|
-
ctx.on("live:raw", (msg, { platform, room }) => {
|
|
74
|
-
saveRaw.write(msg, { platform, room });
|
|
75
|
-
});
|
|
76
|
-
saveRaw.start();
|
|
77
|
-
return saveRaw;
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
exports.messageSaveRaw = messageSaveRaw;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { RoomStatus } from "../..";
|
|
2
|
-
import { FloatingLive } from "../..";
|
|
3
|
-
interface SaveInfoConfig {
|
|
4
|
-
platform: string;
|
|
5
|
-
room: string | number;
|
|
6
|
-
status: RoomStatus;
|
|
7
|
-
timestamp: number;
|
|
8
|
-
statusChanged: boolean;
|
|
9
|
-
}
|
|
10
|
-
declare class SaveInfo implements SaveInfoConfig {
|
|
11
|
-
/** 文件id */
|
|
12
|
-
get fileId(): string;
|
|
13
|
-
/** 平台 */
|
|
14
|
-
platform: string;
|
|
15
|
-
/** 房间号 */
|
|
16
|
-
room: string | number;
|
|
17
|
-
/** 时间戳 */
|
|
18
|
-
timestamp: number;
|
|
19
|
-
/** 状态 */
|
|
20
|
-
status: RoomStatus;
|
|
21
|
-
/** 文件是否存在 */
|
|
22
|
-
exist: boolean;
|
|
23
|
-
/** 记录状态是否已更改 */
|
|
24
|
-
statusChanged: boolean;
|
|
25
|
-
/** 按状态分文件 */
|
|
26
|
-
sliceByStatus: boolean;
|
|
27
|
-
/** 消息记录数 */
|
|
28
|
-
count: number;
|
|
29
|
-
/** 总消息记录数 */
|
|
30
|
-
totalCount: number;
|
|
31
|
-
/** 按消息记录数分文件 */
|
|
32
|
-
sliceByCount: number;
|
|
33
|
-
/** 分块id */
|
|
34
|
-
part: number;
|
|
35
|
-
constructor({ platform, room, status, timestamp, statusChanged, sliceByStatus, sliceByCount, }: SaveInfoConfig & {
|
|
36
|
-
sliceByStatus?: boolean;
|
|
37
|
-
sliceByCount?: number;
|
|
38
|
-
});
|
|
39
|
-
/** 分块 */
|
|
40
|
-
slice(): void;
|
|
41
|
-
}
|
|
42
|
-
declare class MsgSave {
|
|
43
|
-
/** 主模块 */
|
|
44
|
-
main: FloatingLive;
|
|
45
|
-
/** 文件路径 */
|
|
46
|
-
path: string;
|
|
47
|
-
/** 前缀 */
|
|
48
|
-
prefix: string;
|
|
49
|
-
/** 后缀 */
|
|
50
|
-
suffix: string;
|
|
51
|
-
/** 按状态分文件 */
|
|
52
|
-
sliceByStatus: boolean;
|
|
53
|
-
sliceByCount: number;
|
|
54
|
-
paused: boolean;
|
|
55
|
-
/** 列表 */
|
|
56
|
-
list: Map<string, SaveInfo>;
|
|
57
|
-
constructor(main: FloatingLive, { filePath, prefix, suffix, open, sliceByStatus, sliceByCount, }: {
|
|
58
|
-
filePath: string;
|
|
59
|
-
prefix?: string;
|
|
60
|
-
suffix?: string;
|
|
61
|
-
open?: boolean;
|
|
62
|
-
sliceByStatus?: boolean;
|
|
63
|
-
sliceByCount?: number;
|
|
64
|
-
});
|
|
65
|
-
write(message: any, { platform, room }: {
|
|
66
|
-
platform: string;
|
|
67
|
-
room: string | number;
|
|
68
|
-
}): void;
|
|
69
|
-
start(): void;
|
|
70
|
-
pause(): void;
|
|
71
|
-
/** 设置保存信息 */
|
|
72
|
-
setSaveInfo({ platform, room, status, timestamp, statusChanged, }: SaveInfoConfig): void;
|
|
73
|
-
/** 创建保存信息,用于记录信息可能不存在的情况 */
|
|
74
|
-
createSaveInfo({ platform, room, }: {
|
|
75
|
-
platform: string;
|
|
76
|
-
room: string | number;
|
|
77
|
-
}): SaveInfo;
|
|
78
|
-
/** 创建记录文件 */
|
|
79
|
-
createFile(roomKey: string): void;
|
|
80
|
-
/** 移除记录信息 */
|
|
81
|
-
removeSaveInfo(roomKey: string): void;
|
|
82
|
-
}
|
|
83
|
-
export default MsgSave;
|