From dc5adcabbe8e96432719215a54a4b9cd86997b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Thu, 11 Nov 2021 12:13:11 +0100 Subject: [PATCH] Move back clients if match is finished Don't crash if a user moved manually. --- app.ts | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/app.ts b/app.ts index e73dcef..b8e2ba0 100644 --- a/app.ts +++ b/app.ts @@ -271,6 +271,9 @@ async function finish_match(clid: string, teamspeakID: string, winner: string) { return; } + // move clients back to main channel + move_clients(true); + const mutation = gql` mutation ($winner: String!) { finishMatch(winner: $winner) @@ -314,7 +317,7 @@ async function start_match() { } } -async function move_clients() { +async function move_clients(back: boolean = false) { const query = gql` query { getTeams { @@ -330,27 +333,41 @@ async function move_clients() { try { const data = await request(query); - const team1 = data.getTeams.team1; - const channel1 = await teamspeak.channelFind("Team 1"); + const team2 = data.getTeams.team2; + var channel = await teamspeak.channelFind("10 Man"); + + if (!back) { + channel = 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); + teamspeak + .clientMove(client!.clid, channel[0].cid) + .catch(function (e) { + console.error(e); + }); }) .catch(function (e) { console.error(e); }); } - const team2 = data.getTeams.team2; - const channel2 = await teamspeak.channelFind("Team 2"); + if (!back) { + channel = 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); + teamspeak + .clientMove(client!.clid, channel[0].cid) + .catch(function (e) { + console.error(e); + }); }) .catch(function (e) { console.error(e); -- 2.44.0