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 new fields to Attachment and Embed #410

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions discord/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ import (

// Attachment is used for files sent in a Message
type Attachment struct {
ID snowflake.ID `json:"id,omitempty"`
Filename string `json:"filename,omitempty"`
Title *string `json:"title,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"`
ID snowflake.ID `json:"id,omitempty"`
Filename string `json:"filename,omitempty"`
Title *string `json:"title,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"`
ClipParticipants []User `json:"clip_participants,omitempty"`
ClipCreatedAt *time.Time `json:"clip_created_at,omitempty"`
Application *Application `json:"application,omitempty"`
}

func (a Attachment) CreatedAt() time.Time {
Expand All @@ -34,6 +37,9 @@ const (
AttachmentFlagIsClip AttachmentFlags = 1 << iota
AttachmentFlagIsThumbnail
AttachmentFlagIsRemix
AttachmentFlagIsSpoiler
AttachmentFlagContainsExplicitMedia
AttachmentFlagIsAnimated
AttachmentFlagsNone AttachmentFlags = 0
)

Expand Down
25 changes: 21 additions & 4 deletions discord/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Embed struct {
Provider *EmbedProvider `json:"provider,omitempty"`
Author *EmbedAuthor `json:"author,omitempty"`
Fields []EmbedField `json:"fields,omitempty"`
Flags EmbedFlags `json:"flags,omitempty"`
}

func (e Embed) FindField(fieldFindFunc func(field EmbedField) bool) (EmbedField, bool) {
Expand All @@ -53,14 +54,30 @@ func (e Embed) FindAllFields(fieldFindFunc func(field EmbedField) bool) []EmbedF
return fields
}

type EmbedFlags int

const (
EmbedFlagContainsExplicitMedia EmbedFlags = 1 << (iota + 4)
EmbedFlagIsContentInventoryEntry
EmbedFlagsNone EmbedFlags = 0
)

// The EmbedResource of an Embed.Image/Embed.Thumbnail/Embed.Video
type EmbedResource struct {
URL string `json:"url,omitempty"`
ProxyURL string `json:"proxy_url,omitempty"`
Height int `json:"height,omitempty"`
Width int `json:"width,omitempty"`
URL string `json:"url,omitempty"`
ProxyURL string `json:"proxy_url,omitempty"`
Height int `json:"height,omitempty"`
Width int `json:"width,omitempty"`
Flags EmbedResourceFlags `json:"flags,omitempty"`
}

type EmbedResourceFlags int

const (
EmbedResourceFlagIsAnimated EmbedResourceFlags = 1 << 5
EmbedResourceFlagsNone EmbedResourceFlags = 0
)

// The EmbedProvider of an Embed
type EmbedProvider struct {
Name string `json:"name,omitempty"`
Expand Down
Loading