From a2151dde1ba550ea0ed483f0517a765697b7fc8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Mon, 8 Nov 2021 15:08:44 +0100 Subject: [PATCH] Implement cancel and start queue --- app.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/app.ts b/app.ts index 50a5b7c..8356461 100644 --- a/app.ts +++ b/app.ts @@ -42,6 +42,12 @@ teamspeak.on("textmessage", (ev) => { case "!register": register(clid, teamspeakID, argv[1]); break; + case "!play": + play(clid, teamspeakID); + break; + case "!cancel": + cancel(clid, teamspeakID); + break; } }); @@ -124,3 +130,51 @@ async function register(clid: string, teamspeakID: string, steamID: string) { } } } + +async function play(clid: string, teamspeakID: string) { + const mutation = gql` + mutation ($teamspeakID: String!) { + startQueue(teamspeakID: $teamspeakID) + } + `; + const variables = { teamspeakID: teamspeakID }; + + try { + const data = await request(mutation, variables); + message_channel(data.startQueue + " player(s) in queue."); + } catch (e) { + const error = get_error(e); + switch (error) { + case "already in queue": + message(clid, "Already in queue."); + break; + default: + console.error(error); + break; + } + } +} + +async function cancel(clid: string, teamspeakID: string) { + const mutation = gql` + mutation ($teamspeakID: String!) { + cancelQueue(teamspeakID: $teamspeakID) + } + `; + const variables = { teamspeakID: teamspeakID }; + + try { + const data = await request(mutation, variables); + message_channel(data.cancelQueue + " player(s) in queue."); + } catch (e) { + const error = get_error(e); + switch (error) { + case "user not in queue": + message(clid, "You are not in queue."); + break; + default: + console.error(error); + break; + } + } +} -- 2.44.0