Skip to content

Commit

Permalink
lib/discordgo: properly add ThreadMetadata
Browse files Browse the repository at this point in the history
Add the `ThreadMetadata` properly to `discordgo.Channel`, that is,
remove the flattened duplicate entries from said struct and instead keep
just `discordgo.ThreadMetadata`.

As a consequence, this cascades to dstate as well as common/templates,
which were modified to reflect that change; as an added bonus, this now
properly represents the channel structure as defined by Discord, rather
than a custom flattened one.

BREAKING CHANGE:

`.Channel.{Locked,Archived}` will be moved to `.Channel.ThreadMetadata.*`.
Migrate by adding that additional layer to your accessing of these
fields. Reports indicate this hasn't worked properly anyway, therefore
this breakage should be acceptable.

Signed-off-by: Luca Zeuch <l-zeuch@email.de>
  • Loading branch information
l-zeuch committed Jun 29, 2024
1 parent 9e59a6d commit 93147c0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 30 deletions.
12 changes: 5 additions & 7 deletions common/templates/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ type CtxChannel struct {
ParentID int64 `json:"parent_id"`
OwnerID int64 `json:"owner_id"`

AvailableTags []discordgo.ForumTag `json:"available_tags"`
AppliedTags []int64 `json:"applied_tags"`
Flags discordgo.ChannelFlags `json:"flags"`
Archived bool `json:"archived"`
Locked bool `json:"locked"`
AvailableTags []discordgo.ForumTag `json:"available_tags"`
AppliedTags []int64 `json:"applied_tags"`
Flags discordgo.ChannelFlags `json:"flags"`
ThreadMetadata *discordgo.ThreadMetadata `json:"thread_metadata,omitempty"`
}

func (c *CtxChannel) Mention() (string, error) {
Expand Down Expand Up @@ -66,8 +65,7 @@ func CtxChannelFromCS(cs *dstate.ChannelState) *CtxChannel {
AvailableTags: cs.AvailableTags,
AppliedTags: cs.AppliedTags,
Flags: cs.Flags,
Archived: cs.Archived,
Locked: cs.Locked,
ThreadMetadata: cs.ThreadMetadata,
}

return ctxChannel
Expand Down
12 changes: 0 additions & 12 deletions lib/discordgo/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,6 @@ type Channel struct {
// 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"`

// whether the thread is archived
Archived bool `json:"archived"`

// the thread will stop showing in the channel list after auto_archive_duration minutes of inactivity, can be set to: 60, 1440, 4320, 10080
AutoArchiveDuration AutoArchiveDuration `json:"auto_archive_duration,omitempty"`

// whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
Locked bool `json:"locked"`

// whether non-moderators can add other non-moderators to a thread; only available on private threads
Invitable bool `json:"invitable"`
}

func (c *Channel) GetChannelID() int64 {
Expand Down
5 changes: 1 addition & 4 deletions lib/dstate/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ func ChannelStateFromDgo(c *discordgo.Channel) ChannelState {
DefaultThreadRateLimitPerUser: c.DefaultThreadRateLimitPerUser,
DefaultSortOrder: c.DefaultSortOrder,
DefaultForumLayout: c.DefaultForumLayout,
Archived: c.Archived,
AutoArchiveDuration: c.AutoArchiveDuration,
Locked: c.Locked,
Invitable: c.Invitable,
ThreadMetadata: c.ThreadMetadata,
}
}

Expand Down
10 changes: 3 additions & 7 deletions lib/dstate/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,12 @@ type ChannelState struct {
RateLimitPerUser int `json:"rate_limit_per_user"`
Flags discordgo.ChannelFlags `json:"flags"`
OwnerID int64 `json:"owner_id,string"`
ThreadMetadata *discordgo.ThreadMetadata `json:"thread_metadata"`
ThreadMetadata *discordgo.ThreadMetadata `json:"thread_metadata,omitempty"`

PermissionOverwrites []discordgo.PermissionOverwrite `json:"permission_overwrites"`

AvailableTags []discordgo.ForumTag `json:"available_tags"`
AppliedTags []int64 `json:"applied_tags"`
Archived bool `json:"archived"`
AutoArchiveDuration discordgo.AutoArchiveDuration `json:"auto_archive_duration,omitempty"`
Locked bool `json:"locked"`
Invitable bool `json:"invitable"`
AvailableTags []discordgo.ForumTag `json:"available_tags"`
AppliedTags []int64 `json:"applied_tags"`

DefaultReactionEmoji discordgo.ForumDefaultReaction `json:"default_reaction_emoji"`
DefaultThreadRateLimitPerUser int `json:"default_thread_rate_limit_per_user"`
Expand Down

0 comments on commit 93147c0

Please sign in to comment.