fixin stuff i didn't catch on lapop
This commit is contained in:
parent
4ab739d681
commit
249390cf5d
|
@ -36,7 +36,7 @@ export function updateCookie(res: Response, sessionId: string) {
|
||||||
|
|
||||||
export async function getToken(bot: Client, code: string) {
|
export async function getToken(bot: Client, code: string) {
|
||||||
try {
|
try {
|
||||||
return await got.post(DISCORD_ENDPOINT + Routes.oauth2TokenExchange(), {
|
return await got.post(DISCORD_ENDPOINT + Routes.oauth2TokenExchange(), {
|
||||||
form: {
|
form: {
|
||||||
client_id: bot.config.clientId,
|
client_id: bot.config.clientId,
|
||||||
client_secret: bot.config.clientSecret,
|
client_secret: bot.config.clientSecret,
|
||||||
|
@ -46,7 +46,7 @@ export async function getToken(bot: Client, code: string) {
|
||||||
} satisfies RESTPostOAuth2AccessTokenURLEncodedData
|
} satisfies RESTPostOAuth2AccessTokenURLEncodedData
|
||||||
// if you're looking to change this then you are blissfully unaware of the past
|
// if you're looking to change this then you are blissfully unaware of the past
|
||||||
// and have learnt 0 lessons
|
// and have learnt 0 lessons
|
||||||
}).json() as RESTPostOAuth2AccessTokenResult
|
}).json() as RESTPostOAuth2AccessTokenResult;
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
log.error(err);
|
log.error(err);
|
||||||
return;
|
return;
|
||||||
|
@ -97,6 +97,7 @@ export async function getSession(bot: Client, headers: IncomingHttpHeaders) {
|
||||||
if (Date.now() < session.expiresAt) return session;
|
if (Date.now() < session.expiresAt) return session;
|
||||||
|
|
||||||
const newSession = refreshToken(bot, session.id, session.refreshToken);
|
const newSession = refreshToken(bot, session.id, session.refreshToken);
|
||||||
|
return newSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setSession(sessionId: string, sessionData: Omit<Session, 'id'>) {
|
export async function setSession(sessionId: string, sessionData: Omit<Session, 'id'>) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Session, db } from '../lib/db';
|
import { Session } from '../lib/db';
|
||||||
import * as log from '../lib/log';
|
import * as log from '../lib/log';
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
import { APIPartialGuild, APIUser, Routes } from 'discord.js';
|
import { APIPartialGuild, APIUser, Routes } from 'discord.js';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import { create } from 'express-handlebars';
|
import { create } from 'express-handlebars';
|
||||||
import * as log from '../lib/log';
|
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 { defaultItems } from '../lib/rpg/items';
|
||||||
import { Client, CDN } from 'discord.js';
|
import { Client, CDN } from 'discord.js';
|
||||||
import { getToken, getSessionString, getSession, setSession, updateCookie } from './oauth2';
|
import { getToken, getSessionString, getSession, setSession, updateCookie } from './oauth2';
|
||||||
|
@ -12,22 +12,22 @@ async function getGuildInfo(bot: Client, id: string) {
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
const items = await db<CustomItem>('customItems')
|
const items = await db<CustomItem>('customItems')
|
||||||
.where('guild', guild)
|
.where('guild', guild.id)
|
||||||
.count({count: '*'});
|
.count({count: '*'});
|
||||||
|
|
||||||
const counters = await db<Counter>('counters')
|
const counters = await db<Counter>('counters')
|
||||||
.where('guild', guild)
|
.where('guild', guild.id)
|
||||||
.count({count: '*'});
|
.count({count: '*'});
|
||||||
|
|
||||||
const recipes = await db<CustomCraftingRecipe>('customCraftingRecipes')
|
const recipes = await db<CustomCraftingRecipe>('customCraftingRecipes')
|
||||||
.where('guild', guild)
|
.where('guild', guild.id)
|
||||||
.count({count: '*'});
|
.count({count: '*'});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
items: items[0].count as number,
|
items: items[0].count as number,
|
||||||
counters: counters[0].count as number,
|
counters: counters[0].count as number,
|
||||||
recipes: recipes[0].count as number,
|
recipes: recipes[0].count as number,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function startServer(bot: Client, port: 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',
|
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',
|
icon: (id: string, hash: string) => (id && hash) ? cdn.icon(id, hash, { size: 128, forceStatic: true }) : '/assets/avatar.png',
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
app.engine('handlebars', hbs.engine);
|
app.engine('handlebars', hbs.engine);
|
||||||
app.set('view engine', 'handlebars');
|
app.set('view engine', 'handlebars');
|
||||||
|
@ -99,8 +99,7 @@ export async function startServer(bot: Client, port: number) {
|
||||||
|
|
||||||
res.render('home', {
|
res.render('home', {
|
||||||
signedIn: session !== undefined,
|
signedIn: session !== undefined,
|
||||||
username: user?.global_name,
|
user: user,
|
||||||
avatar: user?.avatar ? cdn.avatar(user.id, user.avatar, { size: 128 }) : '/assets/avatar.png',
|
|
||||||
layout: false,
|
layout: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,11 +18,11 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="login" onclick="window.location = '/profile'">
|
<div id="login" onclick="window.location = '/profile'">
|
||||||
{{#if signedIn}}
|
{{#if signedIn}}
|
||||||
<div class="username">{{username}}</div>
|
<div class="username">{{user.global_name}}</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="username logged-out">log in</div>
|
<div class="username logged-out">log in</div>
|
||||||
{{/if}}
|
{{/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>
|
||||||
<div id="main">
|
<div id="main">
|
||||||
<img src="/assets/jillo.png" width="150" height="200">
|
<img src="/assets/jillo.png" width="150" height="200">
|
||||||
|
|
Loading…
Reference in New Issue