Skip to content
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

Add Forum Post Support #1609

Merged
merged 5 commits into from Jan 30, 2024
Merged

Add Forum Post Support #1609

merged 5 commits into from Jan 30, 2024

Conversation

KTStephano
Copy link
Contributor

@KTStephano KTStephano commented Jan 25, 2024

Continuation of #1604 and #1453

This PR does two things:

  • Updates discordgo, dstate with new fields related to forums (available tags, applied tags, default thread rate limits, etc.)
  • Adds createForumPost and deleteForumPost templates

Other Info:

  • Limits for create and remove are currently shared with thread's create and remove limits
  • Optional args for createForumPost are set to use key-value style so that order doesn't matter and we can also expose other optional args later

API (templates):

Field Description
.Channel.IsForum true if channel is forum type
.Channel.AvailableTags Slice of discordgo.ForumTag. Only present if channel is forum type.
.Channel.AppliedTags Slice of int64 representing tag ids. Only present if channel represents a specific forum thread/post.

API (functions):

createForumPost channel name content (optional: "slowmode" arg "tags" arg)

Creates a new forum post in channel. content can be a string, embed or complex message. name represents the title of the post. "slowmode" arg allows the user to specify the thread's slowmode (in seconds). "tags" arg allows the user to specify one or more forum tags. Duplicate and invalid tags are ignored, and arg can be either a string or cslice. Returns *templates.CtxChannel upon success.

deleteForumPost post

Removes post. Can be either thread's ID or mention.

Examples:

(Create)

{{$forumChannel := ...}}
{{$postTitle := "Forum Post Title"}}
{{$post := createForumPost $forumChannel $postTitle "post content as string"}}

{{$tags = cslice "discussion" "bot" "info"}}
{{$post = createForumPost $forumChannel $postTitle (cembed ...) "tags" $tags}}

{{$oneMinute := 60}}
{{$post = createForumPost $forumChannel $postTitle (cembed ...) "slowmode" $oneMinute}}

{{$post = createForumPost $forumChannel $postTitle (cembed ...) "tags" $tags "slowmode" $oneMinute}}

(Delete)

{{deleteForumPost $post.ID}}

…s createForumPost and removeForumPost

IsForum exposed to CCs to quickly check if a channel is a forum channel
AvailableTags are exposed to CCs as a slice of discordgo.ForumTag
AppliedTags are exposed to CCs as a slice of int64 ids
@KTStephano KTStephano changed the title templates,discordgo,dstate: Adds extended support for forums API; add… Add Forum Post Support Jan 25, 2024
c.addContextFunc("createThread", c.tmplCreateThread)
c.addContextFunc("deleteThread", c.tmplDeleteThread)
c.addContextFunc("addThreadMember", c.tmplThreadMemberAdd)
c.addContextFunc("removeThreadMember", c.tmplThreadMemberRemove)

// forum functions
c.addContextFunc("createForumPost", c.tmplCreateForumPost)
c.addContextFunc("removeForumPost", c.tmplRemoveForumPost)
Copy link
Contributor

Choose a reason for hiding this comment

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

deleteForumPost feels better (create > delete, add > remove, give > take logic), also no need for additional c.tmplRemoveForumPost why not just c.tmplDeleteThread

one could always add a comment to that method, that it deletes both, simple thread and a forum post

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, I renamed it "deleteForumPost". I also removed tmplRemoveForumPost in favor of reusing tmplDeleteThread (added a comment about being it able to delete both types of threads like you suggested).

return rateLimit, tags, nil
}

func (c *Context) tmplCreateForumPost(channel, content interface{}, name string, optional ...interface{}) (*CtxChannel, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To me workflow of giving arguments > channel, name, content, (optional...) feels better. Post title is sort of first than post content. I know it needs interface{} twice then : )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Latest commit switches the order to be channel, name, content, (optional...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm also wondering if createThread from the last PR should be changed to follow the same format. For example
createThread channel name (optional: "message_id" arg "private" arg)

Copy link
Contributor

Choose a reason for hiding this comment

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

looks reasonable, to have thread's name first rest is already all content and how content is shown

but at its current state, it is less code and writing createThread nil nil "threadName" is not that cumbersome.

so let's wait what developer thinks, both ways are good for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

it think that parameter name could also be part of type interface{} and you later ToString() it, because in some cases it is easier to use pure numbers as thread/forumPost name : )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed a change that switches both create functions to use interface{} for name. It calls ToString() on it before passing it to discordgo.

DefaultReactionEmoji discordgo.ForumDefaultReaction `json:"default_reaction_emoji"`
DefaultThreadRateLimitPerUser int `json:"default_thread_rate_limit_per_user"`
DefaultSortOrder *discordgo.ForumSortOrderType `json:"default_sort_order"`
DefaultForumLayout discordgo.ForumLayout `json:"default_forum_layout"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, for IsPrivate() method few lines down, || c.Type == discordgo.ChannelTypeGuildPrivateThread needs to be added to if

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does GuildPrivateThread sit on the same level as DM privacy?

Copy link
Contributor

Choose a reason for hiding this comment

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

looking at how this is handled in context functions, well it is a badly named field. Channel Type 12 says yeah it's private as well. so better not change this.

Comment on lines +274 to +286
DefaultReactionEmoji ForumDefaultReaction `json:"default_reaction_emoji"`

// The initial RateLimitPerUser to set on newly created threads in a channel.
// This field is copied to the thread at creation time and does not live update.
DefaultThreadRateLimitPerUser int `json:"default_thread_rate_limit_per_user"`

// The default sort order type used to order posts in forum channels.
// Defaults to null, which indicates a preferred sort order hasn't been set by a channel admin.
DefaultSortOrder *ForumSortOrderType `json:"default_sort_order"`

// The default forum layout view used to display posts in forum channels.
// Defaults to ForumLayoutNotSet, which indicates a layout view has not been set by a channel admin.
DefaultForumLayout ForumLayout `json:"default_forum_layout"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps these fields should be in templates/structs.go > CtxChannel as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah could add them. When I first went through it I just wasn't sure if people would need those fields in CCs. They're present in the dstate.ChannelState struct though for Go code to use

@ashishjh-bst ashishjh-bst merged commit fa1f387 into botlabs-gg:dev Jan 30, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants