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 poll result messages #374

Merged
merged 3 commits into from
Aug 16, 2024
Merged
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
33 changes: 33 additions & 0 deletions discord/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
EmbedTypeArticle EmbedType = "article"
EmbedTypeLink EmbedType = "link"
EmbedTypeAutoModerationMessage EmbedType = "auto_moderation_message"
EmbedTypePollResult EmbedType = "poll_result"
)

// Embed allows you to send embeds to discord
Expand All @@ -33,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 @@ -68,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"
)
4 changes: 3 additions & 1 deletion discord/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const (
_
MessageTypeStageTopic
MessageTypeGuildApplicationPremiumSubscription
MessageTypePurchaseNotification MessageType = 44
MessageTypePurchaseNotification MessageType = iota + 11
_
MessageTypePollResult
)

func (t MessageType) System() bool {
Expand Down
Loading