Skip to content

Commit 74e77e9

Browse files
committed
Renamed CommandRegistry to Commands
as discussed in CR
1 parent 1a1223c commit 74e77e9

6 files changed

Lines changed: 20 additions & 16 deletions

File tree

application/src/main/java/org/togetherjava/tjbot/Application.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import net.dv8tion.jda.api.JDABuilder;
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
7+
import org.togetherjava.tjbot.commands.Commands;
78
import org.togetherjava.tjbot.commands.system.CommandSystem;
89
import org.togetherjava.tjbot.config.Config;
910
import org.togetherjava.tjbot.db.Database;
@@ -19,7 +20,7 @@
1920
* New commands can be created by implementing
2021
* {@link net.dv8tion.jda.api.events.interaction.SlashCommandEvent} or extending
2122
* {@link org.togetherjava.tjbot.commands.SlashCommandAdapter}. They can then be registered in
22-
* {@link org.togetherjava.tjbot.commands.CommandRegistry}.
23+
* {@link Commands}.
2324
*/
2425
public enum Application {
2526
;

application/src/main/java/org/togetherjava/tjbot/commands/CommandRegistry.java renamed to application/src/main/java/org/togetherjava/tjbot/commands/Commands.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
import java.util.List;
1010

1111
/**
12-
* Utility class that offers all registered commands. New commands have to be added here, where
13-
* {@link org.togetherjava.tjbot.commands.system.CommandSystem} will then pick it up from and
14-
* register it with the system.
12+
* Utility class that offers all commands that should be registered by the system. New commands have
13+
* to be added here, where {@link org.togetherjava.tjbot.commands.system.CommandSystem} will then
14+
* pick it up from and register it with the system.
1515
* <p>
1616
* To add a new slash command, extend the commands returned by
1717
* {@link #createSlashCommands(Database)}.
1818
*/
19-
public enum CommandRegistry {
19+
public enum Commands {
2020
;
2121

2222
/**
@@ -30,6 +30,9 @@ public enum CommandRegistry {
3030
*/
3131
public static @NotNull Collection<SlashCommand> createSlashCommands(
3232
@NotNull Database database) {
33+
// NOTE The command system can add special system relevant commands also by itself,
34+
// hence this list may not necessarily represent the full list of all commands actually
35+
// available.
3336
return List.of(new PingCommand(), new DatabaseCommand(database));
3437
}
3538
}

application/src/main/java/org/togetherjava/tjbot/commands/SlashCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* <p>
1818
* All slash commands have to implement this interface. For convenience, there is a
1919
* {@link SlashCommandAdapter} available that implemented most methods already. A new command can
20-
* then be registered by adding it to {@link CommandRegistry}.
20+
* then be registered by adding it to {@link Commands}.
2121
* <p>
2222
* <p>
2323
* Slash commands can either be visible globally in Discord or just to specific guilds. They can

application/src/main/java/org/togetherjava/tjbot/commands/SlashCommandAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* Adapter implementation of a {@link SlashCommand}. The minimal setup only requires implementation
1616
* of {@link #onSlashCommand(SlashCommandEvent)}. A new command can then be registered by adding it
17-
* to {@link CommandRegistry}.
17+
* to {@link Commands}.
1818
* <p>
1919
* Further, {@link #onButtonClick(ButtonClickEvent, List)} and
2020
* {@link #onSelectionMenu(SelectionMenuEvent, List)} can be overridden if desired. The default
@@ -51,7 +51,7 @@
5151
* }
5252
* </pre>
5353
*
54-
* and registration of an instance of that class in {@link CommandRegistry}.
54+
* and registration of an instance of that class in {@link Commands}.
5555
*/
5656
public abstract class SlashCommandAdapter implements SlashCommand {
5757
private final String name;

application/src/main/java/org/togetherjava/tjbot/commands/package-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* This package contains the command system and most commands of the bot. Commands can also be
33
* created in different modules, if desired.
44
* <p>
5-
* Commands are registered in {@link org.togetherjava.tjbot.commands.CommandRegistry} and then
6-
* picked up by the {@link org.togetherjava.tjbot.commands.system.CommandSystem}.
5+
* Commands are registered in {@link org.togetherjava.tjbot.commands.Commands} and then picked up by
6+
* the {@link org.togetherjava.tjbot.commands.system.CommandSystem}.
77
* <p>
88
* Custom slash commands can be created by implementing
99
* {@link org.togetherjava.tjbot.commands.SlashCommand} or using the adapter

application/src/main/java/org/togetherjava/tjbot/commands/system/CommandSystem.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.jetbrains.annotations.NotNull;
1313
import org.slf4j.Logger;
1414
import org.slf4j.LoggerFactory;
15-
import org.togetherjava.tjbot.commands.CommandRegistry;
15+
import org.togetherjava.tjbot.commands.Commands;
1616
import org.togetherjava.tjbot.commands.SlashCommand;
1717
import org.togetherjava.tjbot.db.Database;
1818

@@ -28,9 +28,9 @@
2828
* of event parsing.
2929
* <p>
3030
* <p>
31-
* Commands are made available via {@link CommandRegistry}, then the system has to be added to JDA
32-
* as an event listener, using {@link net.dv8tion.jda.api.JDA#addEventListener(Object...)}.
33-
* Afterwards, the system is ready and will correctly forward events to all commands.
31+
* Commands are made available via {@link Commands}, then the system has to be added to JDA as an
32+
* event listener, using {@link net.dv8tion.jda.api.JDA#addEventListener(Object...)}. Afterwards,
33+
* the system is ready and will correctly forward events to all commands.
3434
*/
3535
public final class CommandSystem extends ListenerAdapter implements SlashCommandProvider {
3636
private static final Logger logger = LoggerFactory.getLogger(CommandSystem.class);
@@ -40,13 +40,13 @@ public final class CommandSystem extends ListenerAdapter implements SlashCommand
4040
/**
4141
* Creates a new command system which uses the given database to allow commands to persist data.
4242
* <p>
43-
* Commands are fetched from {@link CommandRegistry}.
43+
* Commands are fetched from {@link Commands}.
4444
*
4545
* @param database the database that commands may use to persist data
4646
*/
4747
@SuppressWarnings("ThisEscapedInObjectConstruction")
4848
public CommandSystem(@NotNull Database database) {
49-
nameToSlashCommands = CommandRegistry.createSlashCommands(database)
49+
nameToSlashCommands = Commands.createSlashCommands(database)
5050
.stream()
5151
.collect(Collectors.toMap(SlashCommand::getName, Function.identity()));
5252

0 commit comments

Comments
 (0)