Disable multiplayer room checking if access token isn't found

This commit is contained in:
DaInfLoop 2024-08-30 16:28:07 +01:00
parent acfb0ae979
commit b0905eca90
No known key found for this signature in database
GPG key ID: 8B96C44DDF5756E4

View file

@ -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<string> {
return data.access_token;
}
async function getAccessToken(slack_id: string): Promise<string> {
async function getAccessToken(slack_id: string): Promise<string|null> {
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<void> {
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.
})();
})();