bot: fix media file name setting and parse mode passing in SendAlbum

pull/433/head v2.4.0
Demian 3 years ago
parent 915dfba6a4
commit 3f7ecbd8a8

@ -88,7 +88,7 @@ func (b *Bot) sendFiles(method string, files map[string]File, params map[string]
defer pipeWriter.Close()
for field, file := range rawFiles {
if err := addFileToWriter(writer, files[field].FileName, field, file); err != nil {
if err := addFileToWriter(writer, files[field].fileName, field, file); err != nil {
pipeWriter.CloseWithError(err)
return
}

@ -332,7 +332,10 @@ func TestBot(t *testing.T) {
_, err = b.SendAlbum(to, nil)
assert.Error(t, err)
msgs, err := b.SendAlbum(to, Album{photo, photo})
photo2 := *photo
photo2.Caption = ""
msgs, err := b.SendAlbum(to, Album{photo, &photo2}, ModeHTML)
require.NoError(t, err)
assert.Len(t, msgs, 2)
assert.NotEmpty(t, msgs[0].AlbumID)
@ -433,7 +436,7 @@ func TestBot(t *testing.T) {
assert.NotNil(t, edited.Location)
})
// should be the last
// should be after Edit tests
t.Run("Delete()", func(t *testing.T) {
require.NoError(t, b.Delete(msg))
})

@ -9,7 +9,6 @@ import (
type File struct {
FileID string `json:"file_id"`
UniqueID string `json:"file_unique_id"`
FileName string `json:"file_name"`
FileSize int `json:"file_size"`
// file on telegram server https://core.telegram.org/bots/api#file
@ -23,6 +22,8 @@ type File struct {
// file backed with io.Reader
FileReader io.Reader `json:"-"`
fileName string
}
// FromDisk constructs a new local (on-disk) file object.

@ -86,6 +86,7 @@ type Audio struct {
// MediaFile returns &Audio.File
func (a *Audio) MediaFile() *File {
a.fileName = a.FileName
return &a.File
}
@ -103,6 +104,7 @@ type Document struct {
// MediaFile returns &Document.File
func (d *Document) MediaFile() *File {
d.fileName = d.FileName
return &d.File
}
@ -125,6 +127,7 @@ type Video struct {
// MediaFile returns &Video.File
func (v *Video) MediaFile() *File {
v.fileName = v.FileName
return &v.File
}
@ -145,6 +148,7 @@ type Animation struct {
// MediaFile returns &Animation.File
func (a *Animation) MediaFile() *File {
a.fileName = a.FileName
return &a.File
}

@ -123,22 +123,15 @@ func extractMessage(data []byte) (*Message, error) {
}
func extractOptions(how []interface{}) *SendOptions {
var opts *SendOptions
opts := &SendOptions{}
for _, prop := range how {
switch opt := prop.(type) {
case *SendOptions:
opts = opt.copy()
case *ReplyMarkup:
if opts == nil {
opts = &SendOptions{}
}
opts.ReplyMarkup = opt.copy()
case Option:
if opts == nil {
opts = &SendOptions{}
}
switch opt {
case NoPreview:
opts.DisableWebPagePreview = true
@ -158,9 +151,6 @@ func extractOptions(how []interface{}) *SendOptions {
panic("telebot: unsupported flag-option")
}
case ParseMode:
if opts == nil {
opts = &SendOptions{}
}
opts.ParseMode = opt
default:
panic("telebot: unsupported send-option")

Loading…
Cancel
Save