-
Notifications
You must be signed in to change notification settings - Fork 16
Forum Tags #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MC-Samuel
wants to merge
3
commits into
DenizenScript:master
Choose a base branch
from
MC-Samuel:forum_post_tags
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+90
−1
Open
Forum Tags #63
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -8,18 +8,23 @@ | |
| import com.denizenscript.denizencore.objects.*; | ||
| import com.denizenscript.denizencore.objects.core.ElementTag; | ||
| import com.denizenscript.denizencore.objects.core.ListTag; | ||
| import com.denizenscript.denizencore.tags.ObjectTagProcessor; | ||
| import com.denizenscript.denizencore.tags.Attribute; | ||
| import com.denizenscript.denizencore.tags.ObjectTagProcessor; | ||
| import com.denizenscript.denizencore.tags.TagContext; | ||
| import com.denizenscript.denizencore.utilities.CoreUtilities; | ||
| import com.denizenscript.denizencore.utilities.debugging.Debug; | ||
| import net.dv8tion.jda.api.entities.*; | ||
| import net.dv8tion.jda.api.entities.channel.Channel; | ||
| import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer; | ||
| import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel; | ||
| import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; | ||
| import net.dv8tion.jda.api.entities.channel.forums.ForumTagSnowflake; | ||
| import net.dv8tion.jda.api.entities.channel.middleman.*; | ||
| import net.dv8tion.jda.api.entities.channel.unions.IThreadContainerUnion; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
|
|
||
| public class DiscordChannelTag implements ObjectTag, FlaggableObject, Adjustable { | ||
|
|
||
| // <--[ObjectType] | ||
|
|
@@ -434,6 +439,90 @@ public static void register() { | |
| return new ElementTag(((StandardGuildMessageChannel) object.getChannel()).getTopic()); | ||
| }); | ||
|
|
||
| // <--[tag] | ||
| // @attribute <DiscordChannelTag.forum_channel_tags> | ||
| // @returns ListTag | ||
| // @plugin dDiscordBot | ||
| // @description | ||
| // Returns the ids of possible tags for a forum post. | ||
| // Only applicable to forum channels. | ||
| // See also <@link tag DiscordChannelTag.forum_post_tags> and <@link mechanism DiscordChannelTag.forum_post_tags>. | ||
| // --> | ||
| tagProcessor.registerTag(ListTag.class, "forum_channel_tags", (attribute, object) -> { | ||
| if (!(object.getChannel() instanceof ForumChannel forumChannel)) { | ||
| attribute.echoError("This is not a forum channel."); | ||
| return null; | ||
| } | ||
| return new ListTag(forumChannel.getAvailableTags(), tag -> new ElementTag(tag.getIdLong())); | ||
| }); | ||
|
|
||
| // <--[tag] | ||
| // @attribute <DiscordChannelTag.forum_post_tags> | ||
| // @returns ListTag | ||
| // @plugin dDiscordBot | ||
| // @mechanism DiscordChannelTag.forum_post_tags | ||
| // @description | ||
| // Returns the ids of tags on a post in a forum channel. | ||
| // See also <@link tag DiscordChannelTag.forum_channel_tags>. | ||
| // --> | ||
| tagProcessor.registerTag(ListTag.class, "forum_post_tags", (attribute, object) -> { | ||
| if (!(object.getChannel() instanceof ThreadChannel threadChannel)) { | ||
| attribute.echoError("This channel is not a forum post."); | ||
| return null; | ||
| } | ||
| if (!(threadChannel.getParentChannel() instanceof ForumChannel)) { | ||
| attribute.echoError("This thread is not in a forum channel."); | ||
| return null; | ||
| } | ||
| return new ListTag(threadChannel.getAppliedTags(), tag -> new ElementTag(tag.getIdLong())); | ||
| }); | ||
|
|
||
| // <--[mechanism] | ||
| // @object DiscordChannelTag | ||
| // @name forum_post_tags | ||
| // @input ListTag | ||
|
mcmonkey4eva marked this conversation as resolved.
|
||
| // @plugin dDiscordBot | ||
| // @description | ||
| // Sets the tags on a post in a forum channel. A post can have a maximum of 5 tags. | ||
| // Entries are the ids of the tags. Provide no input to remove all tags. | ||
| // @tags | ||
| // <DiscordChannelTag.forum_channel_tags> | ||
| // <DiscordChannelTag.forum_post_tags> | ||
| // --> | ||
| tagProcessor.registerMechanism("forum_post_tags", false, (object, mechanism) -> { | ||
| if (!(object.getChannel() instanceof ThreadChannel threadChannel)) { | ||
| mechanism.echoError("This channel is not a forum post."); | ||
| return; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same thing happens here with a normal text-channel thread; it passes this check, then gets as far as JDA and throws: |
||
| if (!(threadChannel.getParentChannel() instanceof ForumChannel)) { | ||
| mechanism.echoError("This thread is not in a forum channel."); | ||
| return; | ||
| } | ||
| if (!mechanism.hasValue()) { | ||
| threadChannel.getManager().setAppliedTags().submit(); | ||
| return; | ||
| } | ||
| ListTag input = mechanism.valueAsType(ListTag.class); | ||
| int size; | ||
| if (input.size() > 5) { | ||
| mechanism.echoError("Mechanism has a maximum input of 5 tag ids."); | ||
| size = 5; | ||
| } | ||
| else { | ||
| size = input.size(); | ||
| } | ||
| Collection<ForumTagSnowflake> forumTags = new ArrayList<>(size); | ||
| for (int i = 0; i < size; i++) { | ||
| try { | ||
| forumTags.add(ForumTagSnowflake.fromId(Long.parseLong(input.get(i)))); | ||
| } | ||
| catch (NumberFormatException e) { | ||
| mechanism.echoError("Invalid forum tag id '" + input.get(i) + "'."); | ||
| } | ||
| } | ||
| threadChannel.getManager().setAppliedTags(forumTags).submit(); | ||
| }); | ||
|
|
||
| // <--[mechanism] | ||
| // @object DiscordChannelTag | ||
| // @name add_thread_member | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tested this with a normal public thread under a text channel: https://paste.denizenscript.com/View/141576
since it's still a
ThreadChannel, this check passes andforum_post_tagsjust returns an empty list instead of saying it isn't a forum post.I think this also needs to check what the thread's parent channel is, instead of only checking
ThreadChannel.