Forum Tags - #63
Forum Tags#63MC-Samuel wants to merge 3 commits into
Conversation
| // --> | ||
| tagProcessor.registerMechanism("forum_post_tags", false, (object, mechanism) -> { | ||
| if (!(object.getChannel() instanceof ThreadChannel threadChannel)) { | ||
| mechanism.echoError("Cannot adjust 'forum_post_tags' tag: this channel is not a forum post."); |
There was a problem hiding this comment.
mechanism*, but the error already automatically has the whole Error while adjusting mechanism 'X' on 'OBJECT': in it, you only really need the actual error message.
| ListTag input = mechanism.valueAsType(ListTag.class); | ||
| int size; | ||
| if (input.size() > 5) { | ||
| mechanism.echoError("The 'DiscordChannelTag.forum_post_tags' mechanism has a maximum input of 5 tag ids."); |
There was a problem hiding this comment.
Same here, the mechanism name and everything is already automatically in the error message (or should be at least).
| } | ||
| Collection<ForumTagSnowflake> forumTags = new ArrayList<>(size); | ||
| for (int i = 0; i < size; i++) { | ||
| forumTags.add(ForumTagSnowflake.fromId(input.get(i))); |
There was a problem hiding this comment.
Can check if there's precedence one way or the other in the rest of dDiscordBot, but might better if we handle the long parsing ourselves (so that invalid input is a nice Denizen error and not an exception).
BehrRiley
left a comment
There was a problem hiding this comment.
Tested this on 26.2 with an actual Discord forum channel/post and on a text channel with a normal public thread under a text channel;
the normal forum behavior works:
- forum_channel_tags returned the available tag
- forum_post_tags returned the applied tag
- clearing the tags worked
- setting the tag again worked
but there's an edge case with normal threads though; a regular thread under a text channel still passes the ThreadChannel checks. the tag returns an empty list, and the mechanism reaches JDA and throws because tags can't be applied outside forum/media channels.
I left comments on the two checks where that happens.
happy-path good debug: https://paste.denizenscript.com/View/141575
edge-case borked debug: https://paste.denizenscript.com/View/141576
| return null; | ||
| } | ||
| return new ListTag(threadChannel.getAppliedTags(), tag -> new ElementTag(tag.getIdLong())); | ||
| }); |
There was a problem hiding this comment.
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 and forum_post_tags just 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.
| if (!(object.getChannel() instanceof ThreadChannel threadChannel)) { | ||
| mechanism.echoError("This channel is not a forum post."); | ||
| return; | ||
| } |
There was a problem hiding this comment.
same thing happens here with a normal text-channel thread; it passes this check, then gets as far as JDA and throws: IllegalStateException: Cannot apply tags to threads outside of forum/media channels. - this should validate the thread's parent before trying to set the tags too
99417a0 to
696ec9a
Compare
Requested at https://discord.com/channels/315163488085475337/1443702893097255012