-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.ts
102 lines (85 loc) · 2.98 KB
/
bot.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
97
98
99
100
101
102
// Require the necessary discord.js classes
import { Client, GatewayIntentBits, CommandInteraction, InteractionType, Interaction, ChatInputCommandInteraction } from 'discord.js'
import registerHandler from './src/commands/register'
import newgameHandler from './src/commands/newgame'
import joinHandler from './src/commands/join'
import leaveHandler from './src/commands/leave'
import breakHandler from './src/commands/break'
import matchHandler from './src/commands/match'
import resultHandler from './src/commands/report'
import makeRegisterHandler from './src/commands/make-register'
import makeJoinHandler from './src/commands/make-join'
import makeLeaveHandler from './src/commands/make-leave'
import displayHandler from './src/commands/display'
import pingHandler from './src/commands/ping'
import separateHandler from './src/commands/separate'
import separationResetHandler from './src/commands/separation-reset'
import { tksPartyHandler, tksRecruitHandler } from './src/commands/tks'
import { execute as executeButtonHandlers } from './src/commands/buttonHandlers'
import { execute as executeModalHandlers } from './src/commands/modalHandlers'
require('dotenv').config()
const token = process.env.DISCORD_TOKEN
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] })
// When the client is ready, run this code (only once)
client.once('ready', () => {
console.log('Ready!')
})
// Login to Discord with your client's token
if (token) {
client.login(token)
} else {
console.log('DISCORD_TOKEN is not set')
}
export interface CommandHandler {
commandName: string
execute: (interaction: ChatInputCommandInteraction) => Promise<void>
}
const handlers = new Map<string, CommandHandler>()
const helpHandler: CommandHandler = {
commandName: 'sr-help',
execute: async (interaction) => {
await interaction.reply('参加する人は /sr-register でレーティング登録をして /sr-join で参加してね! \n参考URL: https://qsona.github.io/splat-rating/')
},
}
;[
registerHandler,
newgameHandler,
joinHandler,
leaveHandler,
matchHandler,
breakHandler,
resultHandler,
makeRegisterHandler,
makeJoinHandler,
makeLeaveHandler,
displayHandler,
pingHandler,
helpHandler,
separateHandler,
separationResetHandler,
tksRecruitHandler,
tksPartyHandler,
].forEach((handler) => {
handlers.set(handler.commandName, handler)
})
export const onInteractionCreated = async (interaction: Interaction) => {
// if (interaction.type !== InteractionType.ApplicationCommand) {
if (interaction.isChatInputCommand()) {
const { commandName } = interaction
const handler = handlers.get(commandName)
if (handler) {
await handler.execute(interaction)
}
return
}
if (interaction.isButton()) {
await executeButtonHandlers(interaction)
return
}
if (interaction.type === InteractionType.ModalSubmit) {
await executeModalHandlers(interaction)
return
}
}
client.on('interactionCreate', onInteractionCreated)