From 23b847b94a7edbb0cb38dbbfb5dc8178ffaf14f9 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Sat, 20 Feb 2016 21:57:04 +0100 Subject: [PATCH] DEBUG MODE ..OFF? --- broker/telegram.go | 13 +++++++++---- mods/memegen.go | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) 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 {