From beeb89b2c46ac609c4713a04704033922e446c2b Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Mon, 27 Nov 2023 19:21:22 +0300 Subject: [PATCH] update site a lil --- src/web/docs.ts | 31 ++++++++++++++++++++++++ src/web/web.ts | 44 +++++++++++++++++++++++++++++++---- static/style.css | 21 ++++++++++++++--- views/docs.handlebars | 9 +++++++ views/error.handlebars | 5 ++++ views/home.handlebars | 4 +++- views/layouts/main.handlebars | 2 +- 7 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 src/web/docs.ts create mode 100644 views/docs.handlebars create mode 100644 views/error.handlebars diff --git a/src/web/docs.ts b/src/web/docs.ts new file mode 100644 index 0000000..764d80f --- /dev/null +++ b/src/web/docs.ts @@ -0,0 +1,31 @@ +import { outdent } from 'outdent'; + +export const docs: Record = { + introduction: outdent` +

+ Jillo is yet another fun / utility / whatever Swiss knife Discord bot, except this time it's better than the other ones, I promise, please, + you'll have to trust me on this one, please +

+

+ The main big feature currently is the RPG, which lets you scavenge for items, craft them up into weapons and fight others, completely + customizable by server admins to their liking! It's a little rough, officially considered in beta, but you're free to toy around with it! +

+

+ Aside from that, you also have your classic self-assignable roles for colors and pronouns, silly text games somewhat like Jackbox but + playable all inside Discord, and a few little silly miscellaneous commands. If it seems a little overengineered - that's because it is, but also + because a good chunk of the bot's functionality is only relevant inside specific friend groups the bot was made for. +

+

+ That's about it! Here's a few links for your consideration: +

+ +
  • Invite the bot to your server
  • +
  • View the source code that's completely open for you to peek at
  • +
    + + `, +}; + +export function formatTitle(name: string) { + return name.replace('-', ' '); +} \ No newline at end of file diff --git a/src/web/web.ts b/src/web/web.ts index ba0ec0e..bf1dd26 100644 --- a/src/web/web.ts +++ b/src/web/web.ts @@ -1,4 +1,4 @@ -import express from 'express'; +import express, { NextFunction, Response } from 'express'; import { create } from 'express-handlebars'; import * as log from '../lib/log'; import { CustomItem, Counter, CustomCraftingRecipe, db } from '../lib/db'; @@ -6,6 +6,7 @@ import { defaultItems } from '../lib/rpg/items'; import { Client, CDN } from 'discord.js'; import { getToken, getSessionString, getSession, setSession, updateCookie } from './oauth2'; import { getUser, getGuilds } from './user'; +import { docs, formatTitle } from './docs'; async function getGuildInfo(bot: Client, id: string) { const guild = await bot.guilds.cache.get(id); @@ -68,13 +69,13 @@ export async function startServer(bot: Client, port: number) { }); }); - app.get('/', async (req, res) => { + app.get('/', async (req, res, next) => { const code = req.query.code as string; if (code) { try { const resp = await getToken(bot, code); - if (!resp) return res.status(400).send('Invalid code provided'); + if (!resp) return next({ http: 400, message: 'Invalid code provided' }); const sessionId = await getSessionString(decodeURIComponent(req.headers.cookie || '')); @@ -89,8 +90,7 @@ export async function startServer(bot: Client, port: number) { return res.redirect('/profile'); } catch (err) { - log.error(err); - return res.status(500); + return next(err); } } @@ -115,6 +115,7 @@ export async function startServer(bot: Client, port: number) { //res.sendFile('profile/index.html', { root: 'static/' }); res.render('profile', { + title: 'profile', user, guilds: await Promise.all( guilds.map(async guild => @@ -124,7 +125,40 @@ export async function startServer(bot: Client, port: number) { }); }); + app.get('/docs/:name', async (req, res, next) => { + const { name } = req.params; + if (!name) return res.redirect('/docs/introduction'); + + const content = docs[name]; + + if (!content) return next(); + + res.render('docs', { + name: formatTitle(name), + content: content, + sidebar: Object.keys(docs).map(d => ({ name: formatTitle(d), value: d })), + }); + }); + app.use(express.static('static/')); + // error handling + + app.use((req, res, next) => { + // since this is the last non-error-handling middleware, assume 404 + next({ http: '404', message: `${req.path} not found` }); + }); + + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars + app.use((err: Error | any, req: any, res: Response, next: NextFunction) => { + log.error(err); + const status = err.http ? err.http : 500; + res.status(status).render('error', { + path: req.path, + status, + message: err.message, + }); + }); + app.listen(port, () => log.info(`web interface listening on ${port}`)); } \ No newline at end of file diff --git a/static/style.css b/static/style.css index 4b140e3..2d3a926 100644 --- a/static/style.css +++ b/static/style.css @@ -59,19 +59,20 @@ a:hover { min-height: 100%; flex: 1 0 auto; } -#main img { +.jillo { display: block; height: 18rem; width: auto; + margin: 0 auto; animation: 1s popup; animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1); transition: transform 0.15s, opacity 0.1s; } -#main > img:active { +.jillo:active { transform: scale(0.97); opacity: 0.9; } -#main > :not(img) { +#main > :not(.jillo) { animation: 0.8s fadein; } #main h1 { @@ -350,4 +351,18 @@ pre { } .guild .info { color: var(--text-color-light); +} + +.status-code { + font-size: 10rem; + line-height: 1.0; + background: repeating-linear-gradient(98deg, rgba(190,190,190,1) 0%, rgba(190,190,190,1) 10%, rgba(207,207,207,1) 10%, rgba(207,207,207,1) 20%); + background-clip: text; + -webkit-text-fill-color: transparent; + -webkit-background-clip: text; + font-weight: bolder; + text-align: center; +} +.error { + text-align: center; } \ No newline at end of file diff --git a/views/docs.handlebars b/views/docs.handlebars new file mode 100644 index 0000000..d9e82a4 --- /dev/null +++ b/views/docs.handlebars @@ -0,0 +1,9 @@ +
    + +
    +

    {{ name }}

    + {{{ content }}} +
    +
    \ No newline at end of file diff --git a/views/error.handlebars b/views/error.handlebars new file mode 100644 index 0000000..bac601d --- /dev/null +++ b/views/error.handlebars @@ -0,0 +1,5 @@ +
    {{status}}
    + +
    + Error accessing {{ path }}: {{ message }} +
    - +

    jillo!

    invite · repo + · + what
    ··· diff --git a/views/layouts/main.handlebars b/views/layouts/main.handlebars index bc10d4a..bf7b0fe 100644 --- a/views/layouts/main.handlebars +++ b/views/layouts/main.handlebars @@ -3,7 +3,7 @@ - jillo + {{title}} - jillo