Skip to content

Forum Tags - #63

Open
MC-Samuel wants to merge 3 commits into
DenizenScript:masterfrom
MC-Samuel:forum_post_tags
Open

MC-Samuel wants to merge 3 commits into
DenizenScript:masterfrom
MC-Samuel:forum_post_tags

Conversation

@MC-Samuel

Copy link
Copy Markdown
Contributor

// -->
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.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BehrRiley left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()));
});

Copy link
Copy Markdown

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 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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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: 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

@CLAassistant

CLAassistant commented Sep 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants