Revert "bot: add audio and document for sendMediaGroup"

This reverts commit 206507e386.
pull/366/head
Demian 3 years ago
parent f5ff424b8f
commit 7a9c471cf3

@ -83,12 +83,11 @@ func (b *Bot) sendFiles(method string, files map[string]File, params map[string]
pipeReader, pipeWriter := io.Pipe() pipeReader, pipeWriter := io.Pipe()
writer := multipart.NewWriter(pipeWriter) writer := multipart.NewWriter(pipeWriter)
go func() { go func() {
defer pipeWriter.Close() defer pipeWriter.Close()
for field, file := range rawFiles { for field, file := range rawFiles {
if err := addFileToWriter(writer, files[field].fileName, field, file); err != nil { if err := addFileToWriter(writer, params["file_name"], field, file); err != nil {
pipeWriter.CloseWithError(err) pipeWriter.CloseWithError(err)
return return
} }

@ -450,6 +450,7 @@ func (b *Bot) ProcessUpdate(upd Update) {
return return
} }
} }
func (b *Bot) handle(end string, m *Message) bool { func (b *Bot) handle(end string, m *Message) bool {
@ -565,7 +566,7 @@ func (b *Bot) SendAlbum(to Recipient, a Album, options ...interface{}) ([]Messag
Type string `json:"type"` Type string `json:"type"`
Media string `json:"media"` Media string `json:"media"`
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
ParseMode string `json:"parse_mode,omitempty"` ParseMode ParseMode `json:"parse_mode,omitempty"`
}{ }{
Type: "photo", Type: "photo",
Media: repr, Media: repr,
@ -581,7 +582,6 @@ func (b *Bot) SendAlbum(to Recipient, a Album, options ...interface{}) ([]Messag
Height int `json:"height,omitempty"` Height int `json:"height,omitempty"`
Duration int `json:"duration,omitempty"` Duration int `json:"duration,omitempty"`
SupportsStreaming bool `json:"supports_streaming,omitempty"` SupportsStreaming bool `json:"supports_streaming,omitempty"`
ParseMode string `json:"parse_mode,omitempty"`
}{ }{
Type: "video", Type: "video",
Caption: y.Caption, Caption: y.Caption,
@ -590,37 +590,6 @@ func (b *Bot) SendAlbum(to Recipient, a Album, options ...interface{}) ([]Messag
Height: y.Height, Height: y.Height,
Duration: y.Duration, Duration: y.Duration,
SupportsStreaming: y.SupportsStreaming, SupportsStreaming: y.SupportsStreaming,
ParseMode: y.ParseMode,
})
case *Audio:
data, _ = json.Marshal(struct {
Type string `json:"type"`
Media string `json:"media"`
Caption string `json:"caption,omitempty"`
Duration int `json:"duration,omitempty"`
Performer string `json:"performer,omitempty"`
Title string `json:"title,omitempty"`
ParseMode string `json:"parse_mode,omitempty"`
}{
Type: "audio",
Media: repr,
Caption: y.Caption,
Duration: y.Duration,
Performer: y.Performer,
Title: y.Title,
ParseMode: y.ParseMode,
})
case *Document:
data, _ = json.Marshal(struct {
Type string `json:"type"`
Media string `json:"media"`
Caption string `json:"caption,omitempty"`
ParseMode string `json:"parse_mode,omitempty"`
}{
Type: "document",
Media: repr,
Caption: y.Caption,
ParseMode: y.ParseMode,
}) })
default: default:
return nil, errors.Errorf("telebot: album entry #%d is not valid", i) return nil, errors.Errorf("telebot: album entry #%d is not valid", i)
@ -651,18 +620,12 @@ func (b *Bot) SendAlbum(to Recipient, a Album, options ...interface{}) ([]Messag
for attachName := range files { for attachName := range files {
i, _ := strconv.Atoi(attachName) i, _ := strconv.Atoi(attachName)
r := resp.Result[i]
var newID string var newID string
switch { if resp.Result[i].Photo != nil {
case r.Photo != nil: newID = resp.Result[i].Photo.FileID
newID = r.Photo.FileID } else {
case r.Video != nil: newID = resp.Result[i].Video.FileID
newID = r.Video.FileID
case r.Audio != nil:
newID = r.Audio.FileID
case r.Document != nil:
newID = r.Document.FileID
} }
a[i].MediaFile().FileID = newID a[i].MediaFile().FileID = newID

@ -22,9 +22,6 @@ type File struct {
// file backed with io.Reader // file backed with io.Reader
FileReader io.Reader `json:"-"` FileReader io.Reader `json:"-"`
// intermediate file name value to use later in sendFiles
fileName string
} }
// FromDisk constructs a new local (on-disk) file object. // FromDisk constructs a new local (on-disk) file object.

@ -16,9 +16,6 @@ type InputMedia interface {
// As some files must be uploaded (instead of referencing) // As some files must be uploaded (instead of referencing)
// outer layers of Telebot require it. // outer layers of Telebot require it.
MediaFile() *File MediaFile() *File
// NOTE: To add in v3.
// Type() string
} }
// Photo object represents a single photo file. // Photo object represents a single photo file.
@ -89,12 +86,10 @@ type Audio struct {
Performer string `json:"performer,omitempty"` Performer string `json:"performer,omitempty"`
MIME string `json:"mime_type,omitempty"` MIME string `json:"mime_type,omitempty"`
FileName string `json:"file_name,omitempty"` FileName string `json:"file_name,omitempty"`
ParseMode ParseMode `json:"parse_mode,omitempty"`
} }
// MediaFile returns &Audio.File // MediaFile returns &Audio.File
func (a *Audio) MediaFile() *File { func (a *Audio) MediaFile() *File {
a.fileName = a.FileName
return &a.File return &a.File
} }
@ -108,12 +103,10 @@ type Document struct {
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
MIME string `json:"mime_type"` MIME string `json:"mime_type"`
FileName string `json:"file_name,omitempty"` FileName string `json:"file_name,omitempty"`
ParseMode ParseMode `json:"parse_mode,omitempty"`
} }
// MediaFile returns &Document.File // MediaFile returns &Document.File
func (d *Document) MediaFile() *File { func (d *Document) MediaFile() *File {
d.fileName = d.FileName
return &d.File return &d.File
} }
@ -132,12 +125,10 @@ type Video struct {
SupportsStreaming bool `json:"supports_streaming,omitempty"` SupportsStreaming bool `json:"supports_streaming,omitempty"`
MIME string `json:"mime_type,omitempty"` MIME string `json:"mime_type,omitempty"`
FileName string `json:"file_name,omitempty"` FileName string `json:"file_name,omitempty"`
ParseMode ParseMode `json:"parse_mode,omitempty"`
} }
// MediaFile returns &Video.File // MediaFile returns &Video.File
func (v *Video) MediaFile() *File { func (v *Video) MediaFile() *File {
v.fileName = v.FileName
return &v.File return &v.File
} }
@ -159,7 +150,6 @@ type Animation struct {
// MediaFile returns &Animation.File // MediaFile returns &Animation.File
func (a *Animation) MediaFile() *File { func (a *Animation) MediaFile() *File {
a.fileName = a.FileName
return &a.File return &a.File
} }

@ -50,6 +50,7 @@ func (a *Audio) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
"caption": a.Caption, "caption": a.Caption,
"performer": a.Performer, "performer": a.Performer,
"title": a.Title, "title": a.Title,
"file_name": a.FileName,
} }
b.embedSendOptions(params, opt) b.embedSendOptions(params, opt)
@ -57,7 +58,7 @@ func (a *Audio) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
params["duration"] = strconv.Itoa(a.Duration) params["duration"] = strconv.Itoa(a.Duration)
} }
msg, err := b.sendObject(a.MediaFile(), "audio", params, thumbnailToFilemap(a.Thumbnail)) msg, err := b.sendObject(&a.File, "audio", params, thumbnailToFilemap(a.Thumbnail))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -81,6 +82,7 @@ func (d *Document) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error
params := map[string]string{ params := map[string]string{
"chat_id": to.Recipient(), "chat_id": to.Recipient(),
"caption": d.Caption, "caption": d.Caption,
"file_name": d.FileName,
} }
b.embedSendOptions(params, opt) b.embedSendOptions(params, opt)
@ -88,7 +90,7 @@ func (d *Document) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error
params["file_size"] = strconv.Itoa(d.FileSize) params["file_size"] = strconv.Itoa(d.FileSize)
} }
msg, err := b.sendObject(d.MediaFile(), "document", params, thumbnailToFilemap(d.Thumbnail)) msg, err := b.sendObject(&d.File, "document", params, thumbnailToFilemap(d.Thumbnail))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -123,6 +125,7 @@ func (v *Video) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
params := map[string]string{ params := map[string]string{
"chat_id": to.Recipient(), "chat_id": to.Recipient(),
"caption": v.Caption, "caption": v.Caption,
"file_name": v.FileName,
} }
b.embedSendOptions(params, opt) b.embedSendOptions(params, opt)
@ -139,7 +142,7 @@ func (v *Video) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
params["supports_streaming"] = "true" params["supports_streaming"] = "true"
} }
msg, err := b.sendObject(v.MediaFile(), "video", params, thumbnailToFilemap(v.Thumbnail)) msg, err := b.sendObject(&v.File, "video", params, thumbnailToFilemap(v.Thumbnail))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -166,6 +169,7 @@ func (a *Animation) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, erro
params := map[string]string{ params := map[string]string{
"chat_id": to.Recipient(), "chat_id": to.Recipient(),
"caption": a.Caption, "caption": a.Caption,
"file_name": a.FileName,
} }
b.embedSendOptions(params, opt) b.embedSendOptions(params, opt)
@ -179,12 +183,12 @@ func (a *Animation) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, erro
params["height"] = strconv.Itoa(a.Height) params["height"] = strconv.Itoa(a.Height)
} }
// Without the FileName GIF sends as a document. // file_name is required, without file_name GIFs sent as document
if a.FileName == "" && a.File.OnDisk() { if params["file_name"] == "" && a.File.OnDisk() {
a.FileName = filepath.Base(a.File.FileLocal) params["file_name"] = filepath.Base(a.File.FileLocal)
} }
msg, err := b.sendObject(a.MediaFile(), "animation", params, nil) msg, err := b.sendObject(&a.File, "animation", params, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

Loading…
Cancel
Save