Skip to content

Commit 52faaad

Browse files
Merged HelpForumConfig with HelpConfig
1 parent 218e30e commit 52faaad

File tree

8 files changed

+29
-141
lines changed

8 files changed

+29
-141
lines changed

src/main/java/net/javadiscord/javabot/data/config/GuildConfig.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class GuildConfig {
3131
private transient Path file;
3232

3333
private HelpConfig helpConfig;
34-
private HelpForumConfig helpForumConfig;
3534
private ModerationConfig moderationConfig;
3635
private QOTWConfig qotwConfig;
3736
private MetricsConfig metricsConfig;
@@ -49,7 +48,6 @@ public GuildConfig(Guild guild, Path file) {
4948
this.file = file;
5049
// Initialize all config items.
5150
this.helpConfig = new HelpConfig();
52-
this.helpForumConfig = new HelpForumConfig();
5351
this.moderationConfig = new ModerationConfig();
5452
this.qotwConfig = new QOTWConfig();
5553
this.metricsConfig = new MetricsConfig();
@@ -97,8 +95,6 @@ private void setGuild(Guild guild) {
9795
this.guild = guild;
9896
if (this.helpConfig == null) this.helpConfig = new HelpConfig();
9997
this.helpConfig.setGuildConfig(this);
100-
if (this.helpForumConfig == null) this.helpForumConfig = new HelpForumConfig();
101-
this.helpForumConfig.setGuildConfig(this);
10298
if (this.moderationConfig == null) this.moderationConfig = new ModerationConfig();
10399
this.moderationConfig.setGuildConfig(this);
104100
if (this.qotwConfig == null) this.qotwConfig = new QOTWConfig();

src/main/java/net/javadiscord/javabot/data/config/guild/HelpConfig.java

Lines changed: 17 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import lombok.Data;
44
import lombok.EqualsAndHashCode;
55
import net.dv8tion.jda.api.entities.Role;
6-
import net.dv8tion.jda.api.entities.channel.concrete.Category;
6+
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
77
import net.javadiscord.javabot.data.config.GuildConfigItem;
8-
import net.javadiscord.javabot.systems.help.naming_strategies.*;
98

10-
import java.util.List;
119
import java.util.Map;
1210

1311
/**
@@ -21,22 +19,13 @@ public class HelpConfig extends GuildConfigItem {
2119
*/
2220
private Map<String, Long> helpOverviewMessageIds = Map.of();
2321

22+
private long helpForumChannelId = 0;
23+
2424
/**
2525
* The id of the channel category that contains all open channels.
2626
*/
2727
private long openCategoryId;
2828

29-
/**
30-
* The id of the channel category that contains all reserved channels.
31-
*/
32-
private long reservedCategoryId;
33-
34-
/**
35-
* The id of the channel category where dormant channels are put when they
36-
* aren't needed in the open category (due to preferred channel count).
37-
*/
38-
private long dormantCategoryId;
39-
4029
/**
4130
* The id of the helper role.
4231
*/
@@ -47,79 +36,41 @@ public class HelpConfig extends GuildConfigItem {
4736
*/
4837
private long helpPingRoleId;
4938

50-
/**
51-
* The strategy to use when naming help channels. This is only used when
52-
* {@link HelpConfig#recycleChannels} is set to false.
53-
*/
54-
private String channelNamingStrategy = "animal";
55-
56-
/**
57-
* If true, the system will manage a fixed set of help channels which are
58-
* created in advance. If false, the system will create and remove channels
59-
* as needed to maintain the {@link HelpConfig#preferredOpenChannelCount}.
60-
* Note that if this is true, the preferred open channel count is ignored.
61-
*/
62-
private boolean recycleChannels = false;
63-
64-
/**
65-
* The string which is shown as the 'topic' for open channels.
66-
*/
67-
private String openChannelTopic = "Ask your question here!";
68-
69-
/**
70-
* The message that's sent in a recycled help channel to tell users that it
71-
* is now open for someone to ask a question.
72-
*/
73-
private String reopenedChannelMessage = "`✅` **This channel is now available!**\n> This channel is no longer reserved. Feel free to ask your question here!";
74-
7539
/**
7640
* The message that's sent as soon as a user asks a question in an open help
7741
* channel. This is only sent if it's not null.
7842
*/
79-
private String reservedChannelMessage = "`⌛` **This channel has been reserved for your question.**\n> Please use `/unreserve` when you\u0027re finished.";
43+
private String reservedChannelMessageTemplate = "`⌛` **This channel has been reserved for your question.**\n> Please use `/close` when you're finished.";
8044

8145
/**
82-
* The message that's sent in a recycled help channel to tell users that it
46+
* The message that's sent in a post to tell users that it
8347
* is now marked as dormant and no more messages can be sent.
8448
*/
85-
private String dormantChannelMessage = "`\uD83D\uDCA4` **Channel marked as dormant**\n> It is no longer possible to send messages in this channel until it becomes available again.\n> If your question was not answered yet, feel free to claim a new available help channel.";
49+
private String dormantChannelMessageTemplate = "`\uD83D\uDCA4` **Channel marked as dormant**\n> This post has been inactive for over %s minutes. It is no longer possible to send messages in this channel.\n> If your question was not answered yet, feel free to create a new post.";
8650

8751
/**
88-
* The number of open help channels to maintain. If fewer than this many
89-
* open channels exist, the system will try to create more.
52+
* The message that's sent when a user unreserved a channel where other users
53+
* participated in.
9054
*/
91-
private int preferredOpenChannelCount = 3;
55+
private String helpThanksMessageTemplate = "Before your post will be closed, would you like to express your gratitude to any of the people who helped you? When you're done, click **I'm done here. Close this post!**.";
9256

9357
/**
94-
* A list of successive timeouts (in minutes) to use when checking to see if
95-
* a help channel is still active. The bot waits X minutes since the last
96-
* human message before sending an activity check, and waits
58+
* The number of open help channels to maintain. If fewer than this many
59+
* open channels exist, the system will try to create more.
9760
*/
98-
private List<Integer> inactivityTimeouts = List.of(30, 60, 120, 180);
61+
private int preferredOpenChannelCount = 3;
9962

10063
/**
10164
* The number of minutes of inactivity before a channel is considered inactive.
10265
*/
103-
private int inactivityTimeoutMinutes = 30;
104-
105-
/**
106-
* The number of minutes to wait before closing an inactive channel. An
107-
* inactive channel is one in which the most recent message is an unanswered
108-
* activity check that was sent by this bot.
109-
*/
110-
private int removeInactiveTimeoutMinutes = 60;
66+
private int inactivityTimeoutMinutes = 300;
11167

11268
/**
11369
* The number of minutes to wait before closing a channel waiting for a response
11470
* to a thanks question.
11571
*/
11672
private int removeThanksTimeoutMinutes = 15;
11773

118-
/**
119-
* The number of seconds to wait between each help channel update check.
120-
*/
121-
private long updateIntervalSeconds = 60;
122-
12374
/**
12475
* The number of channels which can be reserved by a single user at any time.
12576
*/
@@ -176,33 +127,15 @@ public class HelpConfig extends GuildConfigItem {
176127
*/
177128
private Map<Long, Double> experienceRoles = Map.of(0L, 0.0);
178129

179-
public Category getOpenChannelCategory() {
180-
return getGuild().getCategoryById(this.openCategoryId);
181-
}
182-
183-
public Category getReservedChannelCategory() {
184-
return getGuild().getCategoryById(this.reservedCategoryId);
185-
}
186-
187-
public Category getDormantChannelCategory() {
188-
return getGuild().getCategoryById(this.dormantCategoryId);
130+
public ForumChannel getHelpForumChannel() {
131+
return getGuild().getForumChannelById(helpForumChannelId);
189132
}
190133

191134
public Role getHelperRole() {
192-
return this.getGuild().getRoleById(this.helperRoleId);
135+
return getGuild().getRoleById(helperRoleId);
193136
}
194137

195138
public Role getHelpPingRole() {
196-
return this.getGuild().getRoleById(this.helpPingRoleId);
197-
}
198-
199-
public ChannelNamingStrategy getChannelNamingStrategy() {
200-
return switch (this.channelNamingStrategy) {
201-
case "alphabet" -> new AlphabetNamingStrategy();
202-
case "greek" -> new GreekAlphabetNamingStrategy();
203-
case "animal" -> new AnimalNamingStrategy();
204-
case "coffee" -> new CoffeeNamingStrategy();
205-
default -> throw new IllegalArgumentException("Invalid channel naming strategy.");
206-
};
139+
return getGuild().getRoleById(helpPingRoleId);
207140
}
208141
}

src/main/java/net/javadiscord/javabot/data/config/guild/HelpForumConfig.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/main/java/net/javadiscord/javabot/systems/help/HelpChannelUpdater.java renamed to src/main/java/net/javadiscord/javabot/systems/help/HelpForumUpdater.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
88
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
99
import net.javadiscord.javabot.data.config.BotConfig;
10-
import net.javadiscord.javabot.data.config.GuildConfig;
1110
import net.javadiscord.javabot.data.config.guild.HelpConfig;
1211
import org.jetbrains.annotations.NotNull;
1312
import org.springframework.scheduling.annotation.Scheduled;
@@ -21,7 +20,7 @@
2120
@Slf4j
2221
@Service
2322
@RequiredArgsConstructor
24-
public class HelpChannelUpdater {
23+
public class HelpForumUpdater {
2524
private final JDA jda;
2625
private final BotConfig botConfig;
2726

@@ -32,21 +31,21 @@ public class HelpChannelUpdater {
3231
public void execute() {
3332
for (Guild guild : jda.getGuilds()) {
3433
log.info("Updating help channels in {}", guild.getName());
35-
GuildConfig config = botConfig.get(guild);
36-
ForumChannel forum = config.getHelpForumConfig().getHelpForumChannel();
34+
HelpConfig config = botConfig.get(guild).getHelpConfig();
35+
ForumChannel forum = config.getHelpForumChannel();
3736
if (forum != null) {
3837
for (ThreadChannel post : forum.getThreadChannels()) {
3938
if (post.isArchived() || post.isLocked()) continue;
40-
checkForumPost(post, config.getHelpConfig());
39+
checkForumPost(post, config);
4140
}
4241
}
4342
}
4443
}
4544

4645
private void checkForumPost(@NotNull ThreadChannel post, HelpConfig config) {
4746
post.retrieveMessageById(post.getLatestMessageId()).queue(latest -> {
48-
if (latest.getTimeCreated().plusMinutes(300).isBefore(OffsetDateTime.now())) {
49-
post.sendMessage(config.getDormantChannelMessage()).queue(s ->
47+
if (latest.getTimeCreated().plusMinutes(config.getInactivityTimeoutMinutes()).isBefore(OffsetDateTime.now())) {
48+
post.sendMessage(config.getDormantChannelMessageTemplate().formatted(config.getInactivityTimeoutMinutes())).queue(s ->
5049
post.getManager().setLocked(true).setArchived(true).queue());
5150
}
5251
});

src/main/java/net/javadiscord/javabot/systems/help/HelpListener.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import net.javadiscord.javabot.annotations.AutoDetectableComponentHandler;
2020
import net.javadiscord.javabot.data.config.BotConfig;
2121
import net.javadiscord.javabot.data.config.guild.HelpConfig;
22-
import net.javadiscord.javabot.data.config.guild.HelpForumConfig;
2322
import net.javadiscord.javabot.data.h2db.DbActions;
2423
import net.javadiscord.javabot.systems.help.dao.HelpAccountRepository;
2524
import net.javadiscord.javabot.systems.help.dao.HelpTransactionRepository;
@@ -83,7 +82,7 @@ public void onChannelCreate(@NotNull ChannelCreateEvent event) {
8382
if (event.getGuild() == null || isInvalidForumPost(event.getChannel())) {
8483
return;
8584
}
86-
HelpForumConfig config = botConfig.get(event.getGuild()).getHelpForumConfig();
85+
HelpConfig config = botConfig.get(event.getGuild()).getHelpConfig();
8786
ThreadChannel post = event.getChannel().asThreadChannel();
8887
if (isInvalidHelpForumChannel(post.getParentChannel().asForumChannel())) {
8988
return;
@@ -96,7 +95,7 @@ public void onChannelCreate(@NotNull ChannelCreateEvent event) {
9695
// send /close reminder (if enabled)
9796
UserPreference preference = userPreferenceService.getOrCreate(post.getOwnerIdLong(), Preference.FORUM_CLOSE_REMINDER);
9897
if (Boolean.parseBoolean(preference.getState())) {
99-
post.sendMessageFormat(config.getCloseReminderText(), UserSnowflake.fromId(post.getOwnerIdLong()).getAsMention()).queue();
98+
post.sendMessageFormat(config.getDormantChannelMessageTemplate(), UserSnowflake.fromId(post.getOwnerIdLong()).getAsMention()).queue();
10099
}
101100
});
102101
}
@@ -125,7 +124,7 @@ private boolean isInvalidForumPost(@NotNull Channel channel) {
125124
}
126125

127126
private boolean isInvalidHelpForumChannel(@NotNull ForumChannel forum) {
128-
HelpForumConfig config = botConfig.get(forum.getGuild()).getHelpForumConfig();
127+
HelpConfig config = botConfig.get(forum.getGuild()).getHelpConfig();
129128
return config.getHelpForumChannelId() != forum.getIdLong();
130129
}
131130

src/main/java/net/javadiscord/javabot/systems/help/HelpManager.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
1818
import net.javadiscord.javabot.data.config.BotConfig;
1919
import net.javadiscord.javabot.data.config.guild.HelpConfig;
20-
import net.javadiscord.javabot.data.config.guild.HelpForumConfig;
2120
import net.javadiscord.javabot.data.h2db.DbActions;
2221
import net.javadiscord.javabot.systems.help.dao.HelpAccountRepository;
2322
import net.javadiscord.javabot.systems.help.dao.HelpTransactionRepository;
@@ -72,7 +71,7 @@ public class HelpManager {
7271
* @return The {@link ReplyCallbackAction}.
7372
*/
7473
public ReplyCallbackAction replyHelpThanks(IReplyCallback callback, @NotNull List<Member> helpers) {
75-
HelpForumConfig config = botConfig.get(callback.getGuild()).getHelpForumConfig();
74+
HelpConfig config = botConfig.get(callback.getGuild()).getHelpConfig();
7675
List<ItemComponent> helperThanksButtons = new ArrayList<>(20);
7776
for (Member helper : helpers.subList(0, Math.min(helpers.size(), 20))) {
7877
helperThanksButtons.add(Button.success(ComponentIdBuilder.build(HELP_THANKS_IDENTIFIER, postThread.getId(), helper.getId()), helper.getEffectiveName())
@@ -86,7 +85,7 @@ public ReplyCallbackAction replyHelpThanks(IReplyCallback callback, @NotNull Lis
8685
List<ActionRow> rows = new ArrayList<>();
8786
rows.add(controlsRow);
8887
rows.addAll(MessageActionUtils.toActionRows(helperThanksButtons));
89-
return callback.reply(config.getHelpThanksText())
88+
return callback.reply(config.getHelpThanksMessageTemplate())
9089
.setComponents(rows);
9190
}
9291

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,32 @@
11
package net.javadiscord.javabot.systems.help.commands;
22

33
import net.dv8tion.jda.api.EmbedBuilder;
4-
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
54
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
65
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
76
import net.javadiscord.javabot.data.config.BotConfig;
8-
import net.javadiscord.javabot.data.config.guild.HelpConfig;
97
import net.javadiscord.javabot.util.Responses;
108
import net.javadiscord.javabot.util.StringResourceCache;
119
import org.jetbrains.annotations.NotNull;
1210
import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand;
1311

14-
import java.util.stream.Collectors;
15-
1612
/**
1713
* Shows the server's help-guidelines.
1814
*/
1915
public class HelpGuidelinesSubcommand extends SlashCommand.Subcommand {
20-
private final BotConfig botConfig;
21-
2216
/**
2317
* The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
2418
* @param botConfig The main configuration of the bot
2519
*/
2620
public HelpGuidelinesSubcommand(BotConfig botConfig) {
27-
this.botConfig = botConfig;
2821
setCommandData(new SubcommandData("guidelines", "Show the server's help guidelines in a simple format."));
2922
}
3023

3124
@Override
3225
public void execute(@NotNull SlashCommandInteractionEvent event) {
33-
HelpConfig config = botConfig.get(event.getGuild()).getHelpConfig();
34-
String channels = "N/A";
35-
if (config.getOpenChannelCategory() != null) {
36-
channels = config.getOpenChannelCategory().getChannels()
37-
.stream()
38-
.map(GuildChannel::getAsMention)
39-
.collect(Collectors.joining("\n"));
40-
}
4126
event.replyEmbeds(new EmbedBuilder()
4227
.setTitle("Help Guidelines")
4328
.setColor(Responses.Type.DEFAULT.getColor())
4429
.setDescription(StringResourceCache.load("/help_guidelines/guidelines_text.txt"))
45-
.addField("Available Help Channels", channels, false)
4630
.setImage(StringResourceCache.load("/help_guidelines/guidelines_image_url.txt"))
4731
.build()
4832
).queue();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
6060
GuildConfig config = botConfig.get(guild);
6161
ThreadChannel post = event.getChannel().asThreadChannel();
6262
if (post.getParentChannel().getType() != ChannelType.FORUM ||
63-
post.getParentChannel().getIdLong() != config.getHelpForumConfig().getHelpForumChannelId()
63+
post.getParentChannel().getIdLong() != config.getHelpConfig().getHelpForumChannelId()
6464
) {
6565
Responses.error(event, WRONG_CHANNEL_MSG).queue();
6666
return;

0 commit comments

Comments
 (0)