telebot: fix all miscalculations

pull/405/head
Nikita 3 years ago
parent 0816adc16e
commit 965cd03621

@ -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)

@ -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(),

@ -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.
//

@ -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"`

@ -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)

@ -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.

@ -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 {

Loading…
Cancel
Save