Skip to content

Commit

Permalink
Merge branch 'master' into patch/slog
Browse files Browse the repository at this point in the history
  • Loading branch information
cane authored Sep 21, 2023
2 parents 1fbe20e + 3129dd5 commit f7f5744
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 104 deletions.
129 changes: 81 additions & 48 deletions discord/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,22 +431,19 @@ var (
)

type GuildVoiceChannel struct {
id snowflake.ID
guildID snowflake.ID
position int
permissionOverwrites []PermissionOverwrite
name string
bitrate int
UserLimit int
parentID *snowflake.ID
rtcRegion string
VideoQualityMode VideoQualityMode
lastMessageID *snowflake.ID
lastPinTimestamp *time.Time
topic *string
nsfw bool
defaultAutoArchiveDuration AutoArchiveDuration
rateLimitPerUser int
id snowflake.ID
guildID snowflake.ID
position int
permissionOverwrites []PermissionOverwrite
name string
bitrate int
UserLimit int
parentID *snowflake.ID
rtcRegion string
VideoQualityMode VideoQualityMode
lastMessageID *snowflake.ID
nsfw bool
rateLimitPerUser int
}

func (c *GuildVoiceChannel) UnmarshalJSON(data []byte) error {
Expand All @@ -466,33 +463,27 @@ func (c *GuildVoiceChannel) UnmarshalJSON(data []byte) error {
c.rtcRegion = v.RTCRegion
c.VideoQualityMode = v.VideoQualityMode
c.lastMessageID = v.LastMessageID
c.lastPinTimestamp = v.LastPinTimestamp
c.topic = v.Topic
c.nsfw = v.NSFW
c.defaultAutoArchiveDuration = v.DefaultAutoArchiveDuration
c.rateLimitPerUser = v.RateLimitPerUser
return nil
}

func (c GuildVoiceChannel) MarshalJSON() ([]byte, error) {
return json.Marshal(guildVoiceChannel{
ID: c.id,
Type: c.Type(),
GuildID: c.guildID,
Position: c.position,
PermissionOverwrites: c.permissionOverwrites,
Name: c.name,
Bitrate: c.bitrate,
UserLimit: c.UserLimit,
ParentID: c.parentID,
RTCRegion: c.rtcRegion,
VideoQualityMode: c.VideoQualityMode,
LastMessageID: c.lastMessageID,
LastPinTimestamp: c.lastPinTimestamp,
Topic: c.topic,
NSFW: c.nsfw,
DefaultAutoArchiveDuration: c.defaultAutoArchiveDuration,
RateLimitPerUser: c.rateLimitPerUser,
ID: c.id,
Type: c.Type(),
GuildID: c.guildID,
Position: c.position,
PermissionOverwrites: c.permissionOverwrites,
Name: c.name,
Bitrate: c.bitrate,
UserLimit: c.UserLimit,
ParentID: c.parentID,
RTCRegion: c.rtcRegion,
VideoQualityMode: c.VideoQualityMode,
LastMessageID: c.lastMessageID,
NSFW: c.nsfw,
RateLimitPerUser: c.rateLimitPerUser,
})
}

Expand Down Expand Up @@ -544,20 +535,23 @@ func (c GuildVoiceChannel) LastMessageID() *snowflake.ID {
return c.lastMessageID
}

// LastPinTimestamp always returns nil for GuildVoiceChannel(s) as they cannot have pinned messages.
func (c GuildVoiceChannel) LastPinTimestamp() *time.Time {
return c.lastPinTimestamp
return nil
}

// Topic always returns nil for GuildVoiceChannel(s) as they do not have their own topic.
func (c GuildVoiceChannel) Topic() *string {
return c.topic
return nil
}

func (c GuildVoiceChannel) NSFW() bool {
return c.nsfw
}

// DefaultAutoArchiveDuration is always 0 for GuildVoiceChannel(s) as they do not have their own AutoArchiveDuration.
func (c GuildVoiceChannel) DefaultAutoArchiveDuration() AutoArchiveDuration {
return c.defaultAutoArchiveDuration
return 0
}

func (c GuildVoiceChannel) RateLimitPerUser() int {
Expand Down Expand Up @@ -930,9 +924,10 @@ func (GuildThread) messageChannel() {}
func (GuildThread) guildMessageChannel() {}

var (
_ Channel = (*GuildStageVoiceChannel)(nil)
_ GuildChannel = (*GuildStageVoiceChannel)(nil)
_ GuildAudioChannel = (*GuildStageVoiceChannel)(nil)
_ Channel = (*GuildStageVoiceChannel)(nil)
_ GuildChannel = (*GuildStageVoiceChannel)(nil)
_ GuildAudioChannel = (*GuildStageVoiceChannel)(nil)
_ GuildMessageChannel = (*GuildStageVoiceChannel)(nil)
)

type GuildStageVoiceChannel struct {
Expand All @@ -944,6 +939,10 @@ type GuildStageVoiceChannel struct {
bitrate int
parentID *snowflake.ID
rtcRegion string
VideoQualityMode VideoQualityMode
lastMessageID *snowflake.ID
nsfw bool
rateLimitPerUser int
}

func (c *GuildStageVoiceChannel) UnmarshalJSON(data []byte) error {
Expand All @@ -960,6 +959,10 @@ func (c *GuildStageVoiceChannel) UnmarshalJSON(data []byte) error {
c.bitrate = v.Bitrate
c.parentID = v.ParentID
c.rtcRegion = v.RTCRegion
c.VideoQualityMode = v.VideoQualityMode
c.lastMessageID = v.LastMessageID
c.nsfw = v.NSFW
c.rateLimitPerUser = v.RateLimitPerUser
return nil
}

Expand All @@ -974,6 +977,10 @@ func (c GuildStageVoiceChannel) MarshalJSON() ([]byte, error) {
Bitrate: c.bitrate,
ParentID: c.parentID,
RTCRegion: c.rtcRegion,
VideoQualityMode: c.VideoQualityMode,
LastMessageID: c.lastMessageID,
NSFW: c.nsfw,
RateLimitPerUser: c.rateLimitPerUser,
})
}

Expand Down Expand Up @@ -1021,13 +1028,42 @@ func (c GuildStageVoiceChannel) ParentID() *snowflake.ID {
return c.parentID
}

func (c GuildStageVoiceChannel) LastMessageID() *snowflake.ID {
return c.lastMessageID
}

// LastPinTimestamp always returns nil for GuildStageVoiceChannel(s) as they cannot have pinned messages.
func (c GuildStageVoiceChannel) LastPinTimestamp() *time.Time {
return nil
}

// Topic always returns nil for GuildStageVoiceChannel(s) as they do not have their own topic.
func (c GuildStageVoiceChannel) Topic() *string {
return nil
}

func (c GuildStageVoiceChannel) NSFW() bool {
return c.nsfw
}

// DefaultAutoArchiveDuration is always 0 for GuildStageVoiceChannel(s) as they do not have their own AutoArchiveDuration.
func (c GuildStageVoiceChannel) DefaultAutoArchiveDuration() AutoArchiveDuration {
return 0
}

func (c GuildStageVoiceChannel) RateLimitPerUser() int {
return c.rateLimitPerUser
}

func (c GuildStageVoiceChannel) CreatedAt() time.Time {
return c.id.Time()
}

func (GuildStageVoiceChannel) channel() {}
func (GuildStageVoiceChannel) guildChannel() {}
func (GuildStageVoiceChannel) guildAudioChannel() {}
func (GuildStageVoiceChannel) channel() {}
func (GuildStageVoiceChannel) messageChannel() {}
func (GuildStageVoiceChannel) guildChannel() {}
func (GuildStageVoiceChannel) guildAudioChannel() {}
func (GuildStageVoiceChannel) guildMessageChannel() {}

var (
_ Channel = (*GuildForumChannel)(nil)
Expand Down Expand Up @@ -1386,9 +1422,6 @@ func ApplyLastPinTimestampToChannel(channel GuildMessageChannel, lastPinTimestam
case GuildTextChannel:
c.lastPinTimestamp = lastPinTimestamp
return c
case GuildVoiceChannel:
c.lastPinTimestamp = lastPinTimestamp
return c
case GuildNewsChannel:
c.lastPinTimestamp = lastPinTimestamp
return c
Expand Down
84 changes: 47 additions & 37 deletions discord/channel_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ var (
)

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

func (c GuildTextChannelCreate) Type() ChannelType {
Expand Down Expand Up @@ -57,12 +58,15 @@ var (

type GuildVoiceChannelCreate struct {
Name string `json:"name"`
Topic string `json:"topic,omitempty"`
Bitrate int `json:"bitrate,omitempty"`
UserLimit int `json:"user_limit,omitempty"`
RateLimitPerUser int `json:"rate_limit_per_user,omitempty"`
Position int `json:"position,omitempty"`
PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID snowflake.ID `json:"parent_id,omitempty"`
NSFW bool `json:"nsfw,omitempty"`
RTCRegion string `json:"rtc_region,omitempty"`
VideoQualityMode VideoQualityMode `json:"video_quality_mode,omitempty"`
}

func (c GuildVoiceChannelCreate) Type() ChannelType {
Expand Down Expand Up @@ -119,14 +123,15 @@ var (
)

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

func (c GuildNewsChannelCreate) Type() ChannelType {
Expand Down Expand Up @@ -154,12 +159,15 @@ var (

type GuildStageVoiceChannelCreate struct {
Name string `json:"name"`
Topic string `json:"topic,omitempty"`
Bitrate int `json:"bitrate,omitempty"`
UserLimit int `json:"user_limit,omitempty"`
RateLimitPerUser int `json:"rate_limit_per_user,omitempty"`
Position int `json:"position,omitempty"`
PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID snowflake.ID `json:"parent_id,omitempty"`
NSFW bool `json:"nsfw,omitempty"`
RTCRegion string `json:"rtc_region,omitempty"`
VideoQualityMode VideoQualityMode `json:"video_quality_mode,omitempty"`
}

func (c GuildStageVoiceChannelCreate) Type() ChannelType {
Expand All @@ -181,16 +189,17 @@ func (GuildStageVoiceChannelCreate) channelCreate() {}
func (GuildStageVoiceChannelCreate) guildChannelCreate() {}

type GuildForumChannelCreate struct {
Name string `json:"name"`
Topic string `json:"topic,omitempty"`
Position int `json:"position,omitempty"`
PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID snowflake.ID `json:"parent_id,omitempty"`
RateLimitPerUser int `json:"rate_limit_per_user"`
DefaultReactionEmoji DefaultReactionEmoji `json:"default_reaction_emoji"`
AvailableTags []ChannelTag `json:"available_tags"`
DefaultSortOrder DefaultSortOrder `json:"default_sort_order"`
DefaultForumLayout DefaultForumLayout `json:"default_forum_layout"`
Name string `json:"name"`
Topic string `json:"topic,omitempty"`
Position int `json:"position,omitempty"`
PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID snowflake.ID `json:"parent_id,omitempty"`
RateLimitPerUser int `json:"rate_limit_per_user,omitempty"`
DefaultReactionEmoji DefaultReactionEmoji `json:"default_reaction_emoji"`
AvailableTags []ChannelTag `json:"available_tags"`
DefaultSortOrder DefaultSortOrder `json:"default_sort_order"`
DefaultForumLayout DefaultForumLayout `json:"default_forum_layout"`
DefaultThreadRateLimitPerUser int `json:"default_thread_rate_limit_per_user,omitempty"`
}

func (c GuildForumChannelCreate) Type() ChannelType {
Expand All @@ -212,15 +221,16 @@ func (GuildForumChannelCreate) channelCreate() {}
func (GuildForumChannelCreate) guildChannelCreate() {}

type GuildMediaChannelCreate struct {
Name string `json:"name"`
Topic string `json:"topic,omitempty"`
Position int `json:"position,omitempty"`
PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID snowflake.ID `json:"parent_id,omitempty"`
RateLimitPerUser int `json:"rate_limit_per_user"`
DefaultReactionEmoji DefaultReactionEmoji `json:"default_reaction_emoji"`
AvailableTags []ChannelTag `json:"available_tags"`
DefaultSortOrder DefaultSortOrder `json:"default_sort_order"`
Name string `json:"name"`
Topic string `json:"topic,omitempty"`
Position int `json:"position,omitempty"`
PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID snowflake.ID `json:"parent_id,omitempty"`
RateLimitPerUser int `json:"rate_limit_per_user,omitempty"`
DefaultReactionEmoji DefaultReactionEmoji `json:"default_reaction_emoji"`
AvailableTags []ChannelTag `json:"available_tags"`
DefaultSortOrder DefaultSortOrder `json:"default_sort_order"`
DefaultThreadRateLimitPerUser int `json:"default_thread_rate_limit_per_user,omitempty"`
}

func (c GuildMediaChannelCreate) Type() ChannelType {
Expand Down
3 changes: 2 additions & 1 deletion discord/channel_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type GuildVoiceChannelUpdate struct {
PermissionOverwrites *[]PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
RTCRegion *string `json:"rtc_region,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
VideoQualityMode *VideoQualityMode `json:"video_quality_mode,omitempty"`
}

Expand Down Expand Up @@ -83,7 +84,7 @@ func (GuildThreadUpdate) guildChannelUpdate() {}
type GuildStageVoiceChannelUpdate struct {
Name *string `json:"name,omitempty"`
Position *int `json:"position,omitempty"`
Topic *string `json:"topic,omitempty"`
RateLimitPerUser *int `json:"rate_limit_per_user,omitempty"`
Bitrate *int `json:"bitrate,omitempty"`
UserLimit *int `json:"user_limit,omitempty"`
PermissionOverwrites *[]PermissionOverwrite `json:"permission_overwrites,omitempty"`
Expand Down
Loading

0 comments on commit f7f5744

Please sign in to comment.