blob: bdc193d9d8fdcf1437f7cfbe6d6adda5070cdaac (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import { ChatMessage } from "../../database.d";
import DefaultChatParser from "./default";
import YtDlpChatParser from "./yt-dlp";
export abstract class ChatReplayParser {
name: string = "";
constructor(chatData: string) {
if (this.constructor === ChatReplayParser)
throw new Error("Abstract classes can't be instantiated.");
}
canParse(): boolean {
return false;
}
parse(): ChatMessage[] {
return [];
}
}
export const parseChatReplay = (input: string) => {
console.log("[chat] parsing chat data");
const parser = [DefaultChatParser, YtDlpChatParser]
.map((Parser) => new Parser(input))
.find((parser) => parser.canParse());
if (!parser) throw new Error("No suitable chat parser found");
console.log("[chat] using", parser.name);
const parsed = parser.parse();
console.log("[chat] found", parsed.length, "messages");
console.log(parsed)
return parsed;
};
|