-
Notifications
You must be signed in to change notification settings - Fork 469
/
poll.go
80 lines (66 loc) · 2.41 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
71
72
73
74
75
76
77
78
79
80
package telebot
import "time"
// PollType defines poll types.
type PollType string
const (
// NOTE:
// Despite "any" type isn't described in documentation,
// it needed for proper KeyboardButtonPollType marshaling.
PollAny PollType = "any"
PollQuiz PollType = "quiz"
PollRegular PollType = "regular"
)
// Poll contains information about a poll.
type Poll struct {
ID string `json:"id"`
Type PollType `json:"type"`
Question string `json:"question"`
Options []PollOption `json:"options"`
VoterCount int `json:"total_voter_count"`
// (Optional)
Closed bool `json:"is_closed,omitempty"`
CorrectOption int `json:"correct_option_id,omitempty"`
MultipleAnswers bool `json:"allows_multiple_answers,omitempty"`
Explanation string `json:"explanation,omitempty"`
ParseMode ParseMode `json:"explanation_parse_mode,omitempty"`
Entities []MessageEntity `json:"explanation_entities,omitempty"`
QuestionParseMode string `json:"question_parse_mode,omitempty"`
QuestionEntities []MessageEntity `json:"question_entities,omitempty"`
// True by default, shouldn't be omitted.
Anonymous bool `json:"is_anonymous"`
// (Mutually exclusive)
OpenPeriod int `json:"open_period,omitempty"`
CloseUnixdate int64 `json:"close_date,omitempty"`
}
// PollOption contains information about one answer option in a poll.
type PollOption struct {
Text string `json:"text"`
VoterCount int `json:"voter_count"`
ParseMode ParseMode `json:"text_parse_mode,omitempty"`
Entities []MessageEntity `json:"text_entities,omitempty"`
}
// PollAnswer represents an answer of a user in a non-anonymous poll.
type PollAnswer struct {
PollID string `json:"poll_id"`
Sender *User `json:"user"`
Chat *Chat `json:"voter_chat"`
Options []int `json:"option_ids"`
}
// IsRegular says whether poll is a regular.
func (p *Poll) IsRegular() bool {
return p.Type == PollRegular
}
// IsQuiz says whether poll is a quiz.
func (p *Poll) IsQuiz() bool {
return p.Type == PollQuiz
}
// CloseDate returns the close date of poll in local time.
func (p *Poll) CloseDate() time.Time {
return time.Unix(p.CloseUnixdate, 0)
}
// AddOptions adds text options to the poll.
func (p *Poll) AddOptions(opts ...string) {
for _, t := range opts {
p.Options = append(p.Options, PollOption{Text: t})
}
}