Skip to content

Migrate basic commands (ping, dbget, dbput) #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ First add the jitpack repository:
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
<repository>
</repository>
```
Then add the dependency:
```xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public static void runBot(String token, Path databasePath) {
Database database = new Database("jdbc:sqlite:" + databasePath.toAbsolutePath());

JDA jda = JDABuilder.createDefault(token)
.addEventListeners(new PingPongListener())
.addEventListeners(new DatabaseListener(database))
.addEventListeners(new CommandHandler())
.addEventListeners(new CommandHandler(database))
.build();
jda.awaitReady();
logger.info("Bot is ready");
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.togetherjava.tjbot.commands.basic.DatabaseCommand;
import org.togetherjava.tjbot.commands.basic.PingCommand;
import org.togetherjava.tjbot.db.Database;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -22,7 +25,7 @@

/**
* The command handler
*
* <p>
* Commands need to be added to the commandList
*/
public class CommandHandler extends ListenerAdapter {
Expand All @@ -31,8 +34,9 @@ public class CommandHandler extends ListenerAdapter {
private final List<Command> commandList = new ArrayList<>();
private final Map<String, Command> commandMap;

public CommandHandler() {
commandList.addAll(List.of(new ReloadCommand(this)));
public CommandHandler(Database database) {
commandList.addAll(
List.of(new ReloadCommand(this), new PingCommand(), new DatabaseCommand(database)));

commandMap = commandList.stream()
.collect(Collectors.toMap(Command::getCommandName, Function.identity()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void onButtonClick(ButtonClickEvent event, List<String> idArgs) {
RestAction.allOf(restActions)
.queue(updatedCommands -> event.getHook()
.editOriginal(
"Commands successfully reloaded! *Global commands can take upto 1 hour to load*")
"Commands successfully reloaded! *Global commands can take up to 1 hour to load*")
.queue());
}
default -> event.reply("I am not sure what you clicked?")
Expand Down
Loading