aboutsummaryrefslogtreecommitdiff
path: root/webAO/client/sender/sendOOC.ts
blob: 43c3773bfe1c49d59b3c592fa9219de4a8112318 (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";
import { saveChatlogHandle } from "../../client/saveChatLogHandle";
/**
 * 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": 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}#%`);
  }
};