-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: in help forum, ?solve & lock closed posts * fix: duplicate behavior from ?solved * style: remove var usage & set event.getChannel()s to a variable
- Loading branch information
1 parent
bfe400f
commit 8d2df10
Showing
6 changed files
with
195 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/SolvedCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.diamondfire.helpbot.bot.command.impl.other.util; | ||
|
||
import com.diamondfire.helpbot.bot.HelpBotInstance; | ||
import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; | ||
import com.diamondfire.helpbot.bot.command.help.*; | ||
import com.diamondfire.helpbot.bot.command.impl.Command; | ||
import com.diamondfire.helpbot.bot.command.permissions.Permission; | ||
import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; | ||
import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; | ||
import com.diamondfire.helpbot.bot.events.CommandEvent; | ||
import net.dv8tion.jda.api.entities.channel.ChannelType; | ||
import net.dv8tion.jda.api.entities.channel.concrete.*; | ||
import net.dv8tion.jda.api.entities.channel.forums.ForumTag; | ||
|
||
import java.util.*; | ||
|
||
|
||
public class SolvedCommand extends Command { | ||
|
||
@Override | ||
public String getName() { | ||
return "solved"; | ||
} | ||
|
||
@Override | ||
public HelpContext getHelpContext() { | ||
return new HelpContext() | ||
.description("Marks the help post as solved.") | ||
.category(CommandCategory.OTHER); | ||
} | ||
|
||
@Override | ||
public ArgumentSet compileArguments() { | ||
return new ArgumentSet(); | ||
} | ||
|
||
@Override | ||
public Permission getPermission() { | ||
return Permission.USER; | ||
} | ||
|
||
@Override | ||
public void run(CommandEvent event) { | ||
// Limit to help forum. | ||
if ( | ||
event.getChannel().getType() != ChannelType.GUILD_PUBLIC_THREAD || | ||
event.getChannel().asThreadChannel().getParentChannel().getIdLong() != HelpBotInstance.getConfig().getHelpChannel() | ||
) { | ||
event.reply(new PresetBuilder() | ||
.withPreset( | ||
new InformativeReply(InformativeReplyType.ERROR, "Command can only be used in <#" + HelpBotInstance.getConfig().getHelpChannel() + ">") | ||
)); | ||
return; | ||
} | ||
|
||
ThreadChannel threadChannel = event.getChannel().asThreadChannel(); | ||
|
||
// Check if the command is used by the post owner. | ||
if (event.getMember() == null | threadChannel.getOwnerIdLong() != event.getMember().getIdLong()) { | ||
event.reply(new PresetBuilder() | ||
.withPreset( | ||
new InformativeReply(InformativeReplyType.ERROR, "Command can only be used by the post owner.") | ||
)); | ||
return; | ||
} | ||
|
||
// Check if the post is already locked. | ||
if (threadChannel.isLocked()) { | ||
event.reply(new PresetBuilder() | ||
.withPreset( | ||
new InformativeReply(InformativeReplyType.ERROR, "Post is already solved.") | ||
)); | ||
return; | ||
} | ||
|
||
// Apply the solved tag, other behavior handled by PostAppliedTagsEvent. | ||
ForumTag solvedTag = threadChannel.getParentChannel().asForumChannel().getAvailableTagById(HelpBotInstance.getConfig().getHelpChannelSolvedTag()); | ||
ArrayList<ForumTag> appliedTags = new ArrayList<>(threadChannel.getAppliedTags()); | ||
if (!appliedTags.contains(solvedTag)) appliedTags.add(solvedTag); | ||
|
||
threadChannel.getManager().setAppliedTags(appliedTags).queue(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/com/diamondfire/helpbot/bot/events/ChannelArchiveEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.diamondfire.helpbot.bot.events; | ||
|
||
import com.diamondfire.helpbot.bot.HelpBotInstance; | ||
import net.dv8tion.jda.api.entities.channel.ChannelType; | ||
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateArchivedEvent; | ||
import net.dv8tion.jda.api.hooks.ListenerAdapter; | ||
|
||
public class ChannelArchiveEvent extends ListenerAdapter { | ||
|
||
@Override | ||
public void onChannelUpdateArchived(ChannelUpdateArchivedEvent event) { | ||
// Limit to help forum. | ||
if ( | ||
event.getChannel().getType() != ChannelType.GUILD_PUBLIC_THREAD || | ||
event.getChannel().asThreadChannel().getParentChannel().getIdLong() != HelpBotInstance.getConfig().getHelpChannel() | ||
) { | ||
return; | ||
} | ||
|
||
// When a post is archived, it should be locked. | ||
event.getChannel().asThreadChannel().getManager().setLocked(true).queue(); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/diamondfire/helpbot/bot/events/ChannelCreatedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.diamondfire.helpbot.bot.events; | ||
|
||
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; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class ChannelCreatedEvent extends ListenerAdapter { | ||
|
||
@Override | ||
public void onChannelCreate(ChannelCreateEvent event) { | ||
// Limit to help forum. | ||
if ( | ||
event.getChannel().getType() != ChannelType.GUILD_PUBLIC_THREAD || | ||
event.getChannel().asThreadChannel().getParentChannel().getIdLong() != HelpBotInstance.getConfig().getHelpChannel() | ||
) { | ||
return; | ||
} | ||
|
||
// Remove solved tag if post was created with it. | ||
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); | ||
threadChannel.getManager().setAppliedTags(appliedTags).queue(); | ||
} | ||
|
||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/diamondfire/helpbot/bot/events/PostAppliedTagsEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.diamondfire.helpbot.bot.events; | ||
|
||
import com.diamondfire.helpbot.bot.HelpBotInstance; | ||
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; | ||
|
||
public class PostAppliedTagsEvent extends ListenerAdapter { | ||
|
||
@Override | ||
public void onChannelUpdateAppliedTags(ChannelUpdateAppliedTagsEvent event) { | ||
// Limit to help forum. | ||
ChannelUnion channel = event.getChannel(); | ||
ThreadChannel threadChannel = channel.asThreadChannel(); | ||
if (threadChannel.getParentChannel().getIdLong() != HelpBotInstance.getConfig().getHelpChannel()) { | ||
return; | ||
} | ||
|
||
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) && !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. | ||
threadChannel.getManager().setAppliedTags(event.getOldTags()).queue(); | ||
} | ||
} | ||
|
||
} |