From 849b9768c745f973b26e480e6820e21f204d1abf Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Fri, 2 Aug 2024 21:47:09 +0200 Subject: [PATCH 1/2] Add poll result messages --- discord/embed.go | 13 +++++++------ discord/message.go | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/discord/embed.go b/discord/embed.go index 3de752ff1..d85b6e0ca 100644 --- a/discord/embed.go +++ b/discord/embed.go @@ -7,12 +7,13 @@ type EmbedType string // Constants for EmbedType const ( - EmbedTypeRich EmbedType = "rich" - EmbedTypeImage EmbedType = "image" - EmbedTypeVideo EmbedType = "video" - EmbedTypeGifV EmbedType = "rich" - EmbedTypeArticle EmbedType = "article" - EmbedTypeLink EmbedType = "link" + EmbedTypeRich EmbedType = "rich" + EmbedTypeImage EmbedType = "image" + EmbedTypeVideo EmbedType = "video" + EmbedTypeGifV EmbedType = "rich" + EmbedTypeArticle EmbedType = "article" + EmbedTypeLink EmbedType = "link" + EmbedTypePollResult EmbedType = "poll_result" ) // Embed allows you to send embeds to discord diff --git a/discord/message.go b/discord/message.go index d83a06e25..dcf830e84 100644 --- a/discord/message.go +++ b/discord/message.go @@ -48,7 +48,9 @@ const ( _ MessageTypeStageTopic MessageTypeGuildApplicationPremiumSubscription - MessageTypePurchaseNotification MessageType = 44 + MessageTypePurchaseNotification MessageType = iota + 11 + _ + MessageTypePollResult ) func (t MessageType) System() bool { From 58ee736ea414b877a8f2a8da659b16d380a90b1a Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:32:53 +0200 Subject: [PATCH 2/2] add find helper funcs + poll result consts --- discord/embed.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/discord/embed.go b/discord/embed.go index 079ec7b46..30512902f 100644 --- a/discord/embed.go +++ b/discord/embed.go @@ -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"` @@ -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" +)