~xenrox/10man-ts3

a2151dde1ba550ea0ed483f0517a765697b7fc8c — Thorben Günther 2 years ago b05cd9d
Implement cancel and start queue
1 files changed, 54 insertions(+), 0 deletions(-)

M app.ts
M app.ts => app.ts +54 -0
@@ 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;
        }
    }
}