Skip to content

Commit 3d7056e

Browse files
committed
let spring automatically detect subcommands
1 parent b2638db commit 3d7056e

File tree

15 files changed

+91
-141
lines changed

15 files changed

+91
-141
lines changed

src/main/java/net/javadiscord/javabot/Bot.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.dynxsty.dih4jda.DIH4JDA;
2121
import com.dynxsty.dih4jda.interactions.commands.ContextCommand;
2222
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
23+
import com.dynxsty.dih4jda.interactions.commands.SlashCommand.Subcommand;
2324
import com.dynxsty.dih4jda.interactions.components.ButtonHandler;
2425
import com.dynxsty.dih4jda.interactions.components.ModalHandler;
2526
import com.dynxsty.dih4jda.interactions.components.SelectMenuHandler;
@@ -39,7 +40,7 @@
3940
*/
4041
@SpringBootApplication
4142
@ComponentScan(
42-
includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { SlashCommand.class, ContextCommand.class, ListenerAdapter.class }),
43+
includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { SlashCommand.class, ContextCommand.class, ListenerAdapter.class, Subcommand.class }),
4344
excludeFilters = @ComponentScan.Filter(type=FilterType.ASSIGNABLE_TYPE, classes = PresenceUpdater.class)
4445
)
4546
@EnableScheduling

src/main/java/net/javadiscord/javabot/data/h2db/commands/DbAdminCommand.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
package net.javadiscord.javabot.data.h2db.commands;
22

3+
import java.util.Map;
4+
import java.util.Set;
5+
36
import com.dynxsty.dih4jda.interactions.commands.RegistrationType;
47
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
8+
59
import net.dv8tion.jda.api.Permission;
610
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
711
import net.dv8tion.jda.api.interactions.commands.build.Commands;
812
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
913
import net.javadiscord.javabot.data.config.BotConfig;
10-
import net.javadiscord.javabot.data.h2db.DbActions;
11-
import net.javadiscord.javabot.data.h2db.message_cache.MessageCache;
12-
13-
import java.util.Map;
14-
import java.util.Set;
15-
import java.util.concurrent.ExecutorService;
16-
17-
import javax.sql.DataSource;
1814

1915
/**
2016
* Represents the `/db-admin` command. This holds administrative commands for managing the bot's database.
@@ -23,21 +19,23 @@ public class DbAdminCommand extends SlashCommand {
2319
/**
2420
* This classes constructor which sets the {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData} and
2521
* adds the corresponding {@link net.dv8tion.jda.api.interactions.commands.Command.SubcommandGroup}s & {@link net.dv8tion.jda.api.interactions.commands.Command.Subcommand}s.
26-
* @param messageCache A service managing recent messages
27-
* @param asyncPool The thread pool for asynchronous operations
2822
* @param botConfig The main configuration of the bot
29-
* @param dataSource A factory for connections to the main database
30-
* @param dbActions A utility object providing various operations on the main database
23+
* @param exportSchemaSubcommand /db-admin export-schema
24+
* @param exportTableSubcommand /db-admin export-table
25+
* @param migrationsListSubcommand /db-admin migrations-list
26+
* @param migrateSubcommand /db-admin migrate
27+
* @param quickMigrateSubcommand /db-admin quick-migrate
28+
* @param messageCacheInfoSubcommand /db-admin message-cache info
3129
*/
32-
public DbAdminCommand(MessageCache messageCache, ExecutorService asyncPool, BotConfig botConfig, DataSource dataSource, DbActions dbActions) {
30+
public DbAdminCommand(BotConfig botConfig, ExportSchemaSubcommand exportSchemaSubcommand, ExportTableSubcommand exportTableSubcommand, MigrationsListSubcommand migrationsListSubcommand, MigrateSubcommand migrateSubcommand, QuickMigrateSubcommand quickMigrateSubcommand, MessageCacheInfoSubcommand messageCacheInfoSubcommand) {
3331
setRegistrationType(RegistrationType.GUILD);
3432
setSlashCommandData(Commands.slash("db-admin", "(ADMIN ONLY) Administrative Commands for managing the bot's database.")
3533
.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.MANAGE_SERVER))
3634
.setGuildOnly(true)
3735
);
38-
addSubcommands(new ExportSchemaSubcommand(asyncPool, botConfig, dataSource), new ExportTableSubcommand(asyncPool, botConfig.getSystems(), dataSource), new MigrationsListSubcommand(botConfig.getSystems()), new MigrateSubcommand(asyncPool, dataSource, botConfig.getSystems()), new QuickMigrateSubcommand(dataSource, asyncPool, botConfig.getSystems()));
36+
addSubcommands(exportSchemaSubcommand, exportTableSubcommand, migrationsListSubcommand, migrateSubcommand, quickMigrateSubcommand);
3937
addSubcommandGroups(Map.of(
40-
new SubcommandGroupData("message-cache", "Administrative tools for managing the Message Cache."), Set.of(new MessageCacheInfoSubcommand(messageCache, botConfig, dbActions))
38+
new SubcommandGroupData("message-cache", "Administrative tools for managing the Message Cache."), Set.of(messageCacheInfoSubcommand)
4139
));
4240
requireUsers(botConfig.getSystems().getAdminConfig().getAdminUsers());
4341
}

