From 965cd03621edfafb63420424c91fbc0b015adf45 Mon Sep 17 00:00:00 2001 From: Nikita Date: Sun, 23 May 2021 19:43:58 +0300 Subject: [PATCH] telebot: fix all miscalculations --- admin.go | 9 +++++---- bot.go | 11 +++++------ chat.go | 38 ++++++++++++++++++++------------------ media.go | 4 ++-- sendable.go | 4 ++-- telebot.go | 4 ++-- webhook.go | 12 ++++++------ 7 files changed, 42 insertions(+), 40 deletions(-) diff --git a/admin.go b/admin.go index 4845921..2a6d5b4 100644 --- a/admin.go +++ b/admin.go @@ -148,14 +148,15 @@ func (b *Bot) Ban(chat *Chat, member *ChatMember) error { } // Unban will unban user from chat, who would have thought eh? -func (b *Bot) Unban(chat *Chat, user *User, isBanned ...bool) error { +// forBanned does nothing if the user is not banned. +func (b *Bot) Unban(chat *Chat, user *User, forBanned ...bool) error { params := map[string]string{ "chat_id": chat.Recipient(), "user_id": user.Recipient(), } - if len(isBanned) > 0 { - params["only_if_banned"] = strconv.FormatBool(isBanned[0]) + if len(forBanned) > 0 { + params["only_if_banned"] = strconv.FormatBool(forBanned[0]) } _, err := b.Raw("unbanChatMember", params) @@ -201,7 +202,7 @@ func (b *Bot) Promote(chat *Chat, member *ChatMember) error { params := map[string]interface{}{ "chat_id": chat.Recipient(), "user_id": member.User.Recipient(), - "is_anonymous": member.IsAnonymous, + "is_anonymous": member.Anonymous, } embedRights(params, prv) diff --git a/bot.go b/bot.go index 37da15e..4c578a5 100644 --- a/bot.go +++ b/bot.go @@ -350,10 +350,10 @@ func (b *Bot) ProcessUpdate(upd Update) { } if m.ProximityAlertTriggered != nil { - if handler, ok := b.handlers[OnProximityAlertTriggered]; ok { + if handler, ok := b.handlers[OnProximityAlert]; ok { handler, ok := handler.(func(*Message)) if !ok { - panic("telebot: proximity alert triggered handler is bad") + panic("telebot: proximity alert handler is bad") } b.runHandler(func() { handler(m) }) @@ -786,8 +786,8 @@ func (b *Bot) Edit(msg Editable, what interface{}, options ...interface{}) (*Mes method = "editMessageLiveLocation" params["latitude"] = fmt.Sprintf("%f", v.Lat) params["longitude"] = fmt.Sprintf("%f", v.Lng) - if v.HA != nil { - params["horizontal_accuracy"] = fmt.Sprintf("%f", *v.HA) + if v.HorizontalAccuracy != nil { + params["horizontal_accuracy"] = fmt.Sprintf("%f", *v.HorizontalAccuracy) } if v.Heading != 0 { params["heading"] = strconv.Itoa(v.Heading) @@ -1430,10 +1430,9 @@ func (b *Bot) Unpin(chat *Chat, messageID ...int) error { return err } -// Unpin unpins all messages in a supergroup or a channel. +// UnpinAll unpins all messages in a supergroup or a channel. // // It supports tb.Silent option. -// MessageID is a specific pinned message func (b *Bot) UnpinAll(chat *Chat) error { params := map[string]string{ "chat_id": chat.Recipient(), diff --git a/chat.go b/chat.go index 7815bab..b2c3bfb 100644 --- a/chat.go +++ b/chat.go @@ -42,20 +42,22 @@ type Chat struct { Still bool `json:"is_member,omitempty"` // Returns only in getChat - Bio string `json:"bio,omitempty"` - Photo *ChatPhoto `json:"photo,omitempty"` - Description string `json:"description,omitempty"` - InviteLink string `json:"invite_link,omitempty"` - PinnedMessage *Message `json:"pinned_message,omitempty"` - Permissions *Rights `json:"permissions,omitempty"` - SlowMode int `json:"slow_mode_delay,omitempty"` - StickerSet string `json:"sticker_set_name,omitempty"` - CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` - LinkedChatID int64 `json:"linked_chat_id,omitempty"` - ChatLocation *struct { - Location Location `json:"location,omitempty"` - Address string `json:"address,omitempty"` - } `json:"location,omitempty"` + Bio string `json:"bio,omitempty"` + Photo *ChatPhoto `json:"photo,omitempty"` + Description string `json:"description,omitempty"` + InviteLink string `json:"invite_link,omitempty"` + PinnedMessage *Message `json:"pinned_message,omitempty"` + Permissions *Rights `json:"permissions,omitempty"` + SlowMode int `json:"slow_mode_delay,omitempty"` + StickerSet string `json:"sticker_set_name,omitempty"` + CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` + LinkedChatID int64 `json:"linked_chat_id,omitempty"` + ChatLocation *ChatLocation `json:"location,omitempty"` +} + +type ChatLocation struct { + Location Location `json:"location,omitempty"` + Address string `json:"address,omitempty"` } // ChatPhoto object represents a chat photo. @@ -78,10 +80,10 @@ func (c *Chat) Recipient() string { type ChatMember struct { Rights - User *User `json:"user"` - Role MemberStatus `json:"status"` - Title string `json:"custom_title"` - IsAnonymous bool `json:"is_anonymous"` + User *User `json:"user"` + Role MemberStatus `json:"status"` + Title string `json:"custom_title"` + Anonymous bool `json:"is_anonymous"` // Date when restrictions will be lifted for the user, unix time. // diff --git a/media.go b/media.go index e5e1acf..bcce24b 100644 --- a/media.go +++ b/media.go @@ -196,7 +196,7 @@ type Location struct { Lng float32 `json:"longitude"` // Horizontal Accuracy - HA *float32 `json:"horizontal_accuracy,omitempty"` + HorizontalAccuracy *float32 `json:"horizontal_accuracy,omitempty"` Heading int `json:"heading,omitempty"` @@ -207,7 +207,7 @@ type Location struct { ProximityAlertRadius int `json:"proximity_alert_radius,omitempty"` } -// ProximityAlertTriggered object represents sent whenever +// ProximityAlertTriggered sent whenever // a user in the chat triggers a proximity alert set by another user. type ProximityAlertTriggered struct { Traveler *User `json:"traveler,omitempty"` diff --git a/sendable.go b/sendable.go index 56d5e53..ba80763 100644 --- a/sendable.go +++ b/sendable.go @@ -265,8 +265,8 @@ func (x *Location) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error "longitude": fmt.Sprintf("%f", x.Lng), "live_period": strconv.Itoa(x.LivePeriod), } - if x.HA != nil { - params["horizontal_accuracy"] = fmt.Sprintf("%f", *x.HA) + if x.HorizontalAccuracy != nil { + params["horizontal_accuracy"] = fmt.Sprintf("%f", *x.HorizontalAccuracy) } if x.Heading != 0 { params["heading"] = strconv.Itoa(x.Heading) diff --git a/telebot.go b/telebot.go index e2f3b4d..7a09d45 100644 --- a/telebot.go +++ b/telebot.go @@ -145,10 +145,10 @@ const ( // Handler: func(*Message) OnVoiceChatPartecipantsInvited = "\avoice_chat_partecipants_invited" - // Will fire on ProximityAlertTriggered + // Will fire on ProximityAlert // // Handler: func(*Message) - OnProximityAlertTriggered = "\aproximity_alert_triggered" + OnProximityAlert = "\aproximity_alert" ) // ChatAction is a client-side status indicating bot activity. diff --git a/webhook.go b/webhook.go index 22970c1..17e283a 100644 --- a/webhook.go +++ b/webhook.go @@ -49,8 +49,8 @@ type Webhook struct { ErrorUnixtime int64 `json:"last_error_date"` ErrorMessage string `json:"last_error_message"` - IpAddress string `json:"ip_address"` - DropPendingUpdates bool `json:"drop_pending_updates"` + Ip string `json:"ip_address"` + DropUpdates bool `json:"drop_pending_updates"` TLS *WebhookTLS Endpoint *WebhookEndpoint @@ -91,11 +91,11 @@ func (h *Webhook) getParams() map[string]string { data, _ := json.Marshal(h.AllowedUpdates) params["allowed_updates"] = string(data) } - if h.IpAddress != "" { - params["ip_address"] = h.IpAddress + if h.Ip != "" { + params["ip_address"] = h.Ip } - if h.DropPendingUpdates { - params["drop_pending_updates"] = strconv.FormatBool(h.DropPendingUpdates) + if h.DropUpdates { + params["drop_pending_updates"] = strconv.FormatBool(h.DropUpdates) } if h.TLS != nil {