Skip to content

Commit 3f7ecbd

Browse files
committed
bot: fix media file name setting and parse mode passing in SendAlbum
1 parent 915dfba commit 3f7ecbd

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (b *Bot) sendFiles(method string, files map[string]File, params map[string]
8888
defer pipeWriter.Close()
8989

9090
for field, file := range rawFiles {
91-
if err := addFileToWriter(writer, files[field].FileName, field, file); err != nil {
91+
if err := addFileToWriter(writer, files[field].fileName, field, file); err != nil {
9292
pipeWriter.CloseWithError(err)
9393
return
9494
}

bot_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,10 @@ func TestBot(t *testing.T) {
332332
_, err = b.SendAlbum(to, nil)
333333
assert.Error(t, err)
334334

335-
msgs, err := b.SendAlbum(to, Album{photo, photo})
335+
photo2 := *photo
336+
photo2.Caption = ""
337+
338+
msgs, err := b.SendAlbum(to, Album{photo, &photo2}, ModeHTML)
336339
require.NoError(t, err)
337340
assert.Len(t, msgs, 2)
338341
assert.NotEmpty(t, msgs[0].AlbumID)
@@ -433,7 +436,7 @@ func TestBot(t *testing.T) {
433436
assert.NotNil(t, edited.Location)
434437
})
435438

436-
// should be the last
439+
// should be after Edit tests
437440
t.Run("Delete()", func(t *testing.T) {
438441
require.NoError(t, b.Delete(msg))
439442
})

file.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
type File struct {
1010
FileID string `json:"file_id"`
1111
UniqueID string `json:"file_unique_id"`
12-
FileName string `json:"file_name"`
1312
FileSize int `json:"file_size"`
1413

1514
// file on telegram server https://core.telegram.org/bots/api#file
@@ -23,6 +22,8 @@ type File struct {
2322

2423
// file backed with io.Reader
2524
FileReader io.Reader `json:"-"`
25+
26+
fileName string
2627
}
2728

2829
// FromDisk constructs a new local (on-disk) file object.

media.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type Audio struct {
8686

8787
// MediaFile returns &Audio.File
8888
func (a *Audio) MediaFile() *File {
89+
a.fileName = a.FileName
8990
return &a.File
9091
}
9192

@@ -103,6 +104,7 @@ type Document struct {
103104

104105
// MediaFile returns &Document.File
105106
func (d *Document) MediaFile() *File {
107+
d.fileName = d.FileName
106108
return &d.File
107109
}
108110

@@ -125,6 +127,7 @@ type Video struct {
125127

126128
// MediaFile returns &Video.File
127129
func (v *Video) MediaFile() *File {
130+
v.fileName = v.FileName
128131
return &v.File
129132
}
130133

@@ -145,6 +148,7 @@ type Animation struct {
145148

146149
// MediaFile returns &Animation.File
147150
func (a *Animation) MediaFile() *File {
151+
a.fileName = a.FileName
148152
return &a.File
149153
}
150154

util.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,15 @@ func extractMessage(data []byte) (*Message, error) {
123123
}
124124

125125
func extractOptions(how []interface{}) *SendOptions {
126-
var opts *SendOptions
126+
opts := &SendOptions{}
127127

128128
for _, prop := range how {
129129
switch opt := prop.(type) {
130130
case *SendOptions:
131131
opts = opt.copy()
132132
case *ReplyMarkup:
133-
if opts == nil {
134-
opts = &SendOptions{}
135-
}
136133
opts.ReplyMarkup = opt.copy()
137134
case Option:
138-
if opts == nil {
139-
opts = &SendOptions{}
140-
}
141-
142135
switch opt {
143136
case NoPreview:
144137
opts.DisableWebPagePreview = true
@@ -158,9 +151,6 @@ func extractOptions(how []interface{}) *SendOptions {
158151
panic("telebot: unsupported flag-option")
159152
}
160153
case ParseMode:
161-
if opts == nil {
162-
opts = &SendOptions{}
163-
}
164154
opts.ParseMode = opt
165155
default:
166156
panic("telebot: unsupported send-option")

0 commit comments

Comments
 (0)