From 78413bdb66e306f696f7f4c4ac609a0458dd6011 Mon Sep 17 00:00:00 2001 From: Borbot33 <58076174+Borbot33@users.noreply.github.com> Date: Sat, 22 Feb 2025 21:39:10 +0000 Subject: [PATCH 1/2] add poll --- lib/discordgo/structs.go | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/lib/discordgo/structs.go b/lib/discordgo/structs.go index 2edfcbf4b..a9b772ebc 100644 --- a/lib/discordgo/structs.go +++ b/lib/discordgo/structs.go @@ -1761,6 +1761,57 @@ type AutoModerationAction struct { Metadata *AutoModerationActionMetadata `json:"metadata,omitempty"` } +// PollLayoutType represents the layout of a poll. +type PollLayoutType int + +// Valid PollLayoutType values. +const ( + PollLayoutTypeDefault PollLayoutType = 1 +) + +// PollMedia contains common data used by question and answers. +type PollMedia struct { + Text string `json:"text,omitempty"` + Emoji *ComponentEmoji `json:"emoji,omitempty"` // TODO: rename the type +} + +// PollAnswer represents a single answer in a poll. +type PollAnswer struct { + // NOTE: should not be set on creation. + AnswerID int `json:"answer_id,omitempty"` + Media *PollMedia `json:"poll_media"` +} + +// PollAnswerCount stores counted poll votes for a single answer. +type PollAnswerCount struct { + ID int `json:"id"` + Count int `json:"count"` + MeVoted bool `json:"me_voted"` +} + +// PollResults contains voting results on a poll. +type PollResults struct { + Finalized bool `json:"is_finalized"` + AnswerCounts []*PollAnswerCount `json:"answer_counts"` +} + +// Poll contains all poll related data. +type Poll struct { + Question PollMedia `json:"question"` + Answers []PollAnswer `json:"answers"` + AllowMultiselect bool `json:"allow_multiselect"` + LayoutType PollLayoutType `json:"layout_type,omitempty"` + + // NOTE: should be set only on creation, when fetching use Expiry. + Duration int `json:"duration,omitempty"` + + // NOTE: available only when fetching. + + Results *PollResults `json:"results,omitempty"` + // NOTE: as Discord documentation notes, this field might be null even when fetching. + Expiry *time.Time `json:"expiry,omitempty"` +} + type SKUType int // Valid SKUType values From 20d6ff6a1a026500ebd31670bf8143785ae10257 Mon Sep 17 00:00:00 2001 From: Borbot33 <58076174+Borbot33@users.noreply.github.com> Date: Sat, 22 Feb 2025 21:39:38 +0000 Subject: [PATCH 2/2] added poll --- lib/discordgo/message.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/discordgo/message.go b/lib/discordgo/message.go index 6e2157a46..bdaf0f7f9 100644 --- a/lib/discordgo/message.go +++ b/lib/discordgo/message.go @@ -167,6 +167,9 @@ type Message struct { // An array of StickerItem objects, is the message contains any. StickerItems []*StickerItem `json:"sticker_items"` ApplicationID int64 `json:"application_id,string"` + + // Poll object + Poll *Poll `json:"poll"` } type MessageSnapshot struct { @@ -272,6 +275,7 @@ type MessageSend struct { Reference *MessageReference `json:"message_reference,omitempty"` Flags MessageFlags `json:"flags,omitempty"` StickerIDs []int64 `json:"sticker_ids"` + Poll *Poll `json:"poll,omitempty"` // TODO: Remove this when compatibility is not required. File *File `json:"-"`