From bfa429590a1163e69b3e3581533f01abc43a0228 Mon Sep 17 00:00:00 2001 From: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> Date: Mon, 16 Oct 2023 23:15:47 -0700 Subject: [PATCH] Fix `/lc sync` subcommand (#46) * wip * Update api.ts --- api/api.ts | 7 ------ main.ts | 64 ++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/api/api.ts b/api/api.ts index c848a1e..33d8cf0 100644 --- a/api/api.ts +++ b/api/api.ts @@ -108,10 +108,3 @@ export function makeOnListen( function makeInviteURL(applicationID: string) { return `https://discord.com/api/oauth2/authorize?client_id=${applicationID}&scope=applications.commands`; } - -fetch( - "http://127.0.0.1:8080/webhook?season_id=01H8T4MM00BQHHK7VTTEJE1WAS&webhook_url=https://discord.com/api/webhooks/1128189891847667712/jUq5uK9dzM4V99fsj8Y6b8tBiZx_idMB5DAMKAPJQ4rTbEiqoy7ah2qUpORWyfaHGl4l", - { - method: "POST", - }, -).then((res) => res.json()).then(console.log).catch(console.error); diff --git a/main.ts b/main.ts index 28d879d..d96c2fa 100644 --- a/main.ts +++ b/main.ts @@ -24,29 +24,45 @@ async function main() { kv, lcClient, ); - const r = api.makeAPIRouter( - DISCORD_APPLICATION_ID, - DISCORD_PUBLIC_KEY, - DISCORD_CHANNEL_ID, - DISCORD_WEBHOOK_URL, - WEBHOOK_TOKEN, - lcClient, - leaderboardClient, - ); + try { + const r = api.makeAPIRouter( + DISCORD_APPLICATION_ID, + DISCORD_PUBLIC_KEY, + DISCORD_CHANNEL_ID, + DISCORD_WEBHOOK_URL, + WEBHOOK_TOKEN, + lcClient, + leaderboardClient, + ); - await Router.serve( - { - port: PORT, - onListen: api.makeOnListen( - PORT, - DISCORD_APPLICATION_ID, - DISCORD_TOKEN, - ), - }, - r, - ) - .finished - .finally(() => { - kv.close(); - }); + await Router.serve( + { + port: PORT, + onListen: api.makeOnListen( + PORT, + DISCORD_APPLICATION_ID, + DISCORD_TOKEN, + ), + }, + r, + ) + .finished + .finally(() => { + kv.close(); + }); + } catch (error) { + // TODO: Resolve this error. + // + // Task start deno run -A --unstable main.ts + // - Discord application information: https://discord.com/developers/applications/1130004756153253960/ + // - Interaction endpoint: http://127.0.0.1:8080/ + // - Invite LC-Dailies to your server: http://127.0.0.1:8080/invite + // - Latest season: http://127.0.0.1:8080/seasons/latest + // SyntaxError: Unexpected token 'O', "OK" is not valid JSON + // at parse () + // at packageData (ext:deno_fetch/22_body.js:369:14) + // at consumeBody (ext:deno_fetch/22_body.js:246:12) + // at eventLoopTick (ext:core/01_core.js:183:11) + console.log(error); + } }