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()
|
defer c.Close()
|
||||||
|
|
||||||
// Start reading messages
|
// Start reading messages
|
||||||
|
buf := make([]byte, 0)
|
||||||
for {
|
for {
|
||||||
bytes, _, err := b.ReadLine()
|
bytes, isPrefix, err := b.ReadLine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
buf = append(buf, bytes...)
|
||||||
|
if isPrefix {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get command
|
||||||
var cmd tg.ClientCommand
|
var cmd tg.ClientCommand
|
||||||
err = json.Unmarshal(bytes, &cmd)
|
err = json.Unmarshal(bytes, &cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -45,6 +52,10 @@ func handleClient(c net.Conn) {
|
||||||
log.Printf("%s\n", string(bytes))
|
log.Printf("%s\n", string(bytes))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Empty buffer
|
||||||
|
buf = []byte{}
|
||||||
|
|
||||||
executeClientCommand(cmd, c)
|
executeClientCommand(cmd, c)
|
||||||
}
|
}
|
||||||
removeCon(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) {
|
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)
|
pbytes, err := base64.StdEncoding.DecodeString(*data.Bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("[memegen] Base64 decode error: %s\n", err.Error())
|
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)
|
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
broker.SendPhoto(update.Chat, buf.Bytes(), nil, &update.MessageID)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue