Skip to content

Commit 3ef02e3

Browse files
Removed text-based help functionality from help commands
1 parent 827424e commit 3ef02e3

File tree

4 files changed

+9
-147
lines changed

4 files changed

+9
-147
lines changed

src/main/java/net/javadiscord/javabot/systems/help/commands/CloseCommand.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
11
package net.javadiscord.javabot.systems.help.commands;
22

3-
import java.util.concurrent.ScheduledExecutorService;
4-
53
import net.dv8tion.jda.api.interactions.commands.OptionType;
64
import net.dv8tion.jda.api.interactions.commands.build.Commands;
75
import net.javadiscord.javabot.data.config.BotConfig;
86
import net.javadiscord.javabot.data.h2db.DbActions;
9-
import net.javadiscord.javabot.systems.help.HelpExperienceService;
107
import net.javadiscord.javabot.systems.help.dao.HelpAccountRepository;
118
import net.javadiscord.javabot.systems.help.dao.HelpTransactionRepository;
129

1310
/**
1411
* A simple command that can be used inside reserved help channels to immediately unreserve them,
1512
* instead of waiting for a timeout.
16-
* An alias to /unreserve
13+
* An alias to /unreserve.
1714
*/
1815
public class CloseCommand extends UnreserveCommand {
1916

2017
/**
2118
* The constructor of this class, which sets the corresponding
2219
* {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
23-
* @param asyncPool The thread pool for asynchronous operations
2420
* @param botConfig The main configuration of the bot
2521
* @param dbActions A utility object providing various operations on the main database
26-
* @param helpExperienceService Service object that handles Help Experience Transactions.
2722
* @param helpTransactionRepository Dao object that represents the HELP_TRANSACTION SQL Table.
2823
* @param helpAccountRepository Dao object that represents the HELP_ACCOUNT SQL Table.
2924
*/
30-
public CloseCommand(BotConfig botConfig, ScheduledExecutorService asyncPool, DbActions dbActions, HelpExperienceService helpExperienceService, HelpTransactionRepository helpTransactionRepository, HelpAccountRepository helpAccountRepository) {
31-
super(botConfig, asyncPool, dbActions, helpExperienceService, helpTransactionRepository, helpAccountRepository);
25+
public CloseCommand(BotConfig botConfig, DbActions dbActions, HelpTransactionRepository helpTransactionRepository, HelpAccountRepository helpAccountRepository) {
26+
super(botConfig, dbActions, helpTransactionRepository, helpAccountRepository);
3227
setCommandData(
3328
Commands.slash("close", "Unreserves this help channel so that others can use it.")
3429
.setGuildOnly(true).addOption(OptionType.STRING, "reason",

src/main/java/net/javadiscord/javabot/systems/help/commands/HelpCommand.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand;
44
import net.dv8tion.jda.api.interactions.commands.build.Commands;
5-
import net.javadiscord.javabot.data.config.BotConfig;
65

76
/**
87
* Represents the `/help` command. This holds commands related to the help system.
98
*/
109
public class HelpCommand extends SlashCommand {
1110
/**
1211
* The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
13-
* @param botConfig The main configuration of the bot
1412
* @param helpAccountSubcommand /help account
1513
* @param helpPingSubcommand /help ping
1614
* @param helpGuidelinesSubcommand /help guidelines
1715
*/
18-
public HelpCommand(BotConfig botConfig, HelpAccountSubcommand helpAccountSubcommand, HelpPingSubcommand helpPingSubcommand, HelpGuidelinesSubcommand helpGuidelinesSubcommand) {
16+
public HelpCommand(HelpAccountSubcommand helpAccountSubcommand, HelpPingSubcommand helpPingSubcommand, HelpGuidelinesSubcommand helpGuidelinesSubcommand) {
1917
setCommandData(Commands.slash("help", "Commands related to the help system.")
2018
.setGuildOnly(true)
2119
);

src/main/java/net/javadiscord/javabot/systems/help/commands/HelpPingSubcommand.java

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
import net.javadiscord.javabot.data.config.BotConfig;
1111
import net.javadiscord.javabot.data.config.GuildConfig;
1212
import net.javadiscord.javabot.data.config.guild.HelpConfig;
13-
import net.javadiscord.javabot.data.h2db.DbActions;
14-
import net.javadiscord.javabot.systems.help.HelpChannelManager;
15-
import net.javadiscord.javabot.systems.help.HelpExperienceService;
16-
import net.javadiscord.javabot.systems.help.model.ChannelReservation;
1713
import net.javadiscord.javabot.util.Pair;
1814
import net.javadiscord.javabot.util.Responses;
1915
import org.jetbrains.annotations.NotNull;
@@ -28,29 +24,21 @@
2824
* helpers.
2925
*/
3026
public class HelpPingSubcommand extends SlashCommand.Subcommand {
31-
private static final String WRONG_CHANNEL_MSG = "This command can only be used in **reserved help channels** OR **help forum posts.**.";
27+
private static final String WRONG_CHANNEL_MSG = "This command can only be used in **help forum posts.**.";
3228
private static final long CACHE_CLEANUP_DELAY = 60L;
3329

3430
private final Map<Long, Pair<Long, Guild>> lastPingTimes;
3531
private final BotConfig botConfig;
36-
private final DbActions dbActions;
37-
private final ScheduledExecutorService asyncPool;
38-
private final HelpExperienceService helpExperienceService;
3932

4033
/**
4134
* Constructor that initializes and handles the cooldown map.
4235
* @param asyncPool The thread pool for asynchronous operations
4336
* @param botConfig The main configuration of the bot
44-
* @param helpExperienceService Service object that handles Help Experience Transactions.
45-
* @param dbActions A service object responsible for various operations on the main database
4637
*/
47-
public HelpPingSubcommand(BotConfig botConfig, ScheduledExecutorService asyncPool, HelpExperienceService helpExperienceService, DbActions dbActions) {
38+
public HelpPingSubcommand(BotConfig botConfig, ScheduledExecutorService asyncPool) {
4839
setCommandData(new SubcommandData("ping", "Notify those with the help-ping role that your question is urgent."));
4940
lastPingTimes = new ConcurrentHashMap<>();
5041
this.botConfig = botConfig;
51-
this.dbActions = dbActions;
52-
this.asyncPool=asyncPool;
53-
this.helpExperienceService = helpExperienceService;
5442
asyncPool.scheduleWithFixedDelay(this::cleanTimeoutCache, CACHE_CLEANUP_DELAY, CACHE_CLEANUP_DELAY, TimeUnit.SECONDS);
5543
}
5644

@@ -62,14 +50,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
6250
return;
6351
}
6452
GuildConfig config = botConfig.get(guild);
65-
if (event.getChannelType() == ChannelType.TEXT) {
66-
handleTextBasedHelpPing(event, config);
67-
} else if (event.getChannelType() == ChannelType.GUILD_PUBLIC_THREAD) {
68-
handleForumBasedHelpPing(event, config, event.getChannel().asThreadChannel());
69-
}
70-
}
71-
72-
private void handleForumBasedHelpPing(@NotNull SlashCommandInteractionEvent event, @NotNull GuildConfig config, @NotNull ThreadChannel post) {
53+
ThreadChannel post = event.getChannel().asThreadChannel();
7354
if (post.getParentChannel().getType() != ChannelType.FORUM ||
7455
post.getParentChannel().getIdLong() != config.getHelpForumConfig().getHelpForumChannelId()
7556
) {
@@ -98,65 +79,12 @@ private void handleForumBasedHelpPing(@NotNull SlashCommandInteractionEvent even
9879
}
9980
}
10081

101-
private void handleTextBasedHelpPing(@NotNull SlashCommandInteractionEvent event, @NotNull GuildConfig config) {
102-
HelpChannelManager channelManager = new HelpChannelManager(botConfig, event.getGuild(), dbActions, asyncPool, helpExperienceService);
103-
if (channelManager.isReserved(event.getChannel().asTextChannel())) {
104-
Optional<ChannelReservation> optionalReservation = channelManager.getReservationForChannel(event.getChannel().getIdLong());
105-
if (optionalReservation.isEmpty()) {
106-
Responses.warning(event, "Could not fetch the channel reservation.").queue();
107-
return;
108-
}
109-
ChannelReservation reservation = optionalReservation.get();
110-
Member member = event.getMember();
111-
if (member == null) {
112-
Responses.warning(event, "No member information was available for this event.").queue();
113-
return;
114-
}
115-
if (isHelpPingForbiddenForMember(reservation, member, config)) {
116-
Responses.warning(event, "Sorry, but only the person who reserved this channel, or staff and helpers, may use this command.").queue();
117-
return;
118-
}
119-
if (isHelpPingTimeoutElapsed(member.getIdLong(), config)) {
120-
lastPingTimes.put(event.getMember().getIdLong(), new Pair<>(System.currentTimeMillis(), config.getGuild()));
121-
Role role = channelManager.getConfig().getHelpPingRole();
122-
event.getChannel().sendMessage(role.getAsMention())
123-
.setAllowedMentions(EnumSet.of(Message.MentionType.ROLE))
124-
.setEmbeds(buildAuthorEmbed(event.getUser()))
125-
.queue();
126-
event.replyFormat("Successfully pinged " + role.getAsMention()).setEphemeral(true).queue();
127-
} else {
128-
Responses.warning(event, "Sorry, but you can only use this command occasionally. Please try again later.").queue();
129-
}
130-
} else {
131-
Responses.warning(event, WRONG_CHANNEL_MSG).queue();
132-
}
133-
}
134-
13582
private @NotNull MessageEmbed buildAuthorEmbed(@NotNull User author) {
13683
return new EmbedBuilder()
13784
.setTitle("Requested by " + author.getAsTag())
13885
.build();
13986
}
14087

141-
/**
142-
* Determines if a user is forbidden from sending a help-ping command due
143-
* to their status in the server.
144-
*
145-
* @param reservation The channel reservation for the channel they're
146-
* trying to send the command in.
147-
* @param member The member.
148-
* @param config The guild config.
149-
* @return True if the user is forbidden from sending the command.
150-
*/
151-
private boolean isHelpPingForbiddenForMember(@NotNull ChannelReservation reservation, @NotNull Member member, @NotNull GuildConfig config) {
152-
Set<Role> allowedRoles = Set.of(config.getModerationConfig().getStaffRole(), config.getHelpConfig().getHelperRole());
153-
return !(
154-
reservation.getUserId() == member.getUser().getIdLong() ||
155-
member.getRoles().stream().anyMatch(allowedRoles::contains) ||
156-
member.isOwner()
157-
);
158-
}
159-
16088
/**
16189
* Determines if a user is forbidden from sending a help-ping command due
16290
* to their status in the server.
Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
package net.javadiscord.javabot.systems.help.commands;
22

3-
import java.util.concurrent.ScheduledExecutorService;
4-
53
import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand;
6-
import net.dv8tion.jda.api.entities.User;
74
import net.dv8tion.jda.api.entities.channel.ChannelType;
8-
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
95
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
106
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
117
import net.dv8tion.jda.api.interactions.commands.CommandInteraction;
128
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
139
import net.dv8tion.jda.api.interactions.commands.OptionType;
1410
import net.dv8tion.jda.api.interactions.commands.build.Commands;
1511
import net.javadiscord.javabot.data.config.BotConfig;
16-
import net.javadiscord.javabot.data.config.guild.HelpConfig;
1712
import net.javadiscord.javabot.data.h2db.DbActions;
18-
import net.javadiscord.javabot.systems.help.HelpChannelManager;
19-
import net.javadiscord.javabot.systems.help.HelpExperienceService;
2013
import net.javadiscord.javabot.systems.help.dao.HelpAccountRepository;
2114
import net.javadiscord.javabot.systems.help.dao.HelpTransactionRepository;
2215
import net.javadiscord.javabot.systems.help.forum.ForumHelpManager;
@@ -29,26 +22,20 @@
2922
*/
3023
public 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

Comments
 (0)