From 7fbdcd2534fcc617d4084691037112fb9f41da75 Mon Sep 17 00:00:00 2001 From: Maxim Lebedev Date: Fri, 8 May 2020 20:45:09 +0500 Subject: [PATCH] :alien: Updated code to support BotAPI v4.8 --- const.go | 2 +- methods.go | 17 +++++++++++++++++ types.go | 24 ++++++++++++++++++++++-- types_test.go | 18 ++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/const.go b/const.go index b47233b..87f534a 100644 --- a/const.go +++ b/const.go @@ -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 ( diff --git a/methods.go b/methods.go index ee0a669..0fe1344 100644 --- a/methods.go +++ b/methods.go @@ -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"` diff --git a/types.go b/types.go index 7bf65d8..6898a4b 100644 --- a/types.go +++ b/types.go @@ -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) } diff --git a/types_test.go b/types_test.go index 680ae39..1596617 100644 --- a/types_test.go +++ b/types_test.go @@ -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()) +}