~xenrox/10man-ts3

ef4ca9be4003a0a5bd5bf2c29afb2f47330705b4 — Thorben Günther 2 years ago ef3316a
Add function to move clients to correct channels
1 files changed, 52 insertions(+), 0 deletions(-)

M app.ts
M app.ts => app.ts +52 -0
@@ 313,3 313,55 @@ async function start_match() {
        }
    }
}

async function move_clients() {
    const query = gql`
        query {
            getTeams {
                team1 {
                    teamspeakID
                }
                team2 {
                    teamspeakID
                }
            }
        }
    `;

    try {
        const data = await request(query);

        const team1 = data.getTeams.team1;
        const channel1 = await teamspeak.channelFind("Team 1");
        for (let i of team1) {
            const client = await teamspeak
                .getClientByUid(i.teamspeakID)
                .then((client) => {
                    teamspeak.clientMove(client!.clid, channel1[0].cid);
                })
                .catch(function (e) {
                    console.error(e);
                });
        }

        const team2 = data.getTeams.team2;
        const channel2 = await teamspeak.channelFind("Team 2");
        for (let i of team2) {
            const client = await teamspeak
                .getClientByUid(i.teamspeakID)
                .then((client) => {
                    teamspeak.clientMove(client!.clid, channel2[0].cid);
                })
                .catch(function (e) {
                    console.error(e);
                });
        }
    } catch (e) {
        const error = get_error(e);
        switch (error) {
            default:
                console.error(error);
                break;
        }
    }
}