1
0

👽 Updated code to support BotAPI v4.8

This commit is contained in:
Maxim Lebedev 2020-05-08 20:45:09 +05:00
parent 09c0fe0ba0
commit 7fbdcd2534
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
4 changed files with 58 additions and 3 deletions

View File

@ -3,7 +3,7 @@ package telegram
import "github.com/Masterminds/semver"
// Version represents current version of Telegram API supported by this package
var Version = semver.MustParse("4.7.0") //nolint: gochecknoglobals
var Version = semver.MustParse("4.8.0") //nolint: gochecknoglobals
// Action represents available and supported status actions of bot
const (

View File

@ -419,6 +419,19 @@ type (
// 0-based identifier of the correct answer option, required for polls in quiz mode
CorrectOptionID int `json:"correct_option_id,omitempty"`
// Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style
// poll, 0-200 characters with at most 2 line feeds after entities parsing
Explanation string `json:"explanation,omitempty"`
// Mode for parsing entities in the explanation. See formatting options for more details.
ExplanationParseMode string `json:"explanation_parse_mode,omitempty"`
// Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date.
OpenPeriod int `json:"open_period,omitempty"`
// Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period.
CloseDate int64 `json:"close_date,omitempty"`
// Pass True, if the poll needs to be immediately closed
IsClosed bool `json:"is_closed,omitempty"`
@ -437,6 +450,10 @@ type (
// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
ChatID int64 `json:"chat_id"`
// Emoji on which the dice throw animation is based. Currently, must be one of “🎲” or “🎯”. Defauts to
// “🎲”
Emoji string `json:"emoji,omitempty"`
// Sends the message silently. Users will receive a notification with no sound.
DisableNotification bool `json:"disable_notification,omitempty"`

View File

@ -521,11 +521,27 @@ type (
// 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,omitempty"`
// Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style
// poll, 0-200 characters
Explanation string `json:"explanation,omitempty"`
// Special entities like usernames, URLs, bot commands, etc. that appear in the explanation
ExplanationEntities []*MessageEntity `json:"explanation_entities,omitempty"`
// Amount of time in seconds the poll will be active after creation
OpenPeriod int `json:"open_period,omitempty"`
// Point in time (Unix timestamp) when the poll will be automatically closed
CloseDate int64 `json:"close_date,omitempty"`
}
// Dice represents a dice with random value from 1 to 6. (Yes, we're aware of the “proper” singular of die.
// But it's awkward, and we decided to help it change. One dice at a time!)
// Dice represents a dice with random value from 1 to 6 for currently supported base emoji. (Yes, we're aware
// of the “proper” singular of die. But it's awkward, and we decided to help it change. One dice at a time!)
Dice struct {
// Emoji on which the dice throw animation is based
Emoji string `json:"emoji"`
// Value of the dice, 1-6
Value int `json:"value"`
}
@ -1212,6 +1228,7 @@ func (m Message) IsEvent() bool {
m.IsSupergroupChatCreatedEvent() || m.IsNewChatPhotoEvent()
}
// IsDice checks what current message is a dice.
func (m Message) IsDice() bool { return m.Dice != nil }
// IsBold checks that the current entity is a bold tag.
@ -1477,3 +1494,6 @@ func (f InputFile) MarshalJSON() ([]byte, error) {
return nil, nil
}
}
// CloseTime parse CloseDate and returns time.Time.
func (p Poll) CloseTime() time.Time { return time.Unix(p.CloseDate, 0) }

View File

@ -2126,3 +2126,21 @@ func TestInputFileMarshalJSON(t *testing.T) {
})
}
}
func TestMessageIsDice(t *testing.T) {
t.Run("true", func(t *testing.T) {
f := Message{Dice: &Dice{Value: 3}}
assert.True(t, f.IsDice())
})
t.Run("false", func(t *testing.T) {
f := new(Message)
assert.False(t, f.IsDice())
})
}
func TestPollCloseTime(t *testing.T) {
now := time.Now().Round(time.Second)
p := Poll{CloseDate: now.Unix()}
assert.Equal(t, now, p.CloseTime())
}