-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
63 lines (45 loc) · 1.87 KB
/
index.ts
File metadata and controls
63 lines (45 loc) · 1.87 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
import {config} from 'dotenv';
config();
import express from 'express';
import bot from './bot';
import CommandManager from './CommandManager';
const app = express();
app.use(express.json());
bot.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'ban') {
const {value: username} = interaction.options.get('username') as any;
const {value: reason} = interaction.options.get('reason') as any;
const {foundPlayerServer, chosenServer} = await CommandManager.sendToServer('ban', [username, reason], interaction.user, username);
if (foundPlayerServer) {
interaction.reply(`Found user in a server, sending command to there [${chosenServer}]`);
} else {
interaction.reply('Sent request to a server, request will be performed shortly');
setTimeout(() => {
interaction.followUp('Request has been successfully performed!');
}, 5000);
}
};
});
app.post('/ping', (req, res) => {
const {jobId} : {jobId: string} = req.query as any;
const {players} : {players: string[]} = req.body;
if (!jobId) return res.status(400).send('Missing jobId');
if (!players) return res.status(400).send('Missing players');
CommandManager.serverPing(jobId, players);
return res.sendStatus(204);
});
app.post('/removeCommand', (req, res) => {
const {commandIds} = req.body;
if (!commandIds) return res.status(400).send('Missing commandIds');
CommandManager.removeCommands(commandIds);
return res.sendStatus(204);
});
app.get('/list', (req, res) => {
const {jobId} : {jobId: string} = req.query as any;
if (!jobId) return res.status(400).send('Missing jobId');
return res.json(CommandManager.getCommandsFor(jobId));
});
app.listen(3000, () => {
console.log('listening on port 3000');
});