Skip to content

Commit

Permalink
bot: rename ForwardMessages and CopyMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
demget committed Jun 10, 2024
1 parent 4722793 commit c4fce10
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
62 changes: 31 additions & 31 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,37 @@ func (b *Bot) getUpdates(offset, limit int, timeout time.Duration, allowed []str
return resp.Result, nil
}

func (b *Bot) forwardCopyMany(to Recipient, msgs []Editable, key string, opts ...*SendOptions) ([]Message, error) {
params := map[string]string{
"chat_id": to.Recipient(),
}

embedMessages(params, msgs)

if len(opts) > 0 {
b.embedSendOptions(params, opts[0])
}

data, err := b.Raw(key, params)
if err != nil {
return nil, err
}

var resp struct {
Result []Message
}
if err := json.Unmarshal(data, &resp); err != nil {
var resp struct {
Result bool
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return nil, wrapError(err)
}
return resp.Result, nil
}

// extractOk checks given result for error. If result is ok returns nil.
// In other cases it extracts API error. If error is not presented
// in errors.go, it will be prefixed with `unknown` keyword.
Expand Down Expand Up @@ -327,37 +358,6 @@ func extractMessage(data []byte) (*Message, error) {
return resp.Result, nil
}

func (b *Bot) forwardCopyMessages(to Recipient, msgs []Editable, key string, opts ...*SendOptions) ([]Message, error) {
params := map[string]string{
"chat_id": to.Recipient(),
}

embedMessages(params, msgs)

if len(opts) > 0 {
b.embedSendOptions(params, opts[0])
}

data, err := b.Raw(key, params)
if err != nil {
return nil, err
}

var resp struct {
Result []Message
}
if err := json.Unmarshal(data, &resp); err != nil {
var resp struct {
Result bool
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return nil, wrapError(err)
}
return resp.Result, nil
}

func verbose(method string, payload interface{}, data []byte) {
body, _ := json.Marshal(payload)
body = bytes.ReplaceAll(body, []byte(`\"`), []byte(`"`))
Expand Down
12 changes: 6 additions & 6 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,15 @@ func (b *Bot) Forward(to Recipient, msg Editable, opts ...interface{}) (*Message
return extractMessage(data)
}

// ForwardMessages method forwards multiple messages of any kind.
// ForwardMany method forwards multiple messages of any kind.
// If some of the specified messages can't be found or forwarded, they are skipped.
// Service messages and messages with protected content can't be forwarded.
// Album grouping is kept for forwarded messages.
func (b *Bot) ForwardMessages(to Recipient, msgs []Editable, opts ...*SendOptions) ([]Message, error) {
func (b *Bot) ForwardMany(to Recipient, msgs []Editable, opts ...*SendOptions) ([]Message, error) {
if to == nil {
return nil, ErrBadRecipient
}
return b.forwardCopyMessages(to, msgs, "forwardMessages", opts...)
return b.forwardCopyMany(to, msgs, "forwardMessages", opts...)
}

// Copy behaves just like Forward() but the copied message doesn't have a link to the original message (see Bots API).
Expand Down Expand Up @@ -448,18 +448,18 @@ func (b *Bot) Copy(to Recipient, msg Editable, options ...interface{}) (*Message
return extractMessage(data)
}

// CopyMessages this method makes a copy of messages of any kind.
// CopyMany this method makes a copy of messages of any kind.
// If some of the specified messages can't be found or copied, they are skipped.
// Service messages, giveaway messages, giveaway winners messages, and
// invoice messages can't be copied. A quiz poll can be copied only if the value of the field
// correct_option_id is known to the bot. The method is analogous
// to the method forwardMessages, but the copied messages don't have a link to the original message.
// Album grouping is kept for copied messages.
func (b *Bot) CopyMessages(to Recipient, msgs []Editable, opts ...*SendOptions) ([]Message, error) {
func (b *Bot) CopyMany(to Recipient, msgs []Editable, opts ...*SendOptions) ([]Message, error) {
if to == nil {
return nil, ErrBadRecipient
}
return b.forwardCopyMessages(to, msgs, "copyMessages", opts...)
return b.forwardCopyMany(to, msgs, "copyMessages", opts...)
}

// Edit is magic, it lets you change already sent message.
Expand Down

0 comments on commit c4fce10

Please sign in to comment.