Skip to content

Commit

Permalink
Merge branch 'master' into experiments/event-refactor
Browse files Browse the repository at this point in the history
# Conflicts:
#	events/dm_message_reaction_events.go
#	events/guild_message_reaction_events.go
#	handlers/message_reaction_handler.go
#	oauth2/client_impl.go
  • Loading branch information
topi314 committed Aug 5, 2023
2 parents acc9165 + b0885de commit 57544d5
Show file tree
Hide file tree
Showing 29 changed files with 456 additions and 100 deletions.
12 changes: 12 additions & 0 deletions cache/caches.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@ type Caches interface {

// GuildForumChannel returns a discord.GuildForumChannel from the ChannelCache and a bool indicating if it exists.
GuildForumChannel(channelID snowflake.ID) (discord.GuildForumChannel, bool)

// GuildMediaChannel returns a discord.GuildMediaChannel from the ChannelCache and a bool indicating if it exists.
GuildMediaChannel(channelID snowflake.ID) (discord.GuildMediaChannel, bool)
}

// New returns a new default Caches instance with the given ConfigOpt(s) applied.
Expand Down Expand Up @@ -1347,3 +1350,12 @@ func (c *cachesImpl) GuildForumChannel(channelID snowflake.ID) (discord.GuildFor
}
return discord.GuildForumChannel{}, false
}

