summaryrefslogtreecommitdiff
path: root/src/server.ts
blob: b216ff4655cdbfde94157b6762aa744e803860d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import express from 'express';
import bodyParser from 'body-parser';

class WebSocket {
    constructor(port, client) {
        this.client = client;

        this.app = express()
        this.app.use(bodyParser.urlencoded({ extended: false }))
        this.app.use(bodyParser.json())

        this.registerRoots()

        this.server = this.app.listen(port, () => {
            console.log('\x1b[0m' + 'Listening on port: ' + '\x1b[36m' + this.server.address().port)
        })
    }
    // http://localhost:port?token=123456
    registerRoots() {
        this.app.get('/', (req, res) => {
            res.redirect('https://kyzer.co/discord/bots/uwufier/')
        })
        this.app.get('/api/v1/commands/', async (req, res) => {
            res.json({ guilds: await this.client.registry.commands.size })
        });
        this.app.get('/api/v1/commands/groups/', async (req, res) => {
            res.json({ guilds: await this.client.registry.groups.size })
        });
        this.app.get('/api/v1/servers/', async (req, res) => {
            res.json({ guilds: await this.client.guilds.cache.size })
        });
    }
}

module.exports = WebSocket