aboutsummaryrefslogtreecommitdiffstats
path: root/modules/ChatReplay/parser/default.ts
blob: acf1aefcffd4048d6e8801b74f3779a24e95660c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { ChatReplayParser } from ".";
import { ChatMessage } from "../../database.d";

export default class DefaultChatParser implements ChatReplayParser {
  name: "DefaultChatParser";
  chatData: string = "";

  constructor(chatData: string) {
    this.chatData = chatData.trim();
  }

  canParse(): boolean {
    return this.chatData.startsWith("[") && this.chatData.endsWith("]");
  }

  parse(): ChatMessage[] {
    return (JSON.parse(this.chatData) as ChatMessage[]).sort(
      (a, b) => a.time_in_seconds - b.time_in_seconds
    );
  }
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage