From f1aae4f2a49e504bf14228cc02ae86e644f5dc6c Mon Sep 17 00:00:00 2001 From: Hamcha Date: Sat, 20 Feb 2016 22:33:09 +0100 Subject: [PATCH] Forgot to fix the broker as well --- broker/clients.go | 13 ++++++++++++- mods/memegen.go | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/broker/clients.go b/broker/clients.go index 2882528..5789d4b 100644 --- a/broker/clients.go +++ b/broker/clients.go @@ -33,11 +33,18 @@ func handleClient(c net.Conn) { defer c.Close() // Start reading messages + buf := make([]byte, 0) for { - bytes, _, err := b.ReadLine() + bytes, isPrefix, err := b.ReadLine() if err != nil { break } + buf = append(buf, bytes...) + if isPrefix { + continue + } + + // Get command var cmd tg.ClientCommand err = json.Unmarshal(bytes, &cmd) if err != nil { @@ -45,6 +52,10 @@ func handleClient(c net.Conn) { log.Printf("%s\n", string(bytes)) continue } + + // Empty buffer + buf = []byte{} + executeClientCommand(cmd, c) } removeCon(c) diff --git a/mods/memegen.go b/mods/memegen.go index 5a04028..3b68784 100644 --- a/mods/memegen.go +++ b/mods/memegen.go @@ -58,6 +58,12 @@ func memegen(broker *tg.Broker, update tg.APIMessage) { } broker.GetFile(photo.FileID, func(broker *tg.Broker, data tg.BrokerUpdate) { + if data.Type == tg.BError { + log.Println("[memegen] Received error from broker: %s\n", *data.Error) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + return + } + pbytes, err := base64.StdEncoding.DecodeString(*data.Bytes) if err != nil { log.Println("[memegen] Base64 decode error: %s\n", err.Error()) @@ -161,6 +167,7 @@ func memegen(broker *tg.Broker, update tg.APIMessage) { broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) return } + broker.SendPhoto(update.Chat, buf.Bytes(), nil, &update.MessageID) }) } }