Skip to content

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

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

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
78413bd
add poll
Borbot33 Feb 22, 2025
20d6ff6
added poll
Borbot33 Feb 22, 2025
145471b
add poll to the message state
Borbot33 Mar 14, 2025
06e79e2
fix indentation
Borbot33 Mar 14, 2025
f07d3c9
Update helpers.go
Borbot33 Mar 18, 2025
68d0599
Update helpers.go
Borbot33 Mar 18, 2025
62062d3
build(deps): bump golang.org/x/net from 0.33.0 to 0.36.0 (#1854)
dependabot[bot] Mar 18, 2025
57dc3ec
templates: prevent writing leading and trailing whitespace (#1855)
SoggySaussages Mar 18, 2025
8147df4
Replace username triggers with globalname triggers as username trigge…
ashishjh-bst Mar 18, 2025
cbd5220
Disabled execCC for cron type custom commands (#1857)
ashishjh-bst Mar 18, 2025
0db45cf
Fix automod not working on content that is query escaped (#1858)
ashishjh-bst Mar 18, 2025
945a8a2
strip all invites from dms in message content (#1859)
ashishjh-bst Mar 18, 2025
50fbdbe
added messages forwards to ticket transcripts (#1860)
ashishjh-bst Mar 19, 2025
acca6e2
Revert "templates: prevent writing leading and trailing whitespace (#…
ashishjh-bst Mar 19, 2025
7d396e2
missed it when disabling for execCC (#1863)
ashishjh-bst Mar 20, 2025
4dd808e
fixed issue with missing text from regular messages in ticket transcript
ashishjh-bst Mar 21, 2025
4ebbca3
Fix typo in tmplRoleDropdownMulti web function name (#1867)
H1nr1 Apr 9, 2025
77ad3d8
templates: fix whitespace trim (#1862)
SoggySaussages Apr 9, 2025
58cec0d
templates: add absolute math operator (#1864)
SoggySaussages Apr 9, 2025
3d8bc35
dgo/dstate: add RoleSubscriptionData to Message struct (#1865)
May 11, 2025
48cf9e8
Reddit: add up/down vote counts to non-embed slow feed (#1866)
H1nr1 Apr 9, 2025
93e87cb
added fixed advice list (#1868)
ashishjh-bst Apr 9, 2025
c810828
web: also list stage channels in channel list (#1869)
l-zeuch Apr 9, 2025
9529c13
since the advice api is back, added the list as a fallback (#1870)
ashishjh-bst Apr 9, 2025
9fb5e5b
report: optionally mention roles upon report (#1871)
SoggySaussages Apr 20, 2025
d3ae4b9
templates: add suppress embeds to complexMessage(Edit) (#1873)
SoggySaussages Apr 20, 2025
8947f5d
rolecommands: elaborate on cooldown message (#1876)
SoggySaussages Apr 20, 2025
79b7179
cc/interactions: add response deferral (#1872)
SoggySaussages Apr 25, 2025
0b1f155
build(deps): bump golang.org/x/net from 0.36.0 to 0.38.0 (#1874)
dependabot[bot] Apr 25, 2025
220288c
discordgo: add v2 components (#1879)
SoggySaussages Apr 25, 2025
68863cb
moderation: record moderator in audit log for bulk delete (#1878)
l-zeuch Apr 25, 2025
e099087
cc: attach long dcct output as file (#1881)
jo3-l Apr 28, 2025
abab907
Revert "discordgo: add v2 components (#1879)" (#1882)
ashishjh-bst May 2, 2025
59a345d
customcommands: remove 1k limit on evalcc (#1883)
l-zeuch May 2, 2025
12b554c
templates: properly edit message flags in tmplEditMessage (#1885)
l-zeuch May 5, 2025
b17b840
Fixes for patreon sending incorrect data in entitled cents (#1886)
ashishjh-bst May 5, 2025
21d1b5f
Fixes to advanced automod's discord automod trigger (#1887)
ashishjh-bst May 7, 2025
b5244dd
general: add v2 components (#1884)
SoggySaussages May 7, 2025
2d4412f
fixed missing string specifier in struct tag (#1888)
ashishjh-bst May 7, 2025
ce50ab5
templates: add ability to send v2 components (#1880)
SoggySaussages May 9, 2025
9059182
added poll
Borbot33 Feb 22, 2025
fda212b
Merge branch 'dev' into add-poll-struct
Borbot33 May 11, 2025
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 @@ -169,6 +169,9 @@ type Message struct {
StickerItems []*StickerItem `json:"sticker_items"`
ApplicationID int64 `json:"application_id,string"`

// Poll object
Poll *Poll `json:"poll"`

// Data of the role subscription purchase or renewal that prompted this role subscription message.
RoleSubscriptionData *RoleSubscriptionData `json:"role_subscription_data,omitempty"`
}
Expand Down Expand Up @@ -301,6 +304,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
1 change: 1 addition & 0 deletions lib/dstate/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func MessageStateFromDgo(m *discordgo.Message) *MessageState {
Content: m.Content,
MessageSnapshots: convertMessageSnapshots(m.MessageSnapshots),
Embeds: embeds,
Poll: m.poll,
Mentions: mentions,
Attachments: attachments,
MentionRoles: m.MentionRoles,
Expand Down
1 change: 1 addition & 0 deletions lib/dstate/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ type MessageState struct {
MentionRoles []int64
Attachments []discordgo.MessageAttachment
Stickers []discordgo.Sticker
Poll *discordgo.Poll
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work, take reference of messageForwards support, you'll also have to add helpers to convert poll to value from pointer when saving to state.

Reference PR

https://github.com/botlabs-gg/yagpdb/pull/1744/files#diff-07490940a040da9cec20ec7da7c3a8a1b62c3b90dae49a44aef9f40fa1c506a6


ParsedCreatedAt time.Time
ParsedEditedAt time.Time
Expand Down