fixin stuff i didn't catch on lapop

This commit is contained in:
Jill 2023-11-20 18:20:12 +03:00
parent 4ab739d681
commit 249390cf5d
Signed by: oat
GPG Key ID: 33489AA58A955108
4 changed files with 13 additions and 13 deletions

View File

@ -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<Session, 'id'>) {

View File

@ -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';

View File

@ -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<CustomItem>('customItems')
.where('guild', guild)
.where('guild', guild.id)
.count({count: '*'});
const counters = await db<Counter>('counters')
.where('guild', guild)
.where('guild', guild.id)
.count({count: '*'});
const recipes = await db<CustomCraftingRecipe>('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,
});
});

View File

@ -18,11 +18,11 @@
<body>
<div id="login" onclick="window.location = '/profile'">
{{#if signedIn}}
<div class="username">{{username}}</div>
<div class="username">{{user.global_name}}</div>
{{else}}
<div class="username logged-out">log in</div>
{{/if}}
<img class="avatar" src="{{avatar}}" width="128" height="128">
<img class="avatar" src="{{avatar user.id user.avatar}}" width="128" height="128">
</div>
<div id="main">
<img src="/assets/jillo.png" width="150" height="200">