~xenrox/10man-ts3

76beea35c52f02f3080bce6f5585222d789a8d5a — Thorben Günther 2 years ago 1361e49
Refactor TeamSpeak.connect() -> TeamSpeak class

Now the program structure can be better (e.g. message function).
1 files changed, 29 insertions(+), 24 deletions(-)

M app.ts
M app.ts => app.ts +29 -24
@@ 4,7 4,7 @@ import dotenv from "dotenv";

dotenv.config();

TeamSpeak.connect({
const teamspeak = new TeamSpeak({
    host: process.env.HOST,
    protocol: QueryProtocol.RAW, //optional
    queryport: 10011, //optional


@@ 12,29 12,34 @@ TeamSpeak.connect({
    username: process.env.USERNAME,
    password: process.env.PASSWORD,
    nickname: "10Man",
})
    .then(async (teamspeak) => {
        const whoami = await teamspeak.whoami();
        const channel = await teamspeak.channelFind("10 Man");
        teamspeak.clientMove(whoami.clientId, channel[0].cid);

        teamspeak.on("textmessage", (ev) => {
            const argv = ev.msg.split(" ");
            switch (argv[0]) {
                case "!hello":
                    teamspeak.sendTextMessage(
                        ev.invoker.clid,
                        1,
                        "Hello " + ev.invoker.nickname
                    );
                    break;
            }
        });
    })
    .catch((e) => {
        console.log("Catched an error!");
        console.error(e);
    });
});

teamspeak.on("ready", async () => {
    const whoami = await teamspeak.whoami();
    const channel = await teamspeak.channelFind("10 Man");
    teamspeak.clientMove(whoami.clientId, channel[0].cid);
});

teamspeak.on("error", (e) => {
    console.log("Caught an error!");
    console.error(e);
});

teamspeak.on("textmessage", (ev) => {
    const argv = ev.msg.split(" ");
    const clid = ev.invoker.clid;
    const teamspeakID = ev.invoker.uniqueIdentifier;

    switch (argv[0]) {
        case "!hello":
            message(clid, "Hello " + ev.invoker.nickname);
            break;
    }
});

function message(clid: string, msg: string) {
    teamspeak.sendTextMessage(clid, 1, msg);
}

async function request(query: string): Promise<string> {
    const endpoint = process.env.ENDPOINT!;