Skip to content

Commit

Permalink
Merge pull request #197 from disgoorg/patch/forum-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 authored Sep 14, 2022
2 parents 9ebbc6e + 78ef75c commit f04f463
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 46 deletions.
74 changes: 53 additions & 21 deletions discord/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ const (
type ChannelFlags int

const (
ChannelFlagPinned ChannelFlags = 1 << (iota + 1)
ChannelFlagsNone ChannelFlags = 0
ChannelFlagPinned ChannelFlags = 1 << 1
ChannelFlagRequireTag ChannelFlags = 1 << 4
ChannelFlagsNone ChannelFlags = 0
)

// Add allows you to add multiple bits together, producing a new bit
Expand Down Expand Up @@ -810,6 +811,7 @@ type GuildThread struct {
parentID snowflake.ID
MessageCount int
TotalMessageSent int
AppliedTags []snowflake.ID
MemberCount int
ThreadMetadata ThreadMetadata
}
Expand All @@ -832,6 +834,7 @@ func (c *GuildThread) UnmarshalJSON(data []byte) error {
c.parentID = v.ParentID
c.MessageCount = v.MessageCount
c.TotalMessageSent = v.TotalMessageSent
c.AppliedTags = v.AppliedTags
c.MemberCount = v.MemberCount
c.ThreadMetadata = v.ThreadMetadata
return nil
Expand All @@ -851,6 +854,7 @@ func (c GuildThread) MarshalJSON() ([]byte, error) {
ParentID: c.parentID,
MessageCount: c.MessageCount,
TotalMessageSent: c.TotalMessageSent,
AppliedTags: c.AppliedTags,
MemberCount: c.MemberCount,
ThreadMetadata: c.ThreadMetadata,
})
Expand Down Expand Up @@ -1036,15 +1040,20 @@ var (
)

type GuildForumChannel struct {
id snowflake.ID
guildID snowflake.ID
position int
permissionOverwrites PermissionOverwrites
name string
parentID *snowflake.ID
LastThreadID *snowflake.ID
Topic *string
RateLimitPerUser int
id snowflake.ID
guildID snowflake.ID
position int
permissionOverwrites PermissionOverwrites
name string
parentID *snowflake.ID
LastThreadID *snowflake.ID
Topic *string
NSFW bool
RateLimitPerUser int
Flags ChannelFlags
AvailableTags []ForumTag
DefaultReactionEmoji *DefaultReactionEmoji
DefaultThreadRateLimitPerUser int
}

func (c *GuildForumChannel) UnmarshalJSON(data []byte) error {
Expand All @@ -1061,22 +1070,32 @@ func (c *GuildForumChannel) UnmarshalJSON(data []byte) error {
c.parentID = v.ParentID
c.LastThreadID = v.LastThreadID
c.Topic = v.Topic
c.NSFW = v.NSFW
c.RateLimitPerUser = v.RateLimitPerUser
c.Flags = v.Flags
c.AvailableTags = v.AvailableTags
c.DefaultReactionEmoji = v.DefaultReactionEmoji
c.DefaultThreadRateLimitPerUser = v.DefaultThreadRateLimitPerUser
return nil
}

func (c GuildForumChannel) MarshalJSON() ([]byte, error) {
return json.Marshal(guildForumChannel{
ID: c.id,
Type: c.Type(),
GuildID: c.guildID,
Position: c.position,
PermissionOverwrites: c.permissionOverwrites,
Name: c.name,
ParentID: c.parentID,
LastThreadID: c.LastThreadID,
Topic: c.Topic,
RateLimitPerUser: c.RateLimitPerUser,
ID: c.id,
Type: c.Type(),
GuildID: c.guildID,
Position: c.position,
PermissionOverwrites: c.permissionOverwrites,
Name: c.name,
ParentID: c.parentID,
LastThreadID: c.LastThreadID,
Topic: c.Topic,
NSFW: c.NSFW,
RateLimitPerUser: c.RateLimitPerUser,
Flags: c.Flags,
AvailableTags: c.AvailableTags,
DefaultReactionEmoji: c.DefaultReactionEmoji,
DefaultThreadRateLimitPerUser: c.DefaultThreadRateLimitPerUser,
})
}

Expand Down Expand Up @@ -1149,6 +1168,19 @@ type ThreadMetadata struct {
CreateTimestamp time.Time `json:"create_timestamp"`
}

type ForumTag struct {
ID snowflake.ID `json:"id"`
Name string `json:"name"`
Moderated bool `json:"moderated"`
EmojiID *snowflake.ID `json:"emoji_id"`
EmojiName *string `json:"emoji_name"`
}

type DefaultReactionEmoji struct {
EmojiID *snowflake.ID `json:"emoji_id"`
EmojiName *string `json:"emoji_name"`
}

type AutoArchiveDuration int

const (
Expand Down
49 changes: 34 additions & 15 deletions discord/channel_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ type GuildChannelUpdate interface {
}

type GuildTextChannelUpdate struct {
Name *string `json:"name,omitempty"`
Type *ChannelType `json:"type,omitempty"`
Position *int `json:"position,omitempty"`
Topic *string `json:"topic,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
RateLimitPerUser *int `json:"rate_limit_per_user,omitempty"`
PermissionOverwrites *[]PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
DefaultAutoArchiveDuration *AutoArchiveDuration `json:"default_auto_archive_duration,omitempty"`
Name *string `json:"name,omitempty"`
Type *ChannelType `json:"type,omitempty"`
Position *int `json:"position,omitempty"`
Topic *string `json:"topic,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
RateLimitPerUser *int `json:"rate_limit_per_user,omitempty"`
PermissionOverwrites *[]PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
DefaultAutoArchiveDuration *AutoArchiveDuration `json:"default_auto_archive_duration,omitempty"`
DefaultThreadRateLimitPerUser *int `json:"default_thread_rate_limit_per_user,omitempty"`
}

func (GuildTextChannelUpdate) channelUpdate() {}
Expand Down Expand Up @@ -94,17 +95,35 @@ func (GuildStageVoiceChannelUpdate) channelUpdate() {}
func (GuildStageVoiceChannelUpdate) guildChannelUpdate() {}

type GuildForumChannelUpdate struct {
Name *string `json:"name,omitempty"`
Position *int `json:"position,omitempty"`
Topic *string `json:"topic,omitempty"`
PermissionOverwrites *[]PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
RateLimitPerUser *int `json:"rate_limit_per_user,omitempty"`
Name *string `json:"name,omitempty"`
Position *int `json:"position,omitempty"`
Topic *string `json:"topic,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
PermissionOverwrites *[]PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
RateLimitPerUser *int `json:"rate_limit_per_user"`
AvailableTags *[]ForumTag `json:"available_tags,omitempty"`
DefaultReactionEmoji *json.Nullable[DefaultReactionEmoji] `json:"default_reaction_emoji,omitempty"`
DefaultThreadRateLimitPerUser *int `json:"default_thread_rate_limit_per_user,omitempty"`
}

func (GuildForumChannelUpdate) channelUpdate() {}
func (GuildForumChannelUpdate) guildChannelUpdate() {}

type GuildForumThreadChannelUpdate struct {
Name *string `json:"name,omitempty"`
Archived *bool `json:"archived,omitempty"`
AutoArchiveDuration *AutoArchiveDuration `json:"auto_archive_duration,omitempty"`
Locked *bool `json:"locked,omitempty"`
Invitable *bool `json:"invitable,omitempty"`
RateLimitPerUser *int `json:"rate_limit_per_user,omitempty"`
Flags *ChannelFlags `json:"flags,omitempty"`
AppliedTags *[]snowflake.ID `json:"applied_tags,omitempty"`
}

func (GuildForumThreadChannelUpdate) channelUpdate() {}
func (GuildForumThreadChannelUpdate) guildChannelUpdate() {}

type GuildChannelPositionUpdate struct {
ID snowflake.ID `json:"id"`
Position *json.Nullable[int] `json:"position"`
Expand Down
24 changes: 15 additions & 9 deletions discord/channels_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type guildThread struct {
LastPinTimestamp *time.Time `json:"last_pin_timestamp"`
MessageCount int `json:"message_count"`
TotalMessageSent int `json:"total_message_sent"`
AppliedTags []snowflake.ID `json:"applied_tags"`
MemberCount int `json:"member_count"`
ThreadMetadata ThreadMetadata `json:"thread_metadata"`
}
Expand Down Expand Up @@ -176,15 +177,20 @@ func (t *guildStageVoiceChannel) UnmarshalJSON(data []byte) error {
}

type guildForumChannel struct {
ID snowflake.ID `json:"id"`
Type ChannelType `json:"type"`
GuildID snowflake.ID `json:"guild_id"`
Position int `json:"position"`
PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites"`
Name string `json:"name"`
ParentID *snowflake.ID `json:"parent_id"`
Topic *string `json:"topic"`
RateLimitPerUser int `json:"rate_limit_per_user"`
ID snowflake.ID `json:"id"`
Type ChannelType `json:"type"`
GuildID snowflake.ID `json:"guild_id"`
Position int `json:"position"`
PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites"`
Name string `json:"name"`
ParentID *snowflake.ID `json:"parent_id"`
Topic *string `json:"topic"`
NSFW bool `json:"nsfw"`
RateLimitPerUser int `json:"rate_limit_per_user"`
Flags ChannelFlags `json:"flags"`
AvailableTags []ForumTag `json:"available_tags"`
DefaultReactionEmoji *DefaultReactionEmoji `json:"default_reaction_emoji"`
DefaultThreadRateLimitPerUser int `json:"default_thread_rate_limit_per_user"`

// idk discord name your shit correctly
LastThreadID *snowflake.ID `json:"last_message_id"`
Expand Down
6 changes: 5 additions & 1 deletion discord/thread.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package discord

import "github.com/disgoorg/disgo/json"
import (
"github.com/disgoorg/disgo/json"
"github.com/disgoorg/snowflake/v2"
)

type ThreadCreateFromMessage struct {
Name string `json:"name"`
Expand All @@ -13,6 +16,7 @@ type ForumThreadCreate struct {
AutoArchiveDuration AutoArchiveDuration `json:"auto_archive_duration,omitempty"`
RateLimitPerUser int `json:"rate_limit_per_user,omitempty"`
Message MessageCreate `json:"message"`
AppliedTags []snowflake.ID `json:"applied_tags,omitempty"`
}

func (c ForumThreadCreate) ToBody() (any, error) {
Expand Down

0 comments on commit f04f463

Please sign in to comment.