summaryrefslogtreecommitdiff
path: root/classes/MessageFormattingRule.ts
blob: 7ec061d7ab6cd6c3b0de70ba1157b980f4d14d67 (plain)
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
import {MessageFormattingStyle} from "../enums/MessageFormattingStyle";

export class MessageFormattingRule {
    public start: number;
    public end: number;
    public length: number;
    public extract?: string;
    public styling: MessageFormattingStyle;

    constructor(data: any, text?: string) {
        this.styling = data.style;
        this.start = data.start;
        this.length = data.length;
        this.end = data.start + data.length;
        this.extract = text?.substring(this.start, this.end);
    }

    public static build(style: MessageFormattingStyle, start: number, length: number) {
        return new MessageFormattingRule({
            style,
            start,
            length
        });
    }

    public toCLIFormat(): string {
        return this.start + ":" + this.length + ":" + this.styling;
    }
}