Sending photos by URL.

pull/108/head
Ian Byrd 7 years ago
parent 7316e92265
commit 2f62e39c40
No known key found for this signature in database
GPG Key ID: 598F598CA3B8055F

@ -103,6 +103,9 @@ func (b *Bot) sendObject(f *File, what string, params map[string]string) (*Messa
if f.InCloud() {
params[what] = f.FileID
respJSON, err = b.sendCommand(sendWhat, params)
} else if f.FileURL != nil {
params[what] = f.FileURL.String()
respJSON, err = b.sendCommand(sendWhat, params)
} else {
respJSON, err = b.sendFile(sendWhat, what, f.FileLocal, params)
}

@ -46,12 +46,14 @@ func FromURL(u *url.URL) File {
return File{FileURL: u}
}
func (f *File) importLocal(g *File) {
if !g.OnDisk() {
return
func (f *File) stealRef(g *File) {
if g.OnDisk() {
f.FileLocal = g.FileLocal
}
f.FileLocal = g.FileLocal
if g.FileURL != nil {
f.FileURL = g.FileURL
}
}
// InCloud tells whether the file is present on Telegram servers.

@ -1,9 +1,6 @@
package telebot
import (
"encoding/json"
"fmt"
)
import "encoding/json"
type photoSize struct {
File
@ -27,7 +24,6 @@ type Photo struct {
}
func (p *Photo) UnmarshalJSON(jsonStr []byte) error {
fmt.Println(string(jsonStr))
var hq photoSize
if jsonStr[0] == '{' {

@ -31,7 +31,7 @@ func (p *Photo) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
return nil, err
}
msg.Photo.File.importLocal(&p.File)
msg.Photo.File.stealRef(&p.File)
*p = *msg.Photo
return msg, nil
@ -49,7 +49,7 @@ func (a *Audio) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
return nil, err
}
msg.Audio.File.importLocal(&a.File)
msg.Audio.File.stealRef(&a.File)
*a = *msg.Audio
return msg, nil
@ -67,7 +67,7 @@ func (d *Document) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error
return nil, err
}
msg.Document.File.importLocal(&d.File)
msg.Document.File.stealRef(&d.File)
*d = *msg.Document
return msg, nil
@ -84,7 +84,7 @@ func (s *Sticker) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error)
return nil, err
}
msg.Sticker.File.importLocal(&s.File)
msg.Sticker.File.stealRef(&s.File)
*s = *msg.Sticker
return msg, nil
@ -102,7 +102,7 @@ func (v *Video) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
return nil, err
}
msg.Video.File.importLocal(&v.File)
msg.Video.File.stealRef(&v.File)
*v = *msg.Video
return msg, nil
@ -119,7 +119,7 @@ func (v *Voice) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
return nil, err
}
msg.Voice.File.importLocal(&v.File)
msg.Voice.File.stealRef(&v.File)
*v = *msg.Voice
return msg, nil
@ -136,7 +136,7 @@ func (v *VideoNote) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, erro
return nil, err
}
msg.VideoNote.File.importLocal(&v.File)
msg.VideoNote.File.stealRef(&v.File)
*v = *msg.VideoNote
return msg, nil

Loading…
Cancel
Save