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()
writer := multipart.NewWriter(pipeWriter)
go func() {
defer pipeWriter.Close()
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)
return
}

@ -450,6 +450,7 @@ func (b *Bot) ProcessUpdate(upd Update) {
return
}
}
func (b *Bot) handle(end string, m *Message) bool {
@ -562,10 +563,10 @@ func (b *Bot) SendAlbum(to Recipient, a Album, options ...interface{}) ([]Messag
switch y := x.(type) {
case *Photo:
data, _ = json.Marshal(struct {
Type string `json:"type"`
Media string `json:"media"`
Caption string `json:"caption,omitempty"`
ParseMode string `json:"parse_mode,omitempty"`
Type string `json:"type"`
Media string `json:"media"`
Caption string `json:"caption,omitempty"`
ParseMode ParseMode `json:"parse_mode,omitempty"`
}{
Type: "photo",
Media: repr,
@ -581,7 +582,6 @@ func (b *Bot) SendAlbum(to Recipient, a Album, options ...interface{}) ([]Messag
Height int `json:"height,omitempty"`
Duration int `json:"duration,omitempty"`
SupportsStreaming bool `json:"supports_streaming,omitempty"`
ParseMode string `json:"parse_mode,omitempty"`
}{
Type: "video",
Caption: y.Caption,
@ -590,37 +590,6 @@ func (b *Bot) SendAlbum(to Recipient, a Album, options ...interface{}) ([]Messag
Height: y.Height,
Duration: y.Duration,
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:
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 {
i, _ := strconv.Atoi(attachName)
r := resp.Result[i]
var newID string
switch {
case r.Photo != nil:
newID = r.Photo.FileID
case r.Video != nil:
newID = r.Video.FileID
case r.Audio != nil:
newID = r.Audio.FileID
case r.Document != nil:
newID = r.Document.FileID
if resp.Result[i].Photo != nil {
newID = resp.Result[i].Photo.FileID
} else {
newID = resp.Result[i].Video.FileID
}
a[i].MediaFile().FileID = newID

@ -22,9 +22,6 @@ type File struct {
// file backed with io.Reader
FileReader io.Reader `json:"-"`
// intermediate file name value to use later in sendFiles
fileName string
}
// 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)
// outer layers of Telebot require it.
MediaFile() *File
// NOTE: To add in v3.
// Type() string
}
// Photo object represents a single photo file.
@ -83,18 +80,16 @@ type Audio struct {
Duration int `json:"duration,omitempty"`
// (Optional)
Caption string `json:"caption,omitempty"`
Thumbnail *Photo `json:"thumb,omitempty"`
Title string `json:"title,omitempty"`
Performer string `json:"performer,omitempty"`
MIME string `json:"mime_type,omitempty"`
FileName string `json:"file_name,omitempty"`
ParseMode ParseMode `json:"parse_mode,omitempty"`
Caption string `json:"caption,omitempty"`
Thumbnail *Photo `json:"thumb,omitempty"`
Title string `json:"title,omitempty"`
Performer string `json:"performer,omitempty"`
MIME string `json:"mime_type,omitempty"`
FileName string `json:"file_name,omitempty"`
}
// MediaFile returns &Audio.File
func (a *Audio) MediaFile() *File {
a.fileName = a.FileName
return &a.File
}
@ -104,16 +99,14 @@ type Document struct {
File
// (Optional)
Thumbnail *Photo `json:"thumb,omitempty"`
Caption string `json:"caption,omitempty"`
MIME string `json:"mime_type"`
FileName string `json:"file_name,omitempty"`
ParseMode ParseMode `json:"parse_mode,omitempty"`
Thumbnail *Photo `json:"thumb,omitempty"`
Caption string `json:"caption,omitempty"`
MIME string `json:"mime_type"`
FileName string `json:"file_name,omitempty"`
}
// MediaFile returns &Document.File
func (d *Document) MediaFile() *File {
d.fileName = d.FileName
return &d.File
}
@ -127,17 +120,15 @@ type Video struct {
Duration int `json:"duration,omitempty"`
// (Optional)
Caption string `json:"caption,omitempty"`
Thumbnail *Photo `json:"thumb,omitempty"`
SupportsStreaming bool `json:"supports_streaming,omitempty"`
MIME string `json:"mime_type,omitempty"`
FileName string `json:"file_name,omitempty"`
ParseMode ParseMode `json:"parse_mode,omitempty"`
Caption string `json:"caption,omitempty"`
Thumbnail *Photo `json:"thumb,omitempty"`
SupportsStreaming bool `json:"supports_streaming,omitempty"`
MIME string `json:"mime_type,omitempty"`
FileName string `json:"file_name,omitempty"`
}
// MediaFile returns &Video.File
func (v *Video) MediaFile() *File {
v.fileName = v.FileName
return &v.File
}
@ -159,7 +150,6 @@ type Animation struct {
// MediaFile returns &Animation.File
func (a *Animation) MediaFile() *File {
a.fileName = a.FileName
return &a.File
}

@ -50,6 +50,7 @@ func (a *Audio) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
"caption": a.Caption,
"performer": a.Performer,
"title": a.Title,
"file_name": a.FileName,
}
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)
}
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 {
return nil, err
}
@ -79,8 +80,9 @@ func (a *Audio) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
// Send delivers media through bot b to recipient.
func (d *Document) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
params := map[string]string{
"chat_id": to.Recipient(),
"caption": d.Caption,
"chat_id": to.Recipient(),
"caption": d.Caption,
"file_name": d.FileName,
}
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)
}
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 {
return nil, err
}
@ -121,8 +123,9 @@ func (s *Sticker) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error)
// Send delivers media through bot b to recipient.
func (v *Video) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
params := map[string]string{
"chat_id": to.Recipient(),
"caption": v.Caption,
"chat_id": to.Recipient(),
"caption": v.Caption,
"file_name": v.FileName,
}
b.embedSendOptions(params, opt)
@ -139,7 +142,7 @@ func (v *Video) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
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 {
return nil, err
}
@ -164,8 +167,9 @@ func (v *Video) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
// @see https://core.telegram.org/bots/api#sendanimation
func (a *Animation) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
params := map[string]string{
"chat_id": to.Recipient(),
"caption": a.Caption,
"chat_id": to.Recipient(),
"caption": a.Caption,
"file_name": a.FileName,
}
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)
}
// Without the FileName GIF sends as a document.
if a.FileName == "" && a.File.OnDisk() {
a.FileName = filepath.Base(a.File.FileLocal)
// file_name is required, without file_name GIFs sent as document
if params["file_name"] == "" && a.File.OnDisk() {
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 {
return nil, err
}

Loading…
Cancel
Save