-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added config and onSlashCommand method (#12)
* added config and onSlashCommand method * load config from path * split main method * removed redundent check
- Loading branch information
Showing
8 changed files
with
64 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,5 +44,5 @@ nbdist/ | |
# Ignore Gradle build output directory | ||
build | ||
|
||
### Vim ### | ||
.vim/ | ||
# Credentials | ||
bot-config.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
BOT_TOKEN=<put your token here> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.togetherjava.tjplays; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import com.togetherjava.tjplays.listeners.commands.*; | ||
|
||
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 { | ||
Properties properties = readProperties(args); | ||
|
||
String botToken = properties.getProperty("BOT_TOKEN"); | ||
|
||
createJDA(botToken); | ||
} | ||
|
||
private static Properties readProperties(String... args) throws IOException { | ||
Properties properties = new Properties(); | ||
|
||
String configPath = args.length == 0 ? "bot-config.properties" : args[0]; | ||
properties.load(new FileInputStream(configPath)); | ||
|
||
return properties; | ||
} | ||
|
||
private static JDA createJDA(String botToken) { | ||
JDA jda = JDABuilder.createDefault(botToken).build(); | ||
|
||
List<SlashCommand> commands = getCommands(); | ||
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() { | ||
return List.of( | ||
new PingCommand(), | ||
new Game2048Command() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters