11package net .javadiscord .javabot .systems .help .commands ;
22
3- import java .util .concurrent .ScheduledExecutorService ;
4-
53import xyz .dynxsty .dih4jda .interactions .commands .application .SlashCommand ;
6- import net .dv8tion .jda .api .entities .User ;
74import net .dv8tion .jda .api .entities .channel .ChannelType ;
8- import net .dv8tion .jda .api .entities .channel .concrete .TextChannel ;
95import net .dv8tion .jda .api .entities .channel .concrete .ThreadChannel ;
106import net .dv8tion .jda .api .events .interaction .command .SlashCommandInteractionEvent ;
117import net .dv8tion .jda .api .interactions .commands .CommandInteraction ;
128import net .dv8tion .jda .api .interactions .commands .OptionMapping ;
139import net .dv8tion .jda .api .interactions .commands .OptionType ;
1410import net .dv8tion .jda .api .interactions .commands .build .Commands ;
1511import net .javadiscord .javabot .data .config .BotConfig ;
16- import net .javadiscord .javabot .data .config .guild .HelpConfig ;
1712import net .javadiscord .javabot .data .h2db .DbActions ;
18- import net .javadiscord .javabot .systems .help .HelpChannelManager ;
19- import net .javadiscord .javabot .systems .help .HelpExperienceService ;
2013import net .javadiscord .javabot .systems .help .dao .HelpAccountRepository ;
2114import net .javadiscord .javabot .systems .help .dao .HelpTransactionRepository ;
2215import net .javadiscord .javabot .systems .help .forum .ForumHelpManager ;
2922 */
3023public class UnreserveCommand extends SlashCommand {
3124 private final BotConfig botConfig ;
32- private final ScheduledExecutorService asyncPool ;
3325 private final DbActions dbActions ;
34- private final HelpExperienceService helpExperienceService ;
3526 private final HelpAccountRepository helpAccountRepository ;
3627 private final HelpTransactionRepository helpTransactionRepository ;
3728
3829 /**
3930 * The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
40- * @param asyncPool The thread pool for asynchronous operations
4131 * @param botConfig The main configuration of the bot
4232 * @param dbActions A utility object providing various operations on the main database
43- * @param helpExperienceService Service object that handles Help Experience Transactions.
4433 * @param helpTransactionRepository Dao object that represents the HELP_TRANSACTION SQL Table.
4534 * @param helpAccountRepository Dao object that represents the HELP_ACCOUNT SQL Table.
4635 */
47- public UnreserveCommand (BotConfig botConfig , ScheduledExecutorService asyncPool , DbActions dbActions , HelpExperienceService helpExperienceService , HelpTransactionRepository helpTransactionRepository , HelpAccountRepository helpAccountRepository ) {
36+ public UnreserveCommand (BotConfig botConfig , DbActions dbActions , HelpTransactionRepository helpTransactionRepository , HelpAccountRepository helpAccountRepository ) {
4837 this .botConfig = botConfig ;
49- this .asyncPool = asyncPool ;
5038 this .dbActions = dbActions ;
51- this .helpExperienceService = helpExperienceService ;
5239 this .helpAccountRepository = helpAccountRepository ;
5340 this .helpTransactionRepository = helpTransactionRepository ;
5441 setCommandData (Commands .slash ("unreserve" , "Unreserves this help channel so that others can use it." )
@@ -64,17 +51,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
6451 replyInvalidChannel (event );
6552 return ;
6653 }
67- // handle forum-based help system
68- if (event .getChannelType () == ChannelType .GUILD_PUBLIC_THREAD ) {
69- handleForumBasedHelp (event , event .getChannel ().asThreadChannel ());
70- }
71- // handle text-based help system
72- if (event .getChannelType () == ChannelType .TEXT ) {
73- handleTextBasedHelp (event , event .getChannel ().asTextChannel ());
74- }
75- }
76-
77- private void handleForumBasedHelp (SlashCommandInteractionEvent event , @ NotNull ThreadChannel postThread ) {
54+ ThreadChannel postThread = event .getChannel ().asThreadChannel ();
7855 if (postThread .getParentChannel ().getType () != ChannelType .FORUM ) {
7956 replyInvalidChannel (event );
8057 }
@@ -88,45 +65,9 @@ private void handleForumBasedHelp(SlashCommandInteractionEvent event, @NotNull T
8865 }
8966 }
9067
91- private void handleTextBasedHelp (@ NotNull SlashCommandInteractionEvent event , TextChannel channel ) {
92- HelpConfig config = botConfig .get (event .getGuild ()).getHelpConfig ();
93- HelpChannelManager channelManager = new HelpChannelManager (botConfig , event .getGuild (), dbActions , asyncPool , helpExperienceService );
94- User owner = channelManager .getReservedChannelOwner (channel );
95- if (isTextEligibleToBeUnreserved (event , channel , config , owner )) {
96- String reason = event .getOption ("reason" , null , OptionMapping ::getAsString );
97- event .deferReply (true ).queue ();
98- channelManager .unreserveChannelByOwner (channel , owner , reason , event );
99- } else {
100- Responses .warning (event , "Could not unreserve this channel. This command only works in help channels you've reserved." ).queue ();
101- }
102- }
103-
10468 private void replyInvalidChannel (CommandInteraction interaction ) {
10569 Responses .warning (interaction , "Invalid Channel" ,
10670 "This command may only be used in either the text-channel-based help system, or in our new forum help system." )
10771 .queue ();
10872 }
109-
110- private boolean isTextEligibleToBeUnreserved (SlashCommandInteractionEvent event , TextChannel channel , HelpConfig config , User owner ) {
111- return channelIsInReservedCategory (channel , config ) &&
112- (isUserWhoReservedChannel (event , owner ) || memberHasHelperRole (event ) || memberHasStaffRole (event ));
113- }
114-
115- private boolean channelIsInReservedCategory (@ NotNull TextChannel channel , @ NotNull HelpConfig config ) {
116- return config .getReservedChannelCategory ().equals (channel .getParentCategory ());
117- }
118-
119- private boolean isUserWhoReservedChannel (SlashCommandInteractionEvent event , User owner ) {
120- return owner != null && event .getUser ().equals (owner );
121- }
122-
123- private boolean memberHasStaffRole (@ NotNull SlashCommandInteractionEvent event ) {
124- return event .getMember () != null &&
125- event .getMember ().getRoles ().contains (botConfig .get (event .getGuild ()).getModerationConfig ().getStaffRole ());
126- }
127-
128- private boolean memberHasHelperRole (@ NotNull SlashCommandInteractionEvent event ) {
129- return event .getMember () != null &&
130- event .getMember ().getRoles ().contains (botConfig .get (event .getGuild ()).getHelpConfig ().getHelperRole ());
131- }
13273}
0 commit comments