Skip to content

Commit

Permalink
add find helper funcs + poll result consts
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 committed Aug 16, 2024
1 parent f09d5ef commit 58ee736
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions discord/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ type Embed struct {
Fields []EmbedField `json:"fields,omitempty"`
}

func (e Embed) FindField(fieldFindFunc func(field EmbedField) bool) (EmbedField, bool) {
for _, field := range e.Fields {
if fieldFindFunc(field) {
return field, true
}
}
return EmbedField{}, false
}

func (e Embed) FindAllFields(fieldFindFunc func(field EmbedField) bool) []EmbedField {
var fields []EmbedField
for _, field := range e.Fields {
if fieldFindFunc(field) {
fields = append(fields, field)
}
}
return fields
}

// The EmbedResource of an Embed.Image/Embed.Thumbnail/Embed.Video
type EmbedResource struct {
URL string `json:"url,omitempty"`
Expand Down Expand Up @@ -69,3 +88,16 @@ type EmbedField struct {
Value string `json:"value"`
Inline *bool `json:"inline,omitempty"`
}

type EmbedFieldPollResult string

const (
EmbedFieldPollResultQuestionText EmbedFieldPollResult = "poll_question_text"
EmbedFieldPollResultVictorAnswerVotes EmbedFieldPollResult = "victor_answer_votes"
EmbedFieldPollResultTotalVotes EmbedFieldPollResult = "total_votes"
EmbedFieldPollResultVictorAnswerID EmbedFieldPollResult = "victor_answer_id"
EmbedFieldPollResultVictorAnswerText EmbedFieldPollResult = "victor_answer_text"
EmbedFieldPollResultVictorAnswerEmojiID EmbedFieldPollResult = "victor_answer_emoji_id"
EmbedFieldPollResultVictorAnswerEmojiName EmbedFieldPollResult = "victor_answer_emoji_name"
EmbedFieldPollResultVictorAnswerEmojiAnimated EmbedFieldPollResult = "victor_answer_emoji_animated"
)

0 comments on commit 58ee736

Please sign in to comment.