aboutsummaryrefslogtreecommitdiff
path: root/webAO/client/sender/sendOOC.ts
blob: a410b5f4e9fa4ccdee8679f6265683c04cdfdbe7 (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
30
31
32
33
import { client } from '../../client'
import { escapeChat } from '../../encoding';
import setCookie from '../../utils/setCookie';

/**
 * Sends an out-of-character chat message.
 * @param {string} message the message to send
 */
export const sendOOC = (message: string) => {
    setCookie(
        "OOC_name",
        (<HTMLInputElement>document.getElementById("OOC_name")).value
    );
    const oocName = `${escapeChat(
        (<HTMLInputElement>document.getElementById("OOC_name")).value
    )}`;
    const oocMessage = `${escapeChat(message)}`;

    const commands = {
        "/save_chatlog": client.saveChatlogHandle,
    };
    const commandsMap = new Map(Object.entries(commands));

    if (oocMessage && commandsMap.has(oocMessage.toLowerCase())) {
        try {
            commandsMap.get(oocMessage.toLowerCase())();
        } catch (e) {
            // Command Not Recognized
        }
    } else {
        client.sender.sendServer(`CT#${oocName}#${oocMessage}#%`);
    }
}