Skip to content

Commit 8a53ae9

Browse files
Revert "Merge branch 'main' into springify"
This reverts commit 817c387, reversing changes made to dd29b6a.
1 parent 817c387 commit 8a53ae9

File tree

10 files changed

+36
-197
lines changed

10 files changed

+36
-197
lines changed

build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ repositories {
2626
dependencies {
2727
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.0")
2828
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.0")
29-
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
30-
compileOnly("org.jetbrains:annotations:23.0.0")
3129

3230
// DIH4JDA (Interaction Framework) & JDA
3331
implementation("com.github.DynxstyGIT:DIH4JDA:c8f7928efc")
34-
implementation("com.github.DV8FromTheWorld:JDA:86af73d377") {
32+
implementation("net.dv8tion:JDA:5.0.0-alpha.20") {
3533
exclude(module = "opus-java")
3634
}
3735

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
@EqualsAndHashCode(callSuper = true)
1414
public class HelpForumConfig extends GuildConfigItem {
1515
private long helpForumChannelId = 0;
16-
private String closeReminderText = "Hey, %s!\nPlease remember to `/close` this post once your question has been answered!";
17-
private String helpThanksText = "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!**.";
1816

1917
public ForumChannel getHelpForumChannel() {
2018
return getGuild().getForumChannelById(helpForumChannelId);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ public void reserve(TextChannel channel, User reservingUser, Message message) th
173173
TextChannel targetChannel = dormantChannels.get(0);
174174
targetChannel.getManager().setParent(targetCategory).sync(targetCategory).queue();
175175
targetChannel.sendMessage(config.getReopenedChannelMessage()).queue();
176+
} else {
177+
logChannel.sendMessage("Warning: No dormant channels were available to replenish an open channel that was just reserved.").queue();
176178
}
177179
} else {
178180
this.openNew();

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

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import net.dv8tion.jda.api.JDA;
66
import net.dv8tion.jda.api.entities.*;
77
import net.dv8tion.jda.api.entities.channel.concrete.Category;
8-
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
98
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
109
import net.dv8tion.jda.api.entities.emoji.Emoji;
11-
import net.dv8tion.jda.api.interactions.components.ActionRow;
1210
import net.dv8tion.jda.api.interactions.components.buttons.Button;
1311
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
1412
import net.dv8tion.jda.api.requests.RestAction;
@@ -18,7 +16,6 @@
1816
import net.javadiscord.javabot.data.config.BotConfig;
1917
import net.javadiscord.javabot.data.config.guild.HelpConfig;
2018
import net.javadiscord.javabot.data.h2db.DbActions;
21-
import net.javadiscord.javabot.data.config.guild.HelpForumConfig;
2219
import net.javadiscord.javabot.systems.help.model.ChannelReservation;
2320
import net.javadiscord.javabot.util.ExceptionLogger;
2421
import net.javadiscord.javabot.util.Responses;
@@ -382,27 +379,20 @@ private RestAction<?> semanticMessageCheck(TextChannel channel, User owner, List
382379
}
383380

384381
private void updateHelpOverview() {
385-
HelpForumConfig forumConfig = Bot.getConfig().get(config.getGuild()).getHelpForumConfig();
386-
config.getHelpOverviewMessageIds().forEach((channelId, messageId) -> {
387-
TextChannel channel = config.getGuild().getTextChannelById(channelId);
382+
helpConfig.getHelpOverviewMessageIds().forEach((channelId, messageId) -> {
383+
TextChannel channel = helpConfig.getGuild().getTextChannelById(channelId);
388384
if (channel == null) {
389385
log.error("Could not find Help Overview Channel with id '{}'", channelId);
390386
return;
391387
}
392388
List<TextChannel> availableChannels = helpConfig.getOpenChannelCategory().getTextChannels();
393389
List<Button> buttons = new ArrayList<>(2);
394390
if (!availableChannels.isEmpty()) {
395-
buttons.add(Button.link(availableChannels.get(0).getJumpUrl(), "Show me an Available Help Channel!"));
391+
buttons.add(Button.link(availableChannels.get(0).getJumpUrl(), "Show me an available Help Channel!"));
396392
}
397393
buttons.add(Button.link(StringResourceCache.load("/help_overview/overview_image_url.txt"), "How does this work?"));
398394
channel.retrieveMessageById(messageId).queue(
399-
m -> m.editMessageEmbeds(buildHelpOverviewEmbed()).setComponents(
400-
ActionRow.of(
401-
// Temporary Forum Channel Upsell
402-
Button.link(forumConfig.getHelpForumChannel().getJumpUrl(), "Try our new Help Forum!"),
403-
Button.link("https://discord.com/blog/forum-channels-space-for-organized-conversation", "What are Forums?")
404-
),
405-
ActionRow.of(buttons)).queue(),
395+
m -> m.editMessageEmbeds(buildHelpOverviewEmbed()).setActionRow(buttons).queue(),
406396
err -> channel.sendMessageEmbeds(buildHelpOverviewEmbed()).queue(m -> {
407397
helpConfig.getHelpOverviewMessageIds().put(channelId, m.getIdLong());
408398
botConfig.flush();
@@ -436,14 +426,10 @@ private void updateHelpOverview() {
436426
e -> ExceptionLogger.capture(e, getClass().getSimpleName())
437427
);
438428
}
439-
ForumChannel forum = Bot.getConfig().get(config.getGuild()).getHelpForumConfig().getHelpForumChannel();
440429
EmbedBuilder builder = new EmbedBuilder()
441430
.setTitle("Help Overview")
442431
.setColor(Responses.Type.DEFAULT.getColor())
443-
.setDescription(availableHelpChannels.isEmpty() ?
444-
String.format("There are no help channels available to claim.%nHow about using our new **[Help Forum](%s)** (%s) then?",
445-
forum.getJumpUrl(), forum.getAsMention()) :
446-
availableHelpChannels + " are __**available**__ to claim!")
432+
.setDescription(availableHelpChannels + " are __**available**__ to claim!")
447433
.setFooter("Last refreshed: ")
448434
.setTimestamp(Instant.now());
449435
if (!reservedHelpChannels.isEmpty()) {

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

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
44
import net.dv8tion.jda.api.EmbedBuilder;
55
import net.dv8tion.jda.api.entities.*;
6-
import net.dv8tion.jda.api.entities.channel.ChannelType;
7-
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
86
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
97
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
108
import net.javadiscord.javabot.data.config.BotConfig;
@@ -28,7 +26,7 @@
2826
* helpers.
2927
*/
3028
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.**.";
29+
private static final String WRONG_CHANNEL_MSG = "This command can only be used in **reserved help channels**.";
3230
private static final long CACHE_CLEANUP_DELAY = 60L;
3331

3432
private final Map<Long, Pair<Long, Guild>> lastPingTimes;
@@ -61,45 +59,8 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
6159
Responses.warning(event, WRONG_CHANNEL_MSG).queue();
6260
return;
6361
}
64-
GuildConfig config = Bot.getConfig().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) {
73-
if (post.getParentChannel().getType() != ChannelType.FORUM ||
74-
post.getParentChannel().getIdLong() != config.getHelpForumConfig().getHelpForumChannelId()
75-
) {
76-
Responses.error(event, WRONG_CHANNEL_MSG).queue();
77-
return;
78-
}
79-
Member member = event.getMember();
80-
if (member == null) {
81-
Responses.warning(event, "No member information was available for this event.").queue();
82-
return;
83-
}
84-
if (isHelpPingForbiddenForMember(post.getOwnerIdLong(), member, config)) {
85-
Responses.warning(event, "Sorry, but only the person who reserved this channel, or staff and helpers, may use this command.").queue();
86-
return;
87-
}
88-
if (isHelpPingTimeoutElapsed(member.getIdLong(), config)) {
89-
lastPingTimes.put(event.getMember().getIdLong(), new Pair<>(System.currentTimeMillis(), config.getGuild()));
90-
Role role = config.getHelpConfig().getHelpPingRole();
91-
event.getChannel().sendMessage(role.getAsMention())
92-
.setAllowedMentions(EnumSet.of(Message.MentionType.ROLE))
93-
.setEmbeds(buildAuthorEmbed(event.getUser()))
94-
.queue();
95-
event.replyFormat("Successfully pinged " + role.getAsMention()).setEphemeral(true).queue();
96-
} else {
97-
Responses.warning(event, "Sorry, but you can only use this command occasionally. Please try again later.").queue();
98-
}
99-
}
100-
101-
private void handleTextBasedHelpPing(@NotNull SlashCommandInteractionEvent event, @NotNull GuildConfig config) {
102-
HelpChannelManager channelManager = new HelpChannelManager(config.getHelpConfig());
62+
GuildConfig config = botConfig.get(guild);
63+
HelpChannelManager channelManager=new HelpChannelManager(botConfig, guild, dbActions, asyncPool, helpExperienceService);
10364
if (channelManager.isReserved(event.getChannel().asTextChannel())) {
10465
Optional<ChannelReservation> optionalReservation = channelManager.getReservationForChannel(event.getChannel().getIdLong());
10566
if (optionalReservation.isEmpty()) {
@@ -117,7 +78,7 @@ private void handleTextBasedHelpPing(@NotNull SlashCommandInteractionEvent event
11778
return;
11879
}
11980
if (isHelpPingTimeoutElapsed(member.getIdLong(), config)) {
120-
lastPingTimes.put(event.getMember().getIdLong(), new Pair<>(System.currentTimeMillis(), config.getGuild()));
81+
lastPingTimes.put(event.getMember().getIdLong(), new Pair<>(System.currentTimeMillis(), guild));
12182
Role role = channelManager.getConfig().getHelpPingRole();
12283
event.getChannel().sendMessage(role.getAsMention())
12384
.setAllowedMentions(EnumSet.of(Message.MentionType.ROLE))
@@ -157,24 +118,6 @@ private boolean isHelpPingForbiddenForMember(@NotNull ChannelReservation reserva
157118
);
158119
}
159120

160-
/**
161-
* Determines if a user is forbidden from sending a help-ping command due
162-
* to their status in the server.
163-
*
164-
* @param postOwnerId The posts' owner id.
165-
* @param member The member.
166-
* @param config The guild config.
167-
* @return True if the user is forbidden from sending the command.
168-
*/
169-
private boolean isHelpPingForbiddenForMember(long postOwnerId, @NotNull Member member, @NotNull GuildConfig config) {
170-
Set<Role> allowedRoles = Set.of(config.getModerationConfig().getStaffRole(), config.getHelpConfig().getHelperRole());
171-
return !(
172-
postOwnerId == member.getUser().getIdLong() ||
173-
member.getRoles().stream().anyMatch(allowedRoles::contains) ||
174-
member.isOwner()
175-
);
176-
}
177-
178121
/**
179122
* Determines if the user's timeout has elapsed (or doesn't exist), which
180123
* implies that it's fine for the user to send the command.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ private void replyInvalidChannel(CommandInteraction interaction) {
107107
.queue();
108108
}
109109

110+
private boolean isForumEligibleToBeUnreserved(@NotNull SlashCommandInteractionEvent event, @NotNull ThreadChannel postThread) {
111+
return event.getUser().getIdLong() == postThread.getOwnerIdLong() || memberHasHelperRole(event) || memberHasStaffRole(event);
112+
}
113+
110114
private boolean isTextEligibleToBeUnreserved(SlashCommandInteractionEvent event, TextChannel channel, HelpConfig config, User owner) {
111115
return channelIsInReservedCategory(channel, config) &&
112116
(isUserWhoReservedChannel(event, owner) || memberHasHelperRole(event) || memberHasStaffRole(event));

src/main/java/net/javadiscord/javabot/systems/help/forum/ForumHelpListener.java

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,24 @@
44
import com.dynxsty.dih4jda.interactions.components.ButtonHandler;
55

66
import lombok.RequiredArgsConstructor;
7-
import net.dv8tion.jda.api.EmbedBuilder;
87
import net.dv8tion.jda.api.entities.Message;
9-
import net.dv8tion.jda.api.entities.UserSnowflake;
10-
import net.dv8tion.jda.api.entities.channel.Channel;
118
import net.dv8tion.jda.api.entities.channel.ChannelType;
129
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
1310
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
14-
import net.dv8tion.jda.api.events.channel.ChannelCreateEvent;
1511
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
1612
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
1713
import net.dv8tion.jda.api.hooks.ListenerAdapter;
18-
import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback;
1914
import net.dv8tion.jda.api.interactions.components.ActionComponent;
20-
import net.dv8tion.jda.api.interactions.components.ActionRow;
2115
import net.dv8tion.jda.api.interactions.components.buttons.Button;
2216
import net.javadiscord.javabot.data.config.BotConfig;
2317
import net.javadiscord.javabot.data.config.GuildConfig;
2418
import net.javadiscord.javabot.data.config.guild.HelpConfig;
2519
import net.javadiscord.javabot.data.h2db.DbActions;
26-
import net.javadiscord.javabot.Bot;
27-
import net.javadiscord.javabot.data.config.guild.HelpConfig;
28-
import net.javadiscord.javabot.data.config.guild.HelpForumConfig;
2920
import net.javadiscord.javabot.systems.help.HelpChannelManager;
3021
import net.javadiscord.javabot.systems.help.HelpExperienceService;
3122
import net.javadiscord.javabot.systems.help.dao.HelpAccountRepository;
3223
import net.javadiscord.javabot.systems.help.dao.HelpTransactionRepository;
3324
import net.javadiscord.javabot.systems.help.model.HelpTransactionMessage;
34-
import net.javadiscord.javabot.systems.user_preferences.UserPreferenceService;
35-
import net.javadiscord.javabot.systems.user_preferences.model.Preference;
36-
import net.javadiscord.javabot.systems.user_preferences.model.UserPreference;
3725
import net.javadiscord.javabot.util.ExceptionLogger;
3826
import net.javadiscord.javabot.util.Responses;
3927
import org.jetbrains.annotations.NotNull;
@@ -65,12 +53,19 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
6553
if (event.getMessage().getAuthor().isSystem() || event.getMessage().getAuthor().isBot()) {
6654
return;
6755
}
68-
// check for forum post
69-
if (isInvalidForumPost(event.getChannel())) {
56+
// check for guild & channel type
57+
if (!event.isFromGuild() || event.getChannelType() != ChannelType.GUILD_PUBLIC_THREAD) {
7058
return;
7159
}
60+
// get post & check parent channel
7261
ThreadChannel post = event.getChannel().asThreadChannel();
73-
if (isInvalidHelpForumChannel(post.getParentChannel().asForumChannel())) {
62+
if (post.getParentChannel().getType() != ChannelType.FORUM) {
63+
return;
64+
}
65+
ForumChannel forum = post.getParentChannel().asForumChannel();
66+
GuildConfig config = botConfig.get(event.getGuild());
67+
// check for channel id
68+
if (forum.getIdLong() != config.getHelpForumConfig().getHelpForumChannelId()) {
7469
return;
7570
}
7671
// cache messages
@@ -82,59 +77,20 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
8277
HELP_POST_MESSAGES.put(post.getIdLong(), messages);
8378
}
8479

85-
@Override
86-
public void onChannelCreate(@NotNull ChannelCreateEvent event) {
87-
if (event.getGuild() == null || isInvalidForumPost(event.getChannel())) {
88-
return;
89-
}
90-
HelpForumConfig config = Bot.getConfig().get(event.getGuild()).getHelpForumConfig();
91-
ThreadChannel post = event.getChannel().asThreadChannel();
92-
if (isInvalidHelpForumChannel(post.getParentChannel().asForumChannel())) {
93-
return;
94-
}
95-
// send post buttons
96-
post.sendMessageComponents(ActionRow.of(
97-
Button.primary(ComponentIdBuilder.build(ForumHelpManager.HELP_CLOSE_IDENTIFIER, post.getIdLong()), "Close Post"),
98-
Button.secondary(ComponentIdBuilder.build(ForumHelpManager.HELP_GUIDELINES_IDENTIFIER), "View Help Guidelines")
99-
)).queue(success -> {
100-
// send /close reminder (if enabled)
101-
UserPreferenceService service = new UserPreferenceService(Bot.getDataSource());
102-
UserPreference preference = service.getOrCreate(post.getOwnerIdLong(), Preference.FORUM_CLOSE_REMINDER);
103-
if (Boolean.parseBoolean(preference.getState())) {
104-
post.sendMessageFormat(config.getCloseReminderText(), UserSnowflake.fromId(post.getOwnerIdLong()).getAsMention()).queue();
105-
}
106-
});
107-
}
108-
10980
@Override
11081
public void handleButton(@NotNull ButtonInteractionEvent event, @NotNull Button button) {
11182
String[] id = ComponentIdBuilder.split(event.getComponentId());
112-
if (isInvalidForumPost(event.getChannel()) ||
113-
isInvalidHelpForumChannel(event.getChannel().asThreadChannel().getParentChannel().asForumChannel())
114-
) {
83+
if (event.getChannelType() != ChannelType.GUILD_PUBLIC_THREAD
84+
|| event.getChannel().asThreadChannel().getParentChannel().getType() != ChannelType.FORUM) {
11585
Responses.error(event, "This button may only be used inside help forum threads.").queue();
11686
return;
11787
}
11888
ForumHelpManager manager = new ForumHelpManager(event.getChannel().asThreadChannel(), dbActions, botConfig, dataSource, helpAccountRepository, helpTransactionRepository);
119-
ThreadChannel post = event.getChannel().asThreadChannel();
120-
ForumHelpManager manager = new ForumHelpManager(post);
12189
switch (id[0]) {
12290
case ForumHelpManager.HELP_THANKS_IDENTIFIER -> handleHelpThanksInteraction(event, manager, id);
123-
case ForumHelpManager.HELP_GUIDELINES_IDENTIFIER -> handleReplyGuidelines(event, post.getParentChannel().asForumChannel());
124-
case ForumHelpManager.HELP_CLOSE_IDENTIFIER -> handlePostClose(event, manager);
12591
}
12692
}
12793

128-
private boolean isInvalidForumPost(@NotNull Channel channel) {
129-
return channel.getType() != ChannelType.GUILD_PUBLIC_THREAD ||
130-
((ThreadChannel) channel).getParentChannel().getType() != ChannelType.FORUM;
131-
}
132-
133-
private boolean isInvalidHelpForumChannel(@NotNull ForumChannel forum) {
134-
HelpForumConfig config = Bot.getConfig().get(forum.getGuild()).getHelpForumConfig();
135-
return config.getHelpForumChannelId() != forum.getIdLong();
136-
}
137-
13894
private void handleHelpThanksInteraction(@NotNull ButtonInteractionEvent event, @NotNull ForumHelpManager manager, String @NotNull [] id) {
13995
ThreadChannel post = manager.getPostThread();
14096
HelpConfig config = botConfig.get(event.getGuild()).getHelpConfig();
@@ -166,21 +122,4 @@ private void handleHelpThanksInteraction(@NotNull ButtonInteractionEvent event,
166122
default -> event.editButton(event.getButton().asDisabled()).queue();
167123
}
168124
}
169-
170-
private void handleReplyGuidelines(@NotNull IReplyCallback callback, @NotNull ForumChannel channel) {
171-
callback.replyEmbeds(new EmbedBuilder()
172-
.setTitle("Help Guidelines")
173-
.setDescription(channel.getTopic())
174-
.build()
175-
).setEphemeral(true)
176-
.queue();
177-
}
178-
179-
private void handlePostClose(ButtonInteractionEvent event, @NotNull ForumHelpManager manager) {
180-
if (manager.isForumEligibleToBeUnreserved(event)) {
181-
manager.close(event, event.getUser().getIdLong() == manager.postThread().getOwnerIdLong(), null);
182-
} else {
183-
Responses.warning(event, "Could not close this post", "You're not allowed to close this post.").queue();
184-
}
185-
}
186125
}

0 commit comments

Comments
 (0)