Skip to content

Commit

Permalink
EditMedia: Fix possible thumb attach name conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
stek29 committed Dec 25, 2019
1 parent ddbfc93 commit baa616b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ func (b *Bot) EditMedia(message Editable, inputMedia InputMedia, options ...inte
file := make(map[string]File)

f := inputMedia.MediaFile()
thumbAttachName := "thumb"

switch {
case f.InCloud():
Expand All @@ -793,6 +794,9 @@ func (b *Bot) EditMedia(message Editable, inputMedia InputMedia, options ...inte
if f.FileReader != nil {
s = "0"
}
if s == thumbAttachName {
thumbAttachName = "thumb2"
}
mediaRepr = "attach://" + s
file[s] = *f
default:
Expand Down Expand Up @@ -848,7 +852,7 @@ func (b *Bot) EditMedia(message Editable, inputMedia InputMedia, options ...inte
resultMedia.MIME = y.MIME
thumb = y.Thumbnail
if thumb != nil {
resultMedia.Thumbnail = "attach://thumb"
resultMedia.Thumbnail = "attach://" + thumbAttachName
}
case *Document:
resultMedia.Type = "document"
Expand All @@ -857,7 +861,7 @@ func (b *Bot) EditMedia(message Editable, inputMedia InputMedia, options ...inte
resultMedia.MIME = y.MIME
thumb = y.Thumbnail
if thumb != nil {
resultMedia.Thumbnail = "attach://thumb"
resultMedia.Thumbnail = "attach://" + thumbAttachName
}
case *Audio:
resultMedia.Type = "audio"
Expand All @@ -868,7 +872,7 @@ func (b *Bot) EditMedia(message Editable, inputMedia InputMedia, options ...inte
resultMedia.Performer = y.Performer
thumb = y.Thumbnail
if thumb != nil {
resultMedia.Thumbnail = "attach://thumb"
resultMedia.Thumbnail = "attach://" + thumbAttachName
}
default:
return nil, errors.Errorf("telebot: inputMedia entry is not valid")
Expand All @@ -889,7 +893,7 @@ func (b *Bot) EditMedia(message Editable, inputMedia InputMedia, options ...inte
}

if thumb != nil {
file["thumb"] = *thumb.MediaFile()
file[thumbAttachName] = *thumb.MediaFile()
}

embedSendOptions(params, sendOpts)
Expand Down

0 comments on commit baa616b

Please sign in to comment.