-
Notifications
You must be signed in to change notification settings - Fork 35
/
poll.go
70 lines (58 loc) · 1.67 KB
/
poll.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package discord
import (
"time"
"github.com/disgoorg/json"
"github.com/disgoorg/snowflake/v2"
)
type Poll struct {
Question PollMedia `json:"question"`
Answers []PollAnswer `json:"answers"`
Expiry *time.Time `json:"expiry"`
AllowMultiselect bool `json:"allow_multiselect"`
LayoutType PollLayoutType `json:"layout_type"`
Results *PollResults `json:"results"`
}
type PollCreate struct {
Question PollMedia `json:"question"`
Answers []PollMedia `json:"-"`
Duration int `json:"duration"`
AllowMultiselect bool `json:"allow_multiselect"`
LayoutType PollLayoutType `json:"layout_type,omitempty"`
}
func (p PollCreate) MarshalJSON() ([]byte, error) {
type pollCreate PollCreate
answers := make([]PollAnswer, 0, len(p.Answers))
for _, answer := range p.Answers {
answers = append(answers, PollAnswer{
PollMedia: answer,
})
}
return json.Marshal(struct {
Answers []PollAnswer `json:"answers"`
pollCreate
}{
Answers: answers,
pollCreate: pollCreate(p),
})
}
type PollMedia struct {
Text *string `json:"text"`
Emoji *PartialEmoji `json:"emoji,omitempty"`
}
type PollAnswer struct {
AnswerID *int `json:"answer_id,omitempty"`
PollMedia PollMedia `json:"poll_media"`
}
type PollResults struct {
IsFinalized bool `json:"is_finalized"`
AnswerCounts []PollAnswerCount `json:"answer_counts"`
}
type PollAnswerCount struct {
ID snowflake.ID `json:"id"`
Count int `json:"count"`
MeVoted bool `json:"me_voted"`
}
type PollLayoutType int
const (
PollLayoutTypeDefault PollLayoutType = iota + 1
)