~xenrox/10man-ts3

b05cd9def7db6a26d97e99626c8db57ff46bdf48 — Thorben Günther 2 years ago 740a3cd
Improve error handling, send message to whole channel
1 files changed, 12 insertions(+), 2 deletions(-)

M app.ts
M app.ts => app.ts +12 -2
@@ 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<any> {
    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(