2020-04-24 14:52:15 +00:00
|
|
|
package telebot
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
2022-10-05 21:45:27 +00:00
|
|
|
// 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"
|
|
|
|
)
|
|
|
|
|
2020-04-24 14:52:15 +00:00
|
|
|
// 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"`
|
|
|
|
|
|
|
|
// 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"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// PollAnswer represents an answer of a user in a non-anonymous poll.
|
|
|
|
type PollAnswer struct {
|
|
|
|
PollID string `json:"poll_id"`
|
2020-06-19 20:34:37 +00:00
|
|
|
Sender *User `json:"user"`
|
2024-02-28 15:58:27 +00:00
|
|
|
Chat *Chat `json:"voter_chat"`
|
2020-04-24 14:52:15 +00:00
|
|
|
Options []int `json:"option_ids"`
|
|
|
|
}
|
|
|
|
|
2020-04-26 12:42:25 +00:00
|
|
|
// IsRegular says whether poll is a regular.
|
2020-04-24 14:52:15 +00:00
|
|
|
func (p *Poll) IsRegular() bool {
|
|
|
|
return p.Type == PollRegular
|
|
|
|
}
|
|
|
|
|
2020-05-21 09:02:35 +00:00
|
|
|
// IsQuiz says whether poll is a quiz.
|
2020-04-24 14:52:15 +00:00
|
|
|
func (p *Poll) IsQuiz() bool {
|
|
|
|
return p.Type == PollQuiz
|
|
|
|
}
|
|
|
|
|
2020-04-26 12:42:25 +00:00
|
|
|
// CloseDate returns the close date of poll in local time.
|
2020-04-24 14:52:15 +00:00
|
|
|
func (p *Poll) CloseDate() time.Time {
|
|
|
|
return time.Unix(p.CloseUnixdate, 0)
|
|
|
|
}
|
|
|
|
|
2020-04-26 12:42:25 +00:00
|
|
|
// AddOptions adds text options to the poll.
|
2020-04-24 14:52:15 +00:00
|
|
|
func (p *Poll) AddOptions(opts ...string) {
|
|
|
|
for _, t := range opts {
|
|
|
|
p.Options = append(p.Options, PollOption{Text: t})
|
|
|
|
}
|
|
|
|
}
|