func (c *cachesImpl) GuildMediaChannel(channelID snowflake.ID) (discord.GuildMediaChannel, bool) {
if ch, ok := c.Channel(channelID); ok {
if cCh, ok := ch.(discord.GuildMediaChannel); ok {
return cCh, true
}
}
return discord.GuildMediaChannel{}, false
}
34 changes: 22 additions & 12 deletions discord/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,34 @@ import (

// Attachment is used for files sent in a Message
type Attachment struct {
ID snowflake.ID `json:"id,omitempty"`
Filename string `json:"filename,omitempty"`
Description *string `json:"description,omitempty"`
ContentType *string `json:"content_type,omitempty"`
Size int `json:"size,omitempty"`
URL string `json:"url,omitempty"`
ProxyURL string `json:"proxy_url,omitempty"`
Height *int `json:"height,omitempty"`
Width *int `json:"width,omitempty"`
Ephemeral bool `json:"ephemeral,omitempty"`
DurationSecs *float64 `json:"duration_secs,omitempty"`
Waveform *string `json:"waveform,omitempty"`
ID snowflake.ID `json:"id,omitempty"`
Filename string `json:"filename,omitempty"`
Description *string `json:"description,omitempty"`
ContentType *string `json:"content_type,omitempty"`
Size int `json:"size,omitempty"`
URL string `json:"url,omitempty"`
ProxyURL string `json:"proxy_url,omitempty"`
Height *int `json:"height,omitempty"`
Width *int `json:"width,omitempty"`
Ephemeral bool `json:"ephemeral,omitempty"`
DurationSecs *float64 `json:"duration_secs,omitempty"`
Waveform *string `json:"waveform,omitempty"`
Flags AttachmentFlags `json:"flags"`
}

func (a Attachment) CreatedAt() time.Time {
return a.ID.Time()
}

type AttachmentFlags int

const (
AttachmentFlagIsClip AttachmentFlags = 1 << iota
AttachmentFlagIsThumbnail
AttachmentFlagIsRemix
AttachmentFlagsNone AttachmentFlags = 0
)

type AttachmentUpdate interface {
attachmentUpdate()
}
Expand Down
5 changes: 5 additions & 0 deletions discord/audit_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ const (
AuditLogAutoModerationUserCommunicationDisabled
)

const (
AuditLogCreatorMonetizationRequestCreated AuditLogEvent = iota + 150
AuditLogCreatorMonetizationTermsAccepted
)

// AuditLog (https://discord.com/developers/docs/resources/audit-log) These are logs of events that occurred, accessible via the Discord
type AuditLog struct {
ApplicationCommands []ApplicationCommand `json:"application_commands"`
Expand Down
2 changes: 2 additions & 0 deletions discord/cdn_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var (

MemberAvatar = NewCDN("/guilds/{guild.id}/users/{user.id}/avatars/{member.avatar.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP, FileFormatGIF)

UserAvatarDecoration = NewCDN("/avatar-decorations/{user.id}/{user.avatar.decoration.hash}", FileFormatPNG)

ApplicationIcon = NewCDN("/app-icons/{application.id}/{icon.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP)
ApplicationCover = NewCDN("/app-assets/{application.id}/{cover.image.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP)
ApplicationAsset = NewCDN("/app-assets/{application.id}/{asset.id}", FileFormatPNG, FileFormatJPEG, FileFormatWebP)
Expand Down
133 changes: 127 additions & 6 deletions discord/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
ChannelTypeGuildStageVoice
ChannelTypeGuildDirectory
ChannelTypeGuildForum
ChannelTypeGuildMedia
)

type ChannelFlags int
Expand All @@ -40,7 +41,8 @@ const (
_
_
ChannelFlagRequireTag
ChannelFlagsNone ChannelFlags = 0
ChannelFlagHideMediaDownloadOptions ChannelFlags = 1 << 15
ChannelFlagsNone ChannelFlags = 0
)

// Add allows you to add multiple bits together, producing a new bit
Expand Down Expand Up @@ -208,6 +210,11 @@ func (u *UnmarshalChannel) UnmarshalJSON(data []byte) error {
err = json.Unmarshal(data, &v)
channel = v

case ChannelTypeGuildMedia:
var v GuildMediaChannel
err = json.Unmarshal(data, &v)
channel = v

default:
err = fmt.Errorf("unknown channel with type %d received", cType.Type)
}
Expand Down Expand Up @@ -1034,12 +1041,12 @@ type GuildForumChannel struct {
permissionOverwrites PermissionOverwrites
name string
parentID *snowflake.ID
LastThreadID *snowflake.ID
LastPostID *snowflake.ID
Topic *string
NSFW bool
RateLimitPerUser int
Flags ChannelFlags
AvailableTags []ForumTag
AvailableTags []ChannelTag
DefaultReactionEmoji *DefaultReactionEmoji
DefaultThreadRateLimitPerUser int
DefaultSortOrder *DefaultSortOrder
Expand All @@ -1058,7 +1065,7 @@ func (c *GuildForumChannel) UnmarshalJSON(data []byte) error {
c.permissionOverwrites = v.PermissionOverwrites
c.name = v.Name
c.parentID = v.ParentID
c.LastThreadID = v.LastThreadID
c.LastPostID = v.LastPostID
c.Topic = v.Topic
c.NSFW = v.NSFW
c.RateLimitPerUser = v.RateLimitPerUser
Expand All @@ -1080,7 +1087,7 @@ func (c GuildForumChannel) MarshalJSON() ([]byte, error) {
PermissionOverwrites: c.permissionOverwrites,
Name: c.name,
ParentID: c.parentID,
LastThreadID: c.LastThreadID,
LastPostID: c.LastPostID,
Topic: c.Topic,
NSFW: c.NSFW,
RateLimitPerUser: c.RateLimitPerUser,
Expand Down Expand Up @@ -1136,6 +1143,117 @@ func (c GuildForumChannel) CreatedAt() time.Time {
func (GuildForumChannel) channel() {}
func (GuildForumChannel) guildChannel() {}

var (
_ Channel = (*GuildMediaChannel)(nil)
_ GuildChannel = (*GuildMediaChannel)(nil)
)

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

func (c *GuildMediaChannel) UnmarshalJSON(data []byte) error {
var v guildMediaChannel
if err := json.Unmarshal(data, &v); err != nil {
return err
}

c.id = v.ID
c.guildID = v.GuildID
c.position = v.Position
c.permissionOverwrites = v.PermissionOverwrites
c.name = v.Name
c.parentID = v.ParentID
c.LastPostID = v.LastPostID
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
c.DefaultSortOrder = v.DefaultSortOrder
return nil
}

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

func (c GuildMediaChannel) String() string {
return channelString(c)
}

func (c GuildMediaChannel) Mention() string {
return ChannelMention(c.ID())
}

func (GuildMediaChannel) Type() ChannelType {
return ChannelTypeGuildMedia
}

func (c GuildMediaChannel) ID() snowflake.ID {
return c.id
}

func (c GuildMediaChannel) Name() string {
return c.name
}

func (c GuildMediaChannel) GuildID() snowflake.ID {
return c.guildID
}

func (c GuildMediaChannel) PermissionOverwrites() PermissionOverwrites {
return c.permissionOverwrites
}

func (c GuildMediaChannel) Position() int {
return c.position
}

func (c GuildMediaChannel) ParentID() *snowflake.ID {
return c.parentID
}

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

func (GuildMediaChannel) channel() {}
func (GuildMediaChannel) guildChannel() {}

type FollowedChannel struct {
ChannelID snowflake.ID `json:"channel_id"`
WebhookID snowflake.ID `json:"webhook_id"`
Expand Down Expand Up @@ -1167,7 +1285,7 @@ type ThreadMetadata struct {
CreateTimestamp time.Time `json:"create_timestamp"`
}

type ForumTag struct {
type ChannelTag struct {
ID snowflake.ID `json:"id"`
Name string `json:"name"`
Moderated bool `json:"moderated"`
Expand Down Expand Up @@ -1236,6 +1354,9 @@ func ApplyGuildIDToChannel(channel GuildChannel, guildID snowflake.ID) GuildChan
case GuildForumChannel:
c.guildID = guildID
return c
case GuildMediaChannel:
c.guildID = guildID
return c
default:
return channel
}
Expand Down
32 changes: 31 additions & 1 deletion discord/channel_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ type GuildForumChannelCreate struct {
ParentID snowflake.ID `json:"parent_id,omitempty"`
RateLimitPerUser int `json:"rate_limit_per_user"`
DefaultReactionEmoji DefaultReactionEmoji `json:"default_reaction_emoji"`
AvailableTags []ForumTag `json:"available_tags"`
AvailableTags []ChannelTag `json:"available_tags"`
DefaultSortOrder DefaultSortOrder `json:"default_sort_order"`
DefaultForumLayout DefaultForumLayout `json:"default_forum_layout"`
}
Expand All @@ -211,6 +211,36 @@ func (c GuildForumChannelCreate) MarshalJSON() ([]byte, error) {
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"`
}

func (c GuildMediaChannelCreate) Type() ChannelType {
return ChannelTypeGuildMedia
}

func (c GuildMediaChannelCreate) MarshalJSON() ([]byte, error) {
type guildMediaChannelCreate GuildMediaChannelCreate
return json.Marshal(struct {
Type ChannelType `json:"type"`
guildMediaChannelCreate
}{
Type: c.Type(),
guildMediaChannelCreate: guildMediaChannelCreate(c),
})
}

func (GuildMediaChannelCreate) channelCreate() {}
func (GuildMediaChannelCreate) guildChannelCreate() {}

type DMChannelCreate struct {
RecipientID snowflake.ID `json:"recipient_id"`
}
26 changes: 22 additions & 4 deletions discord/channel_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type GuildForumChannelUpdate struct {
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"`
AvailableTags *[]ChannelTag `json:"available_tags,omitempty"`
Flags *ChannelFlags `json:"flags,omitempty"`
DefaultReactionEmoji *json.Nullable[DefaultReactionEmoji] `json:"default_reaction_emoji,omitempty"`
DefaultThreadRateLimitPerUser *int `json:"default_thread_rate_limit_per_user,omitempty"`
Expand All @@ -115,7 +115,25 @@ type GuildForumChannelUpdate struct {
func (GuildForumChannelUpdate) channelUpdate() {}
func (GuildForumChannelUpdate) guildChannelUpdate() {}

type GuildForumThreadChannelUpdate struct {
type GuildMediaChannelUpdate struct {
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 *[]ChannelTag `json:"available_tags,omitempty"`
Flags *ChannelFlags `json:"flags,omitempty"`
DefaultReactionEmoji *json.Nullable[DefaultReactionEmoji] `json:"default_reaction_emoji,omitempty"`
DefaultThreadRateLimitPerUser *int `json:"default_thread_rate_limit_per_user,omitempty"`
DefaultSortOrder *json.Nullable[DefaultSortOrder] `json:"default_sort_order,omitempty"`
}

func (GuildMediaChannelUpdate) channelUpdate() {}
func (GuildMediaChannelUpdate) guildChannelUpdate() {}

type GuildPostUpdate struct {
Name *string `json:"name,omitempty"`
Archived *bool `json:"archived,omitempty"`
AutoArchiveDuration *AutoArchiveDuration `json:"auto_archive_duration,omitempty"`
Expand All @@ -126,8 +144,8 @@ type GuildForumThreadChannelUpdate struct {
AppliedTags *[]snowflake.ID `json:"applied_tags,omitempty"`
}

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

type GuildChannelPositionUpdate struct {
ID snowflake.ID `json:"id"`
Expand Down
Loading

0 comments on commit 57544d5

Please sign in to comment.