From 161dcee064678147df476295d2a35391af9a1351 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Thu, 13 Dec 2018 11:29:45 +0100 Subject: [PATCH] Update to match tg API change --- mods/config.go | 8 ++++++-- mods/macro.go | 12 +++++++++--- mods/memegen.go | 24 ++++++++++++++++++------ mods/oroscopo.go | 4 +++- mods/remind.go | 27 ++++++++++++++++++++++----- mods/search.go | 16 ++++++++++++---- mods/snapchat.go | 20 +++++++++++++++----- mods/stt.go | 24 ++++++++++++++++++------ mods/unsplash.go | 24 ++++++++++++++++++------ mods/viaggi.go | 12 +++++++++--- 10 files changed, 130 insertions(+), 41 deletions(-) diff --git a/mods/config.go b/mods/config.go index 47f8116..41b61f7 100644 --- a/mods/config.go +++ b/mods/config.go @@ -43,13 +43,17 @@ func tz_message(broker *tg.Broker, update tg.APIMessage) { if isCommand(update, "tz") { parts := strings.SplitN(*(update.Text), " ", 2) if len(parts) < 2 { - broker.SendTextMessage(update.Chat, "Formato: /tz nome_timezone", &update.MessageID) + broker.SendTextMessage(update.Chat, "Formato: /tz nome_timezone", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } loc, err := time.LoadLocation(parts[1]) if err != nil { - broker.SendTextMessage(update.Chat, "Errore: non sono riuscito a trovare una timezone chiamata "+parts[1]+"", &update.MessageID) + broker.SendTextMessage(update.Chat, "Errore: non sono riuscito a trovare una timezone chiamata "+parts[1]+"", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } diff --git a/mods/macro.go b/mods/macro.go index 09d7ee1..31a9108 100644 --- a/mods/macro.go +++ b/mods/macro.go @@ -48,7 +48,9 @@ func macro_message(broker *tg.Broker, update tg.APIMessage) { } else { out = fmt.Sprintf("%s\nmacro inesistente\n(configura con /macro %s contenuto)", macroname, macroname) } - broker.SendTextMessage(update.Chat, out, &update.MessageID) + broker.SendTextMessage(update.Chat, out, &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) case 3: macroname := strings.ToLower(parts[1]) macros[macroname] = Macro{ @@ -57,9 +59,13 @@ func macro_message(broker *tg.Broker, update tg.APIMessage) { Time: time.Now(), } savemacros() - broker.SendTextMessage(update.Chat, fmt.Sprintf("%s → %s", macroname, parts[2]), &update.MessageID) + broker.SendTextMessage(update.Chat, fmt.Sprintf("%s → %s", macroname, parts[2]), &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) default: - broker.SendTextMessage(update.Chat, "Sintassi\nLeggi: /macro nome-macro\nScrivi: /macro nome-macro contenuto macro", &update.MessageID) + broker.SendTextMessage(update.Chat, "Sintassi\nLeggi: /macro nome-macro\nScrivi: /macro nome-macro contenuto macro", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) } } } diff --git a/mods/memegen.go b/mods/memegen.go index 60f9e62..ace9bcf 100644 --- a/mods/memegen.go +++ b/mods/memegen.go @@ -49,7 +49,9 @@ func meme_message(broker *tg.Broker, update tg.APIMessage) { if strings.HasPrefix(caption, "/meme ") && len(caption) > 6 { idx := strings.Index(caption, ";") if idx < 0 { - broker.SendTextMessage(update.Chat, "Formato: /meme TESTO IN ALTO;TESTO IN BASSO", &update.MessageID) + broker.SendTextMessage(update.Chat, "Formato: /meme TESTO IN ALTO;TESTO IN BASSO", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } @@ -68,21 +70,27 @@ func meme_message(broker *tg.Broker, update tg.APIMessage) { broker.GetFile(photo.FileID, func(broker *tg.Broker, data tg.BrokerUpdate) { if data.Type == tg.BError { log.Printf("[memegen] Received error from broker: %s\n", *data.Error) - broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } pbytes, err := base64.StdEncoding.DecodeString(*data.Bytes) if err != nil { log.Printf("[memegen] Base64 decode error: %s\n", err.Error()) - broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } img, _, err := image.Decode(bytes.NewReader(pbytes)) if err != nil { log.Printf("[memegen] Image decode error: %s\n", err.Error()) - broker.SendTextMessage(update.Chat, "ERROR: Non riesco a leggere l'immagine", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERROR: Non riesco a leggere l'immagine", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } @@ -176,10 +184,14 @@ func meme_message(broker *tg.Broker, update tg.APIMessage) { err = jpeg.Encode(buf, timg, &(jpeg.Options{Quality: 80})) if err != nil { log.Printf("[memegen] Image encode error: %s\n", err.Error()) - broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } - broker.SendPhoto(update.Chat, buf.Bytes(), "meme.jpg", "", &update.MessageID) + broker.SendPhoto(update.Chat, buf.Bytes(), "meme.jpg", "", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) }) } } diff --git a/mods/oroscopo.go b/mods/oroscopo.go index 4427504..6c46704 100644 --- a/mods/oroscopo.go +++ b/mods/oroscopo.go @@ -66,6 +66,8 @@ func oroscopo_message(broker *tg.Broker, update tg.APIMessage) { txt = txt[idx:] break } - broker.SendTextMessage(update.Chat, "Ecco cosa dicono le stelle:\n"+txt+".", &update.MessageID) + broker.SendTextMessage(update.Chat, "Ecco cosa dicono le stelle:\n"+txt+".", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) } } diff --git a/mods/remind.go b/mods/remind.go index ec8d037..654a5f2 100644 --- a/mods/remind.go +++ b/mods/remind.go @@ -67,7 +67,9 @@ func remind_message(broker *tg.Broker, update tg.APIMessage) { } if len(parts) < 3 { - broker.SendTextMessage(update.Chat, "Sintassi\n/ricordami [quando] Messaggio\n\nFormati supportati per [quando]:\n 10s 10m 10h 10d (secondi/minuti/ore/giorni)\n 13:20 15:55:01 (ora dello stesso giorno, formato 24h)\n 11/02/2099 11/02/2099-11:20:01 (giorno diverso, stessa ora [1] o specifica [2])", &update.MessageID) + broker.SendTextMessage(update.Chat, "Sintassi\n/ricordami [quando] Messaggio\n\nFormati supportati per [quando]:\n 10s 10m 10h 10d (secondi/minuti/ore/giorni)\n 13:20 15:55:01 (ora dello stesso giorno, formato 24h)\n 11/02/2099 11/02/2099-11:20:01 (giorno diverso, stessa ora [1] o specifica [2])", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } @@ -76,7 +78,9 @@ func remind_message(broker *tg.Broker, update tg.APIMessage) { timestamp, err := parseDuration(format) if err != nil { - broker.SendTextMessage(update.Chat, err.Error(), &update.MessageID) + broker.SendTextMessage(update.Chat, err.Error(), &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } @@ -103,13 +107,17 @@ func remind_message(broker *tg.Broker, update tg.APIMessage) { whenday = "il " + timestamp.Format("2/1") } whentime := "alle " + timestamp.Format("15:04:05") - broker.SendTextMessage(update.Chat, "Ok, vedrò di avvisarti "+whenday+" "+whentime, &update.MessageID) + broker.SendTextMessage(update.Chat, "Ok, vedrò di avvisarti "+whenday+" "+whentime, &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) } if isCommand(update, "reminders") { // Should only work in private chats if update.Chat.Type != tg.ChatTypePrivate { - broker.SendTextMessage(update.Chat, "Per favore chiedimi in privato dei reminder", &update.MessageID) + broker.SendTextMessage(update.Chat, "Per favore chiedimi in privato dei reminder", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } @@ -120,7 +128,16 @@ func remind_message(broker *tg.Broker, update tg.APIMessage) { } } - broker.SendTextMessage(update.Chat, fmt.Sprintf("Ci sono %d reminder in coda per te", len(useritems)), &update.MessageID) + if len(useritems) == 0 { + broker.SendTextMessage(update.Chat, "Non ci sono reminder in coda per te", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) + } else { + broker.SendTextMessage(update.Chat, fmt.Sprintf("Ci sono %d reminder in coda per te", len(useritems)), &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) + } + } } diff --git a/mods/search.go b/mods/search.go index 73684ab..abc56bf 100644 --- a/mods/search.go +++ b/mods/search.go @@ -61,7 +61,9 @@ func search_message(broker *tg.Broker, update tg.APIMessage) { if isCommand(update, "search") { parts := strings.SplitN(*(update.Text), " ", 2) if len(parts) < 2 { - broker.SendTextMessage(update.Chat, "Non mi hai dato niente da cercare!", &update.MessageID) + broker.SendTextMessage(update.Chat, "Non mi hai dato niente da cercare!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } broker.SendChatAction(update.Chat, tg.ActionTyping) @@ -69,12 +71,16 @@ func search_message(broker *tg.Broker, update tg.APIMessage) { result, err := searchAPI(parts[1]) if err != nil { log.Printf("[search] %s\n", err.Error()) - broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } if result.None { - broker.SendTextMessage(update.Chat, "Non ho trovato nulla, mi spiace :(", &update.MessageID) + broker.SendTextMessage(update.Chat, "Non ho trovato nulla, mi spiace :(", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } @@ -86,7 +92,9 @@ func search_message(broker *tg.Broker, update tg.APIMessage) { resulttxt += "\nAlternativamente:\n - " + strings.Join(result.Alternatives, "\n - ") } - broker.SendTextMessage(update.Chat, resulttxt, &update.MessageID) + broker.SendTextMessage(update.Chat, resulttxt, &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) } } diff --git a/mods/snapchat.go b/mods/snapchat.go index f270ecd..0134813 100644 --- a/mods/snapchat.go +++ b/mods/snapchat.go @@ -68,21 +68,27 @@ func snapchat_message(broker *tg.Broker, update tg.APIMessage) { broker.GetFile(photo.FileID, func(broker *tg.Broker, data tg.BrokerUpdate) { if data.Type == tg.BError { log.Printf("[snapchat] Received error from broker: %s\n", *data.Error) - broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } pbytes, err := base64.StdEncoding.DecodeString(*data.Bytes) if err != nil { log.Printf("[snapchat] Base64 decode error: %s\n", err.Error()) - broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } img, _, err := image.Decode(bytes.NewReader(pbytes)) if err != nil { log.Printf("[snapchat] Image decode error: %s\n", err.Error()) - broker.SendTextMessage(update.Chat, "ERROR: Non riesco a leggere l'immagine", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERROR: Non riesco a leggere l'immagine", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } @@ -159,10 +165,14 @@ func snapchat_message(broker *tg.Broker, update tg.APIMessage) { err = jpeg.Encode(buf, timg, &(jpeg.Options{Quality: 80})) if err != nil { log.Printf("[snapchat] Image encode error: %s\n", err.Error()) - broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } - broker.SendPhoto(update.Chat, buf.Bytes(), "meme.jpg", "", &update.MessageID) + broker.SendPhoto(update.Chat, buf.Bytes(), "meme.jpg", "", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) }) } } diff --git a/mods/stt.go b/mods/stt.go index eb9a71b..a06b305 100644 --- a/mods/stt.go +++ b/mods/stt.go @@ -34,26 +34,34 @@ func stt_message(broker *tg.Broker, update tg.APIMessage) { // Make sure it's a voice message if update.Voice == nil { - broker.SendTextMessage(update.Chat, "Non vedo un messaggio vocale da ascoltare", &update.MessageID) + broker.SendTextMessage(update.Chat, "Non vedo un messaggio vocale da ascoltare", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } if update.Voice.Duration > 60 { - broker.SendTextMessage(update.Chat, "L'audio dura un bel po' (> 1 minuto), al momento non posso farci nulla :S", &update.MessageID) + broker.SendTextMessage(update.Chat, "L'audio dura un bel po' (> 1 minuto), al momento non posso farci nulla :S", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } broker.GetFile(update.Voice.FileID, func(broker *tg.Broker, data tg.BrokerUpdate) { if data.Type == tg.BError { log.Printf("[stt] Received error from broker: %s\n", *data.Error) - broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } bytes, err := base64.StdEncoding.DecodeString(*data.Bytes) if err != nil { log.Printf("[stt] Base64 decode error: %s\n", err.Error()) - broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } @@ -70,7 +78,9 @@ func stt_message(broker *tg.Broker, update tg.APIMessage) { }) if err != nil { log.Printf("[stt] STT request error: %s\n", err.Error()) - broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } @@ -81,7 +91,9 @@ func stt_message(broker *tg.Broker, update tg.APIMessage) { } } - broker.SendTextMessage(update.Chat, out, &update.MessageID) + broker.SendTextMessage(update.Chat, out, &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) }) } } diff --git a/mods/unsplash.go b/mods/unsplash.go index 7489ad6..45e8a29 100644 --- a/mods/unsplash.go +++ b/mods/unsplash.go @@ -63,7 +63,9 @@ func unsplash_message(broker *tg.Broker, update tg.APIMessage) { case update.ReplyTo.Caption != nil: text = *(update.ReplyTo.Caption) default: - broker.SendTextMessage(update.Chat, "Non c'e' niente di 'ispiratore' in questo..", &update.MessageID) + broker.SendTextMessage(update.Chat, "Non c'e' niente di 'ispiratore' in questo..", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } @@ -89,14 +91,18 @@ func unsplash_message(broker *tg.Broker, update tg.APIMessage) { author += " (" + user.Username + ")" if strings.TrimSpace(text) == "" { - broker.SendTextMessage(update.Chat, "Non c'e' niente di 'ispiratore' in questo..", &update.MessageID) + broker.SendTextMessage(update.Chat, "Non c'e' niente di 'ispiratore' in questo..", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } resp, err := http.Get(unsplashUrl) if err != nil { log.Printf("[unsplash] HTTP request failed: %s\nOriginal URL: %s\n", err.Error(), unsplashUrl) - broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } defer resp.Body.Close() @@ -104,7 +110,9 @@ func unsplash_message(broker *tg.Broker, update tg.APIMessage) { img, _, err := image.Decode(resp.Body) if err != nil { log.Printf("[unsplash] Image decode error: %s\nOriginal URL: %s\n", err.Error(), unsplashUrl) - broker.SendTextMessage(update.Chat, "ERRORE: Non riesco a leggere l'immagine", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE: Non riesco a leggere l'immagine", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } @@ -199,9 +207,13 @@ func unsplash_message(broker *tg.Broker, update tg.APIMessage) { err = jpeg.Encode(buf, timg, &(jpeg.Options{Quality: 80})) if err != nil { log.Println("[unsplash] Image encode error: %s\n", err.Error()) - broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } - broker.SendPhoto(update.Chat, buf.Bytes(), "quote.jpg", "", &update.MessageID) + broker.SendPhoto(update.Chat, buf.Bytes(), "quote.jpg", "", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) } } diff --git a/mods/viaggi.go b/mods/viaggi.go index d694776..589b03d 100644 --- a/mods/viaggi.go +++ b/mods/viaggi.go @@ -43,16 +43,22 @@ func viaggi_message(broker *tg.Broker, update tg.APIMessage) { out, err := viaggiAPI(msgs[1], msgs[2]) if err != nil { log.Println("[viaggi] " + err.Error()) - broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) + broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) return } - broker.SendTextMessage(update.Chat, out, &update.MessageID) + broker.SendTextMessage(update.Chat, out, &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) } } func viaggi_help(broker *tg.Broker, update tg.APIMessage) { - broker.SendTextMessage(update.Chat, "Formato: /viaggi <PARTENZA> -> <DESTINAZIONE>", &update.MessageID) + broker.SendTextMessage(update.Chat, "Formato: /viaggi <PARTENZA> -> <DESTINAZIONE>", &tg.MessageOptions{ + ReplyID: &update.MessageID, + }) } func parseData(route Romeroute) string {