Skip to content

Commit

Permalink
style: remove var usage & set event.getChannel()s to a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
RedVortexDev committed Oct 18, 2024
1 parent d472fbf commit d360c24
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void run(CommandEvent event) {
}

// Apply the solved tag, other behavior handled by PostAppliedTagsEvent.
var solvedTag = threadChannel.getParentChannel().asForumChannel().getAvailableTagById(HelpBotInstance.getConfig().getHelpChannelSolvedTag());
ForumTag solvedTag = threadChannel.getParentChannel().asForumChannel().getAvailableTagById(HelpBotInstance.getConfig().getHelpChannelSolvedTag());
ArrayList<ForumTag> appliedTags = new ArrayList<>(threadChannel.getAppliedTags());
if (!appliedTags.contains(solvedTag)) appliedTags.add(solvedTag);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.diamondfire.helpbot.bot.HelpBotInstance;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
import net.dv8tion.jda.api.entities.channel.forums.ForumTag;
import net.dv8tion.jda.api.events.channel.ChannelCreateEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

Expand All @@ -20,11 +22,13 @@ public void onChannelCreate(ChannelCreateEvent event) {
}

// Remove solved tag if post was created with it.
var solvedTag = event.getChannel().asThreadChannel().getParentChannel().asForumChannel().getAvailableTagById(HelpBotInstance.getConfig().getHelpChannelSolvedTag());
if (event.getChannel().asThreadChannel().getAppliedTags().contains(solvedTag)) {
var appliedTags = new ArrayList<>(event.getChannel().asThreadChannel().getAppliedTags());
ThreadChannel threadChannel = event.getChannel().asThreadChannel();

ForumTag solvedTag = threadChannel.getParentChannel().asForumChannel().getAvailableTagById(HelpBotInstance.getConfig().getHelpChannelSolvedTag());
if (threadChannel.getAppliedTags().contains(solvedTag)) {
ArrayList<ForumTag> appliedTags = new ArrayList<>(threadChannel.getAppliedTags());
appliedTags.remove(solvedTag);
event.getChannel().asThreadChannel().getManager().setAppliedTags(appliedTags).queue();
threadChannel.getManager().setAppliedTags(appliedTags).queue();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.diamondfire.helpbot.bot.command.reply.*;
import com.diamondfire.helpbot.bot.command.reply.feature.informative.*;
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
import net.dv8tion.jda.api.entities.channel.forums.ForumTag;
import net.dv8tion.jda.api.entities.channel.unions.ChannelUnion;
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateAppliedTagsEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

Expand All @@ -12,28 +14,27 @@ public class PostAppliedTagsEvent extends ListenerAdapter {
@Override
public void onChannelUpdateAppliedTags(ChannelUpdateAppliedTagsEvent event) {
// Limit to help forum.
if (event.getChannel().asThreadChannel().getParentChannel().getIdLong() != HelpBotInstance.getConfig().getHelpChannel()) {
ChannelUnion channel = event.getChannel();
ThreadChannel threadChannel = channel.asThreadChannel();
if (threadChannel.getParentChannel().getIdLong() != HelpBotInstance.getConfig().getHelpChannel()) {
return;
}

var solvedTag = event.getChannel().asThreadChannel().getParentChannel().asForumChannel().getAvailableTagById(HelpBotInstance.getConfig().getHelpChannelSolvedTag());
ForumTag solvedTag = threadChannel.getParentChannel().asForumChannel().getAvailableTagById(HelpBotInstance.getConfig().getHelpChannelSolvedTag());

// If the solved tag is added and the post is not locked, lock the thread.
if (event.getAddedTags().contains(solvedTag) && !event.getChannel().asThreadChannel().isLocked()) {
event.getChannel().asThreadChannel().getManager().setLocked(true).queue();
ThreadChannel threadChannel = HelpBotInstance.getJda().getThreadChannelById(event.getChannel().getIdLong());
if (threadChannel != null) {
threadChannel.sendMessageEmbeds(
new PresetBuilder()
.withPreset(
new InformativeReply(InformativeReplyType.SUCCESS, "Post marked as solved")
).getEmbed().build()
).queue();
}
event.getChannel().asThreadChannel().getManager().setName("[SOLVED] " + event.getChannel().getName()).queue();
} else if (event.getRemovedTags().contains(solvedTag) && event.getChannel().asThreadChannel().isLocked()) {
if (event.getAddedTags().contains(solvedTag) && !threadChannel.isLocked()) {
threadChannel.getManager().setLocked(true).queue();
threadChannel.sendMessageEmbeds(
new PresetBuilder()
.withPreset(
new InformativeReply(InformativeReplyType.SUCCESS, "Post marked as solved")
).getEmbed().build()
).queue();
threadChannel.getManager().setName("[SOLVED] " + channel.getName()).queue();
} else if (event.getRemovedTags().contains(solvedTag) && threadChannel.isLocked()) {
// If the solved tag is removed and the post is locked, put the old tags back.
event.getChannel().asThreadChannel().getManager().setAppliedTags(event.getOldTags()).queue();
threadChannel.getManager().setAppliedTags(event.getOldTags()).queue();
}
}

Expand Down

0 comments on commit d360c24

Please sign in to comment.