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)
})
}
}