Skip to content

Commit

Permalink
telebot: refactor bot api 7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
demget committed Aug 9, 2024
1 parent 5218831 commit 5dc96dc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 53 deletions.
3 changes: 3 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
69 changes: 36 additions & 33 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions media.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
16 changes: 7 additions & 9 deletions poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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.
Expand Down
7 changes: 1 addition & 6 deletions sendable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5dc96dc

Please sign in to comment.