telebot: satisfy Editable for Callback and InlineResult, remove InlineID from Message

pull/425/head
Demian 3 years ago
parent fb7de291df
commit f61d30b66b

@ -411,20 +411,10 @@ func (b *Bot) ProcessUpdate(upd Update) {
if upd.Callback != nil {
if upd.Callback.Data != "" {
if upd.Callback.MessageID != "" {
upd.Callback.Message = &Message{
// InlineID indicates that message
// is inline, so we have only its id
InlineID: upd.Callback.MessageID,
}
}
data := upd.Callback.Data
if data[0] == '\f' {
if data := upd.Callback.Data; data[0] == '\f' {
match := cbackRx.FindAllStringSubmatch(data, -1)
if match != nil {
unique, payload := match[0][1], match[0][3]
if handler, ok := b.handlers["\f"+unique]; ok {
c.callback.Unique = unique
c.callback.Data = payload
@ -732,6 +722,8 @@ func (b *Bot) Copy(to Recipient, msg Editable, options ...interface{}) (*Message
// b.Edit(m, &tele.ReplyMarkup{...})
// b.Edit(m, &tele.Photo{File: ...})
// b.Edit(m, tele.Location{42.1337, 69.4242})
// b.Edit(c, "edit inline message from the callback")
// b.Edit(r, "edit message from chosen inline result")
//
func (b *Bot) Edit(msg Editable, what interface{}, opts ...interface{}) (*Message, error) {
var (

@ -34,6 +34,11 @@ type Callback struct {
Unique string `json:"-"`
}
// MessageSig satisfies Editable interface.
func (c *Callback) MessageSig() (string, int64) {
return c.MessageID, 0
}
// IsInline says whether message is an inline message.
func (c *Callback) IsInline() bool {
return c.MessageID != ""

@ -315,6 +315,10 @@ func (c *nativeContext) ForwardTo(to Recipient, opts ...interface{}) error {
}
func (c *nativeContext) Edit(what interface{}, opts ...interface{}) error {
if c.inlineResult != nil {
_, err := c.b.Edit(c.inlineResult, what, opts...)
return err
}
clb := c.callback
if clb == nil || clb.Message == nil {
return ErrBadContext

@ -7,16 +7,6 @@ import (
"github.com/pkg/errors"
)
// InlineResult represents a result of an inline query that was chosen
// by the user and sent to their chat partner.
type InlineResult struct {
Sender *User `json:"from"`
Location *Location `json:"location,omitempty"`
ResultID string `json:"result_id"`
Query string `json:"query"`
MessageID string `json:"inline_message_id"` // inline messages only!
}
// Query is an incoming inline query. When the user sends
// an empty query, your bot could return some default or
// trending results.
@ -75,6 +65,21 @@ type QueryResponse struct {
SwitchPMParameter string `json:"switch_pm_parameter,omitempty"`
}
// InlineResult represents a result of an inline query that was chosen
// by the user and sent to their chat partner.
type InlineResult struct {
Sender *User `json:"from"`
Location *Location `json:"location,omitempty"`
ResultID string `json:"result_id"`
Query string `json:"query"`
MessageID string `json:"inline_message_id"` // inline messages only!
}
// MessageSig satisfies Editable interface.
func (ir *InlineResult) MessageSig() (string, int64) {
return ir.MessageID, 0
}
// Result represents one result of an inline query.
type Result interface {
ResultID() string

@ -9,8 +9,6 @@ import (
type Message struct {
ID int `json:"message_id"`
InlineID string `json:"-"`
// For message sent to channels, Sender will be nil
Sender *User `json:"from"`
@ -241,11 +239,6 @@ type Message struct {
AutoDeleteTimer *AutoDeleteTimer `json:"message_auto_delete_timer_changed,omitempty"`
}
// AutoDeleteTimer represents a service message about a change in auto-delete timer settings.
type AutoDeleteTimer struct {
Unixtime int `json:"message_auto_delete_time"`
}
// MessageEntity object represents "special" parts of text messages,
// including hashtags, usernames, URLs, etc.
type MessageEntity struct {
@ -270,11 +263,13 @@ type MessageEntity struct {
Language string `json:"language,omitempty"`
}
// AutoDeleteTimer represents a service message about a change in auto-delete timer settings.
type AutoDeleteTimer struct {
Unixtime int `json:"message_auto_delete_time"`
}
// MessageSig satisfies Editable interface (see Editable.)
func (m *Message) MessageSig() (string, int64) {
if m.InlineID != "" {
return m.InlineID, 0
}
return strconv.Itoa(m.ID), m.Chat.ID
}

Loading…
Cancel
Save