telebot/poll.go
2020-03-30 19:21:06 +03:00

48 lines
1.5 KiB
Go

package telebot
// Poll object represents a poll, it contains information about a poll.
type Poll struct {
ID string `json:"id"`
Question string `json:"question"`
Options []PollOption `json:"options"`
TotalVoterCount int `json:"total_voter_count"`
IsClosed bool `json:"is_closed"`
IsAnonymous bool `json:"is_anonymous"`
Type string `json:"type"`
AllowsMultipleAnswers bool `json:"allows_multiple_answers"`
// Optional. 0-based identifier of the correct answer option.
// Available only for polls in the quiz mode, which are closed,
// or was sent (not forwarded) by the bot or to the private chat with the bot.
CorrectOptionID int `json:"correct_option_id"`
}
// PollOption object represents a option of a poll
type PollOption struct {
Text string `json:"text"`
VoterCount int `json:"voter_count"`
}
// PollAnswer object represents an answer of a user in a non-anonymous poll.
type PollAnswer struct {
PollID string `json:"poll_id"`
User User `json:"user"`
// 0-based identifiers of answer options, chosen by the user. May be empty if the user retracted their vote.
OptionIDs []int `json:"option_ids"`
}
func (p *Poll) IsRegular() bool {
return p.Type == "regular"
}
func (p *Poll) IsQuiz() bool {
return p.Type == "quiz"
}
func (p *Poll) AddAnswers(text ...string) {
for _, t := range text {
p.Options = append(p.Options, PollOption{Text: t})
}
}