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

Added poll to the Message object [Suggestion #2201] #1850

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions lib/discordgo/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:"-"`
Expand Down
51 changes: 51 additions & 0 deletions lib/discordgo/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down