src/main/java/net/javadiscord/javabot/systems/configuration/ConfigCommand.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ public class ConfigCommand extends SlashCommand implements CommandModerationPerm
1313
/**
1414
* The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
1515
* @param botConfig The main configuration of the bot
16+
* @param exportConfigSubcommand /config export
17+
* @param getConfigSubcommand /config get
18+
* @param setConfigSubcommand /config set
1619
*/
17-
public ConfigCommand(BotConfig botConfig) {
20+
public ConfigCommand(BotConfig botConfig, ExportConfigSubcommand exportConfigSubcommand, GetConfigSubcommand getConfigSubcommand, SetConfigSubcommand setConfigSubcommand) {
1821
setModerationSlashCommandData(Commands.slash("config", "Administrative Commands for managing the bot's configuration."));
19-
addSubcommands(new ExportConfigSubcommand(botConfig), new GetConfigSubcommand(botConfig), new SetConfigSubcommand(botConfig));
22+
addSubcommands(exportConfigSubcommand, getConfigSubcommand, setConfigSubcommand);
2023
requireUsers(botConfig.getSystems().getAdminConfig().getAdminUsers());
2124
}
2225
}
Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
package net.javadiscord.javabot.systems.help.commands;
22

3-
import java.util.concurrent.ScheduledExecutorService;
4-
5-
import javax.sql.DataSource;
6-
73
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
84
import net.dv8tion.jda.api.interactions.commands.build.Commands;
95
import net.javadiscord.javabot.data.config.BotConfig;
10-
import net.javadiscord.javabot.data.h2db.DbActions;
11-
import net.javadiscord.javabot.systems.help.HelpExperienceService;
126

