~xenrox/10man-ts3

c6018880b51784016a4b21470945b081c7bf4cd6 — Thorben Günther 2 years ago dc5adca
Add !help command
1 files changed, 39 insertions(+), 0 deletions(-)

M app.ts
M app.ts => app.ts +39 -0
@@ 16,6 16,23 @@ const teamspeak = new TeamSpeak({
    nickname: "10Man",
});

let commands = new Map([
    ["!hello", "Say hello"],
    ["!elo", "Show your elo"],
    [
        "!register <STEAMID64>",
        "Register with your STEAMID64 (https://steamid.io/)",
    ],
    ["!play", "Go into the queue"],
    ["!cancel", "Cancel you queue"],
    ["!help", "Show this help text"],
]);

let admin_commands = new Map([
    ["!cancelMatch", "Cancel the ongoing match"],
    ["!finish <WINNER>", "Finish the ongoing match with WINNER (TEAM1, TEAM2)"],
]);

teamspeak.on("ready", async () => {
    const whoami = await teamspeak.whoami();
    const channel = await teamspeak.channelFind("10 Man");


@@ 54,6 71,9 @@ teamspeak.on("textmessage", (ev) => {
        case "!finish":
            finish_match(clid, teamspeakID, argv[1]);
            break;
        case "!help":
            help(clid, teamspeakID);
            break;
    }
});



@@ 382,3 402,22 @@ async function move_clients(back: boolean = false) {
        }
    }
}

async function help(clid: string, teamspeakID: string) {
    const admin = await is_admin(clid, teamspeakID);
    var msg = "";

    if (admin) {
        msg += "\nAdmin only commands:\n";
        for (let entry of admin_commands) {
            msg += entry[0] + ": " + entry[1] + "\n";
        }
    }

    msg += "\nUser commands:\n";
    for (let entry of commands) {
        msg += entry[0] + ": " + entry[1] + "\n";
    }

    teamspeak.sendTextMessage(clid, 1, msg);
}