mirror of
https://git.haroon.hackclub.app/haroon/osu-leaderboard.git
synced 2024-11-09 23:39:40 +00:00
Disable multiplayer room checking if access token isn't found
This commit is contained in:
parent
acfb0ae979
commit
b0905eca90
1 changed files with 9 additions and 4 deletions
13
index.ts
13
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<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.
|
||||
})();
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue