From b05cd9def7db6a26d97e99626c8db57ff46bdf48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Mon, 8 Nov 2021 15:04:32 +0100 Subject: [PATCH] Improve error handling, send message to whole channel --- app.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app.ts b/app.ts index a9c90c5..50a5b7c 100644 --- a/app.ts +++ b/app.ts @@ -49,6 +49,16 @@ function message(clid: string, msg: string) { teamspeak.sendTextMessage(clid, 1, msg); } +function message_channel(msg: string) { + teamspeak.channelFind("10 Man").then((channel) => { + teamspeak.sendTextMessage(channel[0].cid, 2, msg); + }); +} + +function get_error(e: unknown): string { + return JSON.parse(JSON.stringify(e)).response.errors[0].message; +} + async function request(query: string, variables: Variables): Promise { const endpoint = process.env.ENDPOINT!; const graphQLClient = new GraphQLClient(endpoint, { @@ -73,7 +83,7 @@ async function elo(clid: string, teamspeakID: string) { const data = await request(query, variables); message(clid, "Elo: " + data.userByTS.elo); } catch (e) { - const error = JSON.parse(JSON.stringify(e)).response.errors[0].message; + const error = get_error(e); switch (error) { case "no result": message(clid, "You are not registered with this teamspeakID."); @@ -97,7 +107,7 @@ async function register(clid: string, teamspeakID: string, steamID: string) { const data = await request(mutation, variables); message(clid, "Registered successfully."); } catch (e) { - const error = JSON.parse(JSON.stringify(e)).response.errors[0].message; + const error = get_error(e); switch (error) { case "not unique": message( -- 2.44.0