Forgot to fix the broker as well
This commit is contained in:
parent
a49072ab16
commit
f1aae4f2a4
2 changed files with 19 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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, "<b>ERRORE!</b> @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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
|
||||
return
|
||||
}
|
||||
broker.SendPhoto(update.Chat, buf.Bytes(), nil, &update.MessageID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue