diff --git a/api.go b/api.go index 73f85f65..e20d7ce4 100644 --- a/api.go +++ b/api.go @@ -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 } diff --git a/bot_test.go b/bot_test.go index f5f15da5..f69c6643 100644 --- a/bot_test.go +++ b/bot_test.go @@ -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)) }) diff --git a/file.go b/file.go index 9d61d17a..6868e94d 100644 --- a/file.go +++ b/file.go @@ -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. diff --git a/media.go b/media.go index 5609adc0..48dd3a87 100644 --- a/media.go +++ b/media.go @@ -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 } diff --git a/util.go b/util.go index f316f121..b6bb2bfe 100644 --- a/util.go +++ b/util.go @@ -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")