-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.ts
96 lines (77 loc) · 2.15 KB
/
start.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import {Discordeno} from './deps.ts';
import * as Env from './env.ts';
import {Match} from './src/match.ts';
import {MatchManager} from './src/match_manager.ts';
const matchManager = new MatchManager();
const bot = Discordeno.createBot({
token: Env.TOKEN,
intents: ['Guilds', 'GuildMessages'],
botId: Env.APP_ID,
applicationId: Env.APP_ID,
events: {
interactionCreate(bot, interaction) {
if (!interaction.channelId)
return;
if (interaction.data?.name == 'hangman') {
if (matchManager.hasOngoingMatch(interaction.channelId)) {
Discordeno.sendInteractionResponse(bot, interaction.id, interaction.token, {
type: 4,
data: {content: '❗ There is an ongoing match in the current channel.'}
});
return;
}
Discordeno.sendInteractionResponse(bot, interaction.id, interaction.token, {
type: 4,
data: {content: "Let's play!"}
});
const match = new Match({
autoHints: 1,
bot: bot,
channelId: interaction.channelId,
duration: 300,
rounds: 1
});
matchManager.add(match);
} else {
Discordeno.sendInteractionResponse(bot, interaction.id, interaction.token, {
private: true,
type: 6
});
const match = matchManager.get(interaction.channelId);
if (!match)
return;
switch (interaction.data?.customId) {
case 'hint': {
match.getCurrentRound()?.requestHint();
break;
}
case 'synonym': {
match.getCurrentRound()?.requestSynonym();
break;
}
case 'example': {
match.getCurrentRound()?.requestExample();
break;
}
}
}
},
ready(bot) {
console.log('READY');
Discordeno.createApplicationCommand(bot, {
description: "🎗 Play Hangman by HelloLingers!",
name: 'hangman'
}, (Env.GUILD_ID ?? undefined))
},
messageCreate(_bot, message) {
const match = matchManager.get(message.channelId);
if (!match || !match.getCurrentRound())
return;
const msg = message.content.toLowerCase().trim();
if (msg.length == 1 || msg.length == match.getCurrentRound()?.word.text.length) {
match.getCurrentRound()?.guess(msg);
}
}
}
});
await Discordeno.startBot(bot);