import express from 'express'; import * as log from './lib/log'; import { CustomItem, db } from './lib/db'; import { defaultItems } from './lib/rpg/items'; import { Client } from 'discord.js'; export async function startServer(bot: Client, port: number) { const app = express(); app.use(express.static('static/')); app.get('/api/items', async (req, res) => { const guildID = req.query.guild; let customItems : Partial[]; if (guildID) { customItems = await db('customItems') .select('emoji', 'name', 'id', 'description') .where('guild', guildID) .limit(25); } else { customItems = []; } res.json([...defaultItems, ...customItems]); }); app.get('/api/status', async (_, res) => { res.json({ guilds: bot.guilds.cache.size, uptime: bot.uptime }); }); app.listen(port, () => log.info(`web interface listening on ${port}`)); }