jillo-bot/src/web.ts

28 lines
762 B
TypeScript

import express from 'express';
import * as log from './lib/log';
import { CustomItem, db } from './lib/db';
import { defaultItems } from './lib/rpg/items';
export async function startServer(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<CustomItem>[];
if (guildID) {
customItems = await db<CustomItem>('customItems')
.select('emoji', 'name', 'id', 'description')
.where('guild', guildID)
.limit(25);
} else {
customItems = [];
}
res.json([...defaultItems, ...customItems]);
});
app.listen(port, () => log.info(`web interface listening on ${port}`));
}