From 5dc96dc937d91f621366e7ffc6f6df326dfd924e Mon Sep 17 00:00:00 2001 From: Demian Date: Fri, 9 Aug 2024 02:21:46 +0200 Subject: [PATCH] telebot: refactor bot api 7.3 --- bot.go | 3 +++ chat.go | 69 ++++++++++++++++++++++++++++------------------------- media.go | 7 +++--- message.go | 4 ++-- poll.go | 16 ++++++------- sendable.go | 7 +----- 6 files changed, 53 insertions(+), 53 deletions(-) diff --git a/bot.go b/bot.go index 3062705a..f224f717 100644 --- a/bot.go +++ b/bot.go @@ -505,6 +505,9 @@ func (b *Bot) Edit(msg Editable, what interface{}, opts ...interface{}) (*Messag if v.AlertRadius != 0 { params["proximity_alert_radius"] = strconv.Itoa(v.AlertRadius) } + if v.LivePeriod != 0 { + params["live_period"] = strconv.Itoa(v.LivePeriod) + } default: return nil, ErrUnsupportedWhat } diff --git a/chat.go b/chat.go index 84dbd5c8..c97eb840 100644 --- a/chat.go +++ b/chat.go @@ -74,7 +74,7 @@ type Chat struct { ProfileBackgroundEmojiID string `json:"profile_background_custom_emoji_id"` HasVisibleHistory bool `json:"has_visible_history"` UnrestrictBoosts int `json:"unrestrict_boost_count"` - MaxReactionCount int `json:"max_reaction_count"` + MaxReactions int `json:"max_reaction_count"` Birthdate Birthdate `json:"birthdate,omitempty"` PersonalChat *Chat `json:"personal_chat,omitempty"` BusinessIntro BusinessIntro `json:"business_intro,omitempty"` @@ -173,8 +173,8 @@ type ChatMemberUpdate struct { InviteLink *ChatInviteLink `json:"invite_link"` // (Optional) True, if the user joined the chat after sending - //a direct join request without using an invite link and being - //approved by an administrator + // a direct join request without using an invite link and being + // approved by an administrator ViaJoinRequest bool `json:"via_join_request"` // (Optional) True, if the user joined the chat via a chat folder invite link. @@ -273,25 +273,20 @@ type Story struct { Poster *Chat `json:"chat"` } -type BackgroundFill struct { - // Type of the background fill, always “solid” - Type string `json:"type"` - - // The color of the background fill in the RGB24 format - Color int `json:"color,omitempty"` - - // Top color of the gradient in the RGB24 format - TopColor int `json:"top_color,omitempty"` +type Birthdate struct { + // Day of the user's birth; 1-31 + Day int `json:"day"` - // Bottom color of the gradient in the RGB24 format - BottomColor int `json:"bottom_color,omitempty"` + // Month of the user's birth; 1-12 + Month int `json:"month"` - // Clockwise rotation angle of the background fill in degrees; 0-359 - RotationAngle int `json:"rotation_angle,omitempty"` + // (Optional) Year of the user's birth + Year int `json:"year"` +} - // A list of the 3 or 4 base colors that are used to generate - // the freeform gradient in the RGB24 format - Colors []int `json:"colors,omitempty"` +type ChatBackground struct { + // Type of the background + Type BackgroundType `json:"type"` } type BackgroundType struct { @@ -312,30 +307,38 @@ type BackgroundType struct { // (Optional) True, if the wallpaper is downscaled to fit in a 450x450 // square and then box-blurred with radius 12 - IsBlurred bool `json:"is_blurred,omitempty"` + Blurred bool `json:"is_blurred,omitempty"` // (Optional) True, if the background moves slightly when the device is tilted - IsMoving bool `json:"is_moving,omitempty"` + Moving bool `json:"is_moving,omitempty"` // (Optional) True, if the background fill must be applied only to the pattern itself. // All other pixels are black in this case. For dark themes only - IsInverted bool `json:"is_inverted,omitempty"` -} + Inverted bool `json:"is_inverted,omitempty"` -type ChatBackground struct { - // Type of the background - Type BackgroundType `json:"type"` + // Name of the chat theme, which is usually an emoji + ThemeName string `json:"theme_name,omitempty"` } -type Birthdate struct { - // Day of the user's birth; 1-31 - Day int `json:"day"` +type BackgroundFill struct { + // Type of the background fill. + Type string `json:"type"` - // Month of the user's birth; 1-12 - Month int `json:"month"` + // The color of the background fill in the RGB24 format + SolidColor int `json:"color,omitempty"` - // (Optional) Year of the user's birth - Year int `json:"year"` + // Top color of the gradient in the RGB24 format + GradientTopColor int `json:"top_color,omitempty"` + + // Bottom color of the gradient in the RGB24 format + GradientBottomColor int `json:"bottom_color,omitempty"` + + // Clockwise rotation angle of the background fill in degrees; 0-359 + GradientRotationAngle int `json:"rotation_angle,omitempty"` + + // A list of the 3 or 4 base colors that are used to generate + // the freeform gradient in the RGB24 format + GradientColors []int `json:"colors,omitempty"` } // ExpireDate returns the moment of the link expiration in local time. diff --git a/media.go b/media.go index 2af63deb..d79419af 100644 --- a/media.go +++ b/media.go @@ -5,9 +5,6 @@ import ( "math" ) -// Alias for math.MaxInt32 -const LiveForever = math.MaxInt32 - // Media is a generic type for all kinds of media that includes File. type Media interface { // MediaType returns string-represented media type. @@ -334,6 +331,10 @@ type Contact struct { UserID int64 `json:"user_id,omitempty"` } +// LiveForever is an alias for math.MaxInt32. +// Use it for LivePeriod of the Location. +const LiveForever = math.MaxInt32 + // Location object represents geographic position. type Location struct { Lat float32 `json:"latitude"` diff --git a/message.go b/message.go index f8a848a3..3663fcc7 100644 --- a/message.go +++ b/message.go @@ -314,11 +314,11 @@ type Message struct { BoostAdded *BoostAdded `json:"boost_added"` // Service message: chat background set - ChatBackgroundSet ChatBackground `json:"chat_background_set"` + ChatBackground ChatBackground `json:"chat_background_set"` // If the sender of the message boosted the chat, the number of boosts // added by the user. - SenderBoostCount int `json:"sender_boost_count"` + SenderBoosts int `json:"sender_boost_count"` // Service message: forum topic created TopicCreated *Topic `json:"forum_topic_created,omitempty"` diff --git a/poll.go b/poll.go index 196d562d..9394ced0 100644 --- a/poll.go +++ b/poll.go @@ -29,9 +29,9 @@ type Poll struct { MultipleAnswers bool `json:"allows_multiple_answers,omitempty"` Explanation string `json:"explanation,omitempty"` ParseMode ParseMode `json:"explanation_parse_mode,omitempty"` - Entities []MessageEntity `json:"explanation_entities"` - QuestionEntities []MessageEntity `json:"question_entities"` - QuestionParseMode string `json:"question_parse_mode"` + 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"` @@ -43,12 +43,10 @@ type Poll struct { // PollOption contains information about one answer option in a poll. type PollOption struct { - Text string `json:"text"` - VoterCount int `json:"voter_count"` - - // (Optional) A JSON-serialized list of special entities that appear - //in the poll option text. It can be specified instead of text_parse_mode - TextEntities []MessageEntity `json:"text_entities"` + 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. diff --git a/sendable.go b/sendable.go index 4d7d9a5e..1e431811 100644 --- a/sendable.go +++ b/sendable.go @@ -352,12 +352,7 @@ func (p *Poll) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) { } b.embedSendOptions(params, opt) - var options []string - for _, o := range p.Options { - options = append(options, o.Text) - } - - opts, _ := json.Marshal(options) + opts, _ := json.Marshal(p.Options) params["options"] = string(opts) data, err := b.Raw("sendPoll", params)