-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBot.java
More file actions
44 lines (34 loc) · 1.47 KB
/
Bot.java
File metadata and controls
44 lines (34 loc) · 1.47 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
package com.togetherjava.tjplays;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import com.togetherjava.tjplays.listeners.commands.*;
import com.togetherjava.tjplays.trivia.TriviaManager;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
public final class Bot {
public static void main(String[] args) throws IOException {
Config config = Config.readConfig(args.length == 0 ? null : Path.of(args[0]));
createBot(config);
}
private static JDA createBot(Config config) {
JDA jda = JDABuilder.createDefault(config.botToken()).build();
List<SlashCommand> commands = getCommands(config);
commands.forEach(command -> jda.addEventListener(command));
List<SlashCommandData> commandDatas = commands.stream()
.map(SlashCommand::getData)
.toList();
jda.updateCommands().addCommands(commandDatas).queue();
return jda;
}
private static List<SlashCommand> getCommands(Config config) {
// Construct JavaQuizCommand with TriviaManager and ChatGptService
TriviaManager triviaManager = new TriviaManager(new com.togetherjava.tjplays.services.chatgpt.ChatGptService(config.openAIApiKey()));
return java.util.Arrays.asList(
new PingCommand(),
new Game2048Command(),
new JavaQuizCommand(triviaManager)
);
}
}