-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (45 loc) · 1.71 KB
/
index.js
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
import 'dotenv/config';
import express from 'express';
import { InteractionType, InteractionResponseType } from 'discord-interactions';
import { VerifyDiscordRequest, createMasterAccount } from './utils.mjs';
import { commandHandler, createCommands } from './commands/index.mjs';
// Create an express app
const app = express();
// Get port, or default to 3000
const PORT = process.env.PORT || 3000;
// Parse request body and verifies incoming requests using discord-interactions package
app.use(express.json({ verify: VerifyDiscordRequest(process.env.PUBLIC_KEY) }));
app.get('/healthcheck', (req, res) => res.send('ok'));
app.get('/verify-user', (req, res) => {
res.send('verified');
})
app.get('/terms-of-service', (req, res) => {
res.send('use at your own risk.');
})
app.get('/privacy-policy', (req, res) => {
res.send('I might save your discord info to reference later. But I don\'t know your real name or anything... Nancy.');
})
/**
* Interactions endpoint URL where Discord will send HTTP requests
*/
app.post('/interactions', async function (req, res) {
// Interaction type and data
const { type } = req.body;
/**
* Handle verification requests
*/
if (type === InteractionType.PING) {
return res.send({ type: InteractionResponseType.PONG });
}
/**
* Handle slash command requests
* See https://discord.com/developers/docs/interactions/application-commands#slash-commands
*/
if (type === InteractionType.APPLICATION_COMMAND) return commandHandler(req, res);
});
app.listen(PORT, async () => {
console.log('Listening on port', PORT);
createCommands();
// const masterAccount = await createMasterAccount();
// console.log(`Master Account Address ${masterAccount.getAddress()}`);
});