diff --git a/broker/telegram.go b/broker/telegram.go index 20fb9e5..eef548c 100644 --- a/broker/telegram.go +++ b/broker/telegram.go @@ -88,16 +88,21 @@ func (t Telegram) GetFile(data tg.FileRequestData, client net.Conn, callback int } defer resp.Body.Close() - var filespecs tg.APIFile + var filespecs = struct { + Ok bool `json:"ok"` + Result *tg.APIFile `json:"result,omitempty"` + }{} err = json.NewDecoder(resp.Body).Decode(&filespecs) if checkerr("GetFile/json.Decode", err) { fail("Server sent garbage (or error)") return } + if filespecs.Result == nil { + fail("Server didn't send a file info, does the file exist?") + return + } - fmt.Println(filespecs) - - path := "https://api.telegram.org/file/bot" + t.Token + "/" + *(filespecs.Path) + path := APIEndpoint + "file/bot" + t.Token + "/" + *(*(filespecs.Result).Path) fileresp, err := http.Get(path) if checkerr("GetFile/get", err) { fail("Could not retrieve file from Telegram's servers") diff --git a/mods/memegen.go b/mods/memegen.go index 5f1831c..d62e79f 100644 --- a/mods/memegen.go +++ b/mods/memegen.go @@ -56,6 +56,7 @@ func memegen(broker *tg.Broker, update tg.APIMessage) { photo = curphoto } } + broker.GetFile(photo.FileID, func(broker *tg.Broker, data tg.BrokerUpdate) { pbytes, err := base64.StdEncoding.DecodeString(*data.Bytes) if err != nil {