forked from liang3472/freemint-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (59 loc) · 1.75 KB
/
app.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
56
57
58
59
60
61
62
63
64
65
import express from 'express';
import {
InteractionType,
InteractionResponseType,
} from 'discord-interactions';
import { VerifyDiscordRequest, getRandomEmoji } from './utils.js';
import {
START_COMMAND,
STOP_COMMAND,
INFO_COMMAND,
HasGuildCommands,
} from './commands.js';
import WatchDog from './watchDog.js';
const app = express();
app.use(express.json({ verify: VerifyDiscordRequest(process.env.PUBLIC_KEY) }));
app.post('/interactions', async function (req, res) {
const { type, id, data, channel_id } = req.body;
if (type === InteractionType.PING) {
return res.send({ type: InteractionResponseType.PONG });
}
if (type === InteractionType.APPLICATION_COMMAND) {
const { name } = data;
// 初始化
WatchDog.init(channel_id);
if (name === 'start') {
WatchDog.start(channel_id);
return res.send({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
content: `你踢了一脚🤖️, 它动了${getRandomEmoji()}`,
},
});
} else if (name === 'stop') {
WatchDog.stop(channel_id);
return res.send({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
content: `你踢了一脚🤖️, 它不动了${getRandomEmoji()}`,
},
});
} else if (name === 'test') {
WatchDog.info(channel_id);
return res.send({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
content: `你踢了一脚🤖️, 看它咋样了${getRandomEmoji()}`,
},
});
}
}
});
app.listen(3000, () => {
console.log('Listening on port 3000');
HasGuildCommands(process.env.APP_ID, process.env.GUILD_ID, [
START_COMMAND,
STOP_COMMAND,
INFO_COMMAND,
]);
});