From 249390cf5d4f1a14b0612e2b612e8846c3e25d87 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Mon, 20 Nov 2023 18:20:12 +0300 Subject: [PATCH] fixin stuff i didn't catch on lapop --- src/web/oauth2.ts | 5 +++-- src/web/user.ts | 2 +- src/web/web.ts | 15 +++++++-------- views/home.handlebars | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/web/oauth2.ts b/src/web/oauth2.ts index a5782de..45ebcc3 100644 --- a/src/web/oauth2.ts +++ b/src/web/oauth2.ts @@ -36,7 +36,7 @@ export function updateCookie(res: Response, sessionId: string) { export async function getToken(bot: Client, code: string) { try { - return await got.post(DISCORD_ENDPOINT + Routes.oauth2TokenExchange(), { + return await got.post(DISCORD_ENDPOINT + Routes.oauth2TokenExchange(), { form: { client_id: bot.config.clientId, client_secret: bot.config.clientSecret, @@ -46,7 +46,7 @@ export async function getToken(bot: Client, code: string) { } satisfies RESTPostOAuth2AccessTokenURLEncodedData // if you're looking to change this then you are blissfully unaware of the past // and have learnt 0 lessons - }).json() as RESTPostOAuth2AccessTokenResult + }).json() as RESTPostOAuth2AccessTokenResult; } catch(err) { log.error(err); return; @@ -97,6 +97,7 @@ export async function getSession(bot: Client, headers: IncomingHttpHeaders) { if (Date.now() < session.expiresAt) return session; const newSession = refreshToken(bot, session.id, session.refreshToken); + return newSession; } export async function setSession(sessionId: string, sessionData: Omit) { diff --git a/src/web/user.ts b/src/web/user.ts index ee6989b..9c286ac 100644 --- a/src/web/user.ts +++ b/src/web/user.ts @@ -1,4 +1,4 @@ -import { Session, db } from '../lib/db'; +import { Session } from '../lib/db'; import * as log from '../lib/log'; import got from 'got'; import { APIPartialGuild, APIUser, Routes } from 'discord.js'; diff --git a/src/web/web.ts b/src/web/web.ts index 99dcfab..ba0ec0e 100644 --- a/src/web/web.ts +++ b/src/web/web.ts @@ -1,7 +1,7 @@ import express from 'express'; import { create } from 'express-handlebars'; import * as log from '../lib/log'; -import { CustomItem, Counter, Session, CustomCraftingRecipe, db } from '../lib/db'; +import { CustomItem, Counter, CustomCraftingRecipe, db } from '../lib/db'; import { defaultItems } from '../lib/rpg/items'; import { Client, CDN } from 'discord.js'; import { getToken, getSessionString, getSession, setSession, updateCookie } from './oauth2'; @@ -12,22 +12,22 @@ async function getGuildInfo(bot: Client, id: string) { if (!guild) return; const items = await db('customItems') - .where('guild', guild) + .where('guild', guild.id) .count({count: '*'}); const counters = await db('counters') - .where('guild', guild) + .where('guild', guild.id) .count({count: '*'}); const recipes = await db('customCraftingRecipes') - .where('guild', guild) + .where('guild', guild.id) .count({count: '*'}); return { items: items[0].count as number, counters: counters[0].count as number, recipes: recipes[0].count as number, - } + }; } export async function startServer(bot: Client, port: number) { @@ -39,7 +39,7 @@ export async function startServer(bot: Client, port: number) { avatar: (id: string, hash: string) => (id && hash) ? cdn.avatar(id, hash, { size: 128 }) : '/assets/avatar.png', icon: (id: string, hash: string) => (id && hash) ? cdn.icon(id, hash, { size: 128, forceStatic: true }) : '/assets/avatar.png', } - }) + }); app.engine('handlebars', hbs.engine); app.set('view engine', 'handlebars'); @@ -99,8 +99,7 @@ export async function startServer(bot: Client, port: number) { res.render('home', { signedIn: session !== undefined, - username: user?.global_name, - avatar: user?.avatar ? cdn.avatar(user.id, user.avatar, { size: 128 }) : '/assets/avatar.png', + user: user, layout: false, }); }); diff --git a/views/home.handlebars b/views/home.handlebars index 7c53449..5b1e91c 100644 --- a/views/home.handlebars +++ b/views/home.handlebars @@ -18,11 +18,11 @@
{{#if signedIn}} -
{{username}}
+
{{user.global_name}}
{{else}}
log in
{{/if}} - +