summaryrefslogtreecommitdiff
path: root/src/server.ts
blob: 11576f1c7b5e37d693b7c55cdc5a245818ed6929 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//@ts-nocheck //TODO: this

import express from 'express';
import bodyParser from 'body-parser';

class WebSocket {
    client: any;
    app: any;
    server: any;
    constructor(port: any, client: any) {
        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.all('*', function (req, res, next) {
            res.header('Access-Control-Allow-Origin', '*');
            res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
            res.header('Access-Control-Allow-Headers', 'Content-Type');
            next();
        });

        this.app.get('/', (req, res) => {
            res.redirect('https://kyzer.co/discord/bots/uwufier/')
        })
        this.app.get('/api/v1/commands/', async (req, res) => {
            res.json({ commands: await this.client.registry.commands.size })
        });
        this.app.get('/api/v1/groups/', async (req, res) => {
            res.json({ groups: await this.client.registry.groups.size })
        });
        this.app.get('/api/v1/commands/groups/', async (req, res) => {
            res.json({ groups: await this.client.registry.groups.size })
        });
        this.app.get('/api/v1/guilds/', async (req, res) => {
            res.json({ guilds: await this.client.guilds.cache.size })
        });
    }
}

module.exports = WebSocket