137
/**
148
* Represents the `/help` command. This holds commands related to the help system.
159
*/
1610
public class HelpCommand extends SlashCommand {
1711
/**
1812
* The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
19-
* @param asyncPool The thread pool for asynchronous operations
2013
* @param botConfig The main configuration of the bot
21-
* @param dataSource A factory for connections to the main database
22-
* @param dbActions A service object responsible for various operations on the main database
23-
* @param helpExperienceService Service object that handles Help Experience Transactions.
14+
* @param helpAccountSubcommand /help account
15+
* @param helpPingSubcommand /help ping
16+
* @param helpGuidelinesSubcommand /help guidelines
2417
*/
25-
public HelpCommand(DataSource dataSource, BotConfig botConfig, ScheduledExecutorService asyncPool, DbActions dbActions, HelpExperienceService helpExperienceService) {
18+
public HelpCommand(BotConfig botConfig, HelpAccountSubcommand helpAccountSubcommand, HelpPingSubcommand helpPingSubcommand, HelpGuidelinesSubcommand helpGuidelinesSubcommand) {
2619
setSlashCommandData(Commands.slash("help", "Commands related to the help system.")
2720
.setGuildOnly(true)
2821
);
29-
addSubcommands(new HelpAccountSubcommand(dbActions, helpExperienceService), new HelpPingSubcommand(botConfig, asyncPool, helpExperienceService, dbActions), new HelpGuidelinesSubcommand(botConfig));
22+
addSubcommands(helpAccountSubcommand, helpPingSubcommand, helpGuidelinesSubcommand);
3023
}
3124
}

src/main/java/net/javadiscord/javabot/systems/moderation/server_lock/ServerLockCommand.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
44
import net.dv8tion.jda.api.interactions.commands.build.Commands;
5-
import net.javadiscord.javabot.data.config.BotConfig;
65
import net.javadiscord.javabot.systems.moderation.CommandModerationPermissions;
76

87
/**
@@ -12,11 +11,11 @@ public class ServerLockCommand extends SlashCommand implements CommandModeration
1211
/**
1312
* This classes constructor which sets the {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData} and
1413
* adds the corresponding {@link net.dv8tion.jda.api.interactions.commands.Command.Subcommand}s.
15-
* @param serverLockManager the service containing functionality regarding the server lock
16-
* @param botConfig The main configuration of the bot
14+
* @param setLockStatusSubcommand /serverlock-admin set-status
15+
* @param checkLockStatusSubcommand /serverlock-admin check-status
1716
*/
18-
public ServerLockCommand(ServerLockManager serverLockManager, BotConfig botConfig) {
17+
public ServerLockCommand(SetLockStatusSubcommand setLockStatusSubcommand, CheckLockStatusSubcommand checkLockStatusSubcommand) {
1918
setModerationSlashCommandData(Commands.slash("serverlock-admin", "Administrative commands for managing the server lock functionality."));
20-
addSubcommands(new SetLockStatusSubcommand(serverLockManager, botConfig), new CheckLockStatusSubcommand(botConfig));
19+
addSubcommands(setLockStatusSubcommand, checkLockStatusSubcommand);
2120
}
2221
}
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
package net.javadiscord.javabot.systems.moderation.timeout;
22

3-
import java.util.concurrent.ExecutorService;
4-
53
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
4+
65
import net.dv8tion.jda.api.interactions.commands.build.Commands;
7-
import net.javadiscord.javabot.data.config.BotConfig;
8-
import net.javadiscord.javabot.data.h2db.DbHelper;
96
import net.javadiscord.javabot.systems.moderation.CommandModerationPermissions;
10-
import net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository;
11-
import net.javadiscord.javabot.systems.notification.NotificationService;
127

138
/**
149
* Handler class for all timeout specific commands.
1510
*/
1611
public class TimeoutCommand extends SlashCommand implements CommandModerationPermissions {
1712
/**
1813
* The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
19-
* @param notificationService The {@link NotificationService}
20-
* @param botConfig The main configuration of the bot
21-
* @param dbHelper An object managing databse operations
22-
* @param asyncPool The main thread pool for asynchronous operations
23-
* @param warnRepository DAO for interacting with the set of {@link Warn} objects.
14+
* @param addTimeoutSubcommand /timeout add
15+
* @param removeTimeoutSubcommand /timeout remove
2416
*/
25-
public TimeoutCommand(NotificationService notificationService, BotConfig botConfig, DbHelper dbHelper, ExecutorService asyncPool, WarnRepository warnRepository) {
17+
public TimeoutCommand(AddTimeoutSubcommand addTimeoutSubcommand, RemoveTimeoutSubcommand removeTimeoutSubcommand) {
2618
setModerationSlashCommandData(Commands.slash("timeout", "Commands for managing member timeouts."));
27-
addSubcommands(new AddTimeoutSubcommand(notificationService, botConfig, asyncPool, warnRepository), new RemoveTimeoutSubcommand(notificationService, botConfig, asyncPool, warnRepository));
19+
addSubcommands(addTimeoutSubcommand, removeTimeoutSubcommand);
2820
}
2921
}
Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package net.javadiscord.javabot.systems.moderation.warn;
22

3-
import java.util.concurrent.ExecutorService;
4-
53
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
4+
65
import net.dv8tion.jda.api.interactions.commands.build.Commands;
7-
import net.javadiscord.javabot.data.config.BotConfig;
8-
import net.javadiscord.javabot.data.h2db.DbHelper;
96
import net.javadiscord.javabot.systems.moderation.CommandModerationPermissions;
10-
import net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository;
11-
import net.javadiscord.javabot.systems.notification.NotificationService;
127

138
/**
149
* Represents the `/warn` command. This holds administrative commands for managing user warns.
@@ -17,14 +12,12 @@ public class WarnCommand extends SlashCommand implements CommandModerationPermis
1712
/**
1813
* This classes constructor which sets the {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData} and
1914
* adds the corresponding {@link net.dv8tion.jda.api.interactions.commands.Command.Subcommand}s.
20-
* @param notificationService The {@link NotificationService}
21-
* @param botConfig The main configuration of the bot
22-
* @param dbHelper An object managing databse operations
23-
* @param asyncPool The main thread pool for asynchronous operations
24-
* @param warnRepository DAO for interacting with the set of {@link Warn} objects.
15+
* @param warnAddSubcommand /warn add
16+
* @param discardWarnByIdSubCommand /warn discard-by-id
17+
* @param discardAllWarnsSubcommand /warn discard-all
2518
*/
26-
public WarnCommand(NotificationService notificationService, BotConfig botConfig, DbHelper dbHelper, ExecutorService asyncPool, WarnRepository warnRepository) {
19+
public WarnCommand(WarnAddSubcommand warnAddSubcommand, DiscardWarnByIdSubCommand discardWarnByIdSubCommand, DiscardAllWarnsSubcommand discardAllWarnsSubcommand) {
2720
setModerationSlashCommandData(Commands.slash("warn", "Administrative commands for managing user warns."));
28-
addSubcommands(new WarnAddSubcommand(notificationService, botConfig, asyncPool, warnRepository), new DiscardWarnByIdSubCommand(notificationService, botConfig, warnRepository, asyncPool), new DiscardAllWarnsSubcommand(notificationService, botConfig, warnRepository, asyncPool));
21+
addSubcommands(warnAddSubcommand, discardWarnByIdSubCommand, discardAllWarnsSubcommand);
2922
}
3023
}
Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,43 @@
11
package net.javadiscord.javabot.systems.qotw.commands;
22

3+
import java.util.Map;
4+
import java.util.Set;
5+
36
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
7+
48
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
59
import net.dv8tion.jda.api.interactions.commands.build.Commands;
610
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
7-
import net.javadiscord.javabot.data.config.BotConfig;
8-
import net.javadiscord.javabot.data.h2db.DbHelper;
9-
import net.javadiscord.javabot.systems.notification.NotificationService;
10-
import net.javadiscord.javabot.systems.qotw.QOTWPointsService;
1111
import net.javadiscord.javabot.systems.qotw.commands.qotw_points.IncrementPointsSubcommand;
1212
import net.javadiscord.javabot.systems.qotw.commands.qotw_points.SetPointsSubcommand;
1313
import net.javadiscord.javabot.systems.qotw.commands.questions_queue.AddQuestionSubcommand;
1414
import net.javadiscord.javabot.systems.qotw.commands.questions_queue.ListQuestionsSubcommand;
1515
import net.javadiscord.javabot.systems.qotw.commands.questions_queue.RemoveQuestionSubcommand;
16-
import net.javadiscord.javabot.systems.qotw.dao.QuestionPointsRepository;
17-
import net.javadiscord.javabot.systems.qotw.dao.QuestionQueueRepository;
18-
import net.javadiscord.javabot.systems.qotw.submissions.dao.QOTWSubmissionRepository;
1916
import net.javadiscord.javabot.systems.qotw.submissions.subcommands.MarkBestAnswerSubcommand;
2017

21-
import java.util.Map;
22-
import java.util.Set;
23-
import java.util.concurrent.ExecutorService;
24-
2518
/**
2619
* Represents the `/qotw-admin` command. This holds administrative commands for managing the Question of the Week.
2720
*/
2821
public class QOTWAdminCommand extends SlashCommand {
2922
/**
3023
* This classes constructor which sets the {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData} and
3124
* adds the corresponding {@link net.dv8tion.jda.api.interactions.commands.Command.SubcommandGroup}s.
32-
* @param pointsService The {@link QOTWPointsService}
33-
* @param notificationService The {@link NotificationService}
34-
* @param botConfig The main configuration of the bot
35-
* @param dbHelper An object managing databse operations
36-
* @param qotwPointsRepository Dao object that represents the QOTW_POINTS SQL Table.
37-
* @param questionQueueRepository Dao class that represents the QOTW_QUESTION SQL Table.
38-
* @param asyncPool The main thread pool for asynchronous operations
39-
* @param qotwSubmissionRepository Dao object that represents the QOTW_SUBMISSIONS SQL Table.
25+
* @param listQuestionsSubcommand /qotw-admin questions-queue list-questions
26+
* @param addQuestionSubcommand /qotw-admin questions-queue add
27+
* @param removeQuestionSubcommand /qotw-admin questions-queue remove
28+
* @param incrementPointsSubcommand /qotw-admin account increment
29+
* @param setPointsSubcommand /qotw-admin account set
30+
* @param markBestAnswerSubcommand /qotw-admin submissions mark-best
4031
*/
41-
public QOTWAdminCommand(QOTWPointsService pointsService, NotificationService notificationService, BotConfig botConfig, DbHelper dbHelper, QuestionPointsRepository qotwPointsRepository, QuestionQueueRepository questionQueueRepository, ExecutorService asyncPool, QOTWSubmissionRepository qotwSubmissionRepository) {
32+
public QOTWAdminCommand(ListQuestionsSubcommand listQuestionsSubcommand, AddQuestionSubcommand addQuestionSubcommand, RemoveQuestionSubcommand removeQuestionSubcommand, IncrementPointsSubcommand incrementPointsSubcommand, SetPointsSubcommand setPointsSubcommand, MarkBestAnswerSubcommand markBestAnswerSubcommand) {
4233
setSlashCommandData(Commands.slash("qotw-admin", "Administrative tools for managing the Question of the Week.")
4334
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)
4435
.setGuildOnly(true)
4536
);
4637
addSubcommandGroups(Map.of(
47-
new SubcommandGroupData("questions-queue", "Commands for interacting with the set of QOTW questions that are in queue."), Set.of(new ListQuestionsSubcommand(questionQueueRepository, asyncPool), new AddQuestionSubcommand(questionQueueRepository, asyncPool), new RemoveQuestionSubcommand(questionQueueRepository)),
48-
new SubcommandGroupData("account", "Commands for interaction with Users Question of the Week points."), Set.of(new IncrementPointsSubcommand(pointsService, notificationService), new SetPointsSubcommand(pointsService, dbHelper.getDataSource(), qotwPointsRepository)),
49-
new SubcommandGroupData("submissions", "Commands for managing QOTW Submissions."), Set.of(new MarkBestAnswerSubcommand(pointsService, notificationService, botConfig, asyncPool, qotwSubmissionRepository))
38+
new SubcommandGroupData("questions-queue", "Commands for interacting with the set of QOTW questions that are in queue."), Set.of(listQuestionsSubcommand, addQuestionSubcommand, removeQuestionSubcommand),
39+
new SubcommandGroupData("account", "Commands for interaction with Users Question of the Week points."), Set.of(incrementPointsSubcommand, setPointsSubcommand),
40+
new SubcommandGroupData("submissions", "Commands for managing QOTW Submissions."), Set.of(markBestAnswerSubcommand)
5041
));
5142
}
5243
}

0 commit comments

Comments
 (0)