From b0905eca909f828e39909edc4ef70179ae5eb547 Mon Sep 17 00:00:00 2001 From: DaInfLoop Date: Fri, 30 Aug 2024 16:28:07 +0100 Subject: [PATCH] Disable multiplayer room checking if access token isn't found --- index.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index a59f932..a728f59 100644 --- a/index.ts +++ b/index.ts @@ -5,6 +5,7 @@ import postgres from "postgres"; import "dotenv/config"; import bcrypt from "bcrypt"; import type { StaticSelectAction } from "@slack/bolt"; +import { inspect } from "node:util"; const sql = postgres({ host: '/var/run/postgresql', @@ -161,9 +162,11 @@ async function getTemporaryToken(): Promise { return data.access_token; } -async function getAccessToken(slack_id: string): Promise { +async function getAccessToken(slack_id: string): Promise { const user = await sql`SELECT * FROM links WHERE slack_id = ${slack_id}`; + if (!user.length) return null + const data = await fetch("https://osu.ppy.sh/oauth/token", { method: "POST", headers: { @@ -259,7 +262,9 @@ async function cacheStuff(): Promise { multiplayerRoundCache.length = 0; - const tohken = await getAccessToken("U06TBP41C3E"); + const tohken = await getAccessToken("U06TBP41C3E") as string; + + if (!tohken) return; const rooms = await fetch(`https://osu.ppy.sh/api/v2/rooms?category=realtime`, { headers: { @@ -816,7 +821,7 @@ app.command('/osu-eval', async (ctx) => { if (ctx.context.userId != 'U06TBP41C3E') return; - const resp = require('util').inspect(await eval(ctx.body.text), undefined, 1) + const resp = inspect(await eval(ctx.body.text), undefined, 1) ctx.respond({ text: resp, @@ -1093,4 +1098,4 @@ receiver.router.get('*', (req, res) => { cacheStuff(); setTimeout(cacheStuff, 60 * 1000) // Cache every minute. Ratelimit is 1200 req/m anyways. - })(); \ No newline at end of file + })();