Update to match tg API change

This commit is contained in:
Hamcha 2018-12-13 11:29:45 +01:00
parent a6e013ede5
commit 161dcee064
Signed by: hamcha
GPG Key ID: A40413D21021EAEE
10 changed files with 130 additions and 41 deletions

View File

@ -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, "<b>Formato:</b> /tz <i>nome_timezone</i>", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>Formato:</b> /tz <i>nome_timezone</i>", &tg.MessageOptions{
ReplyID: &update.MessageID,
})
return
}
loc, err := time.LoadLocation(parts[1])
if err != nil {
broker.SendTextMessage(update.Chat, "<b>Errore:</b> non sono riuscito a trovare una timezone chiamata <b>"+parts[1]+"</b>", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>Errore:</b> non sono riuscito a trovare una timezone chiamata <b>"+parts[1]+"</b>", &tg.MessageOptions{
ReplyID: &update.MessageID,
})
return
}

View File

@ -48,7 +48,9 @@ func macro_message(broker *tg.Broker, update tg.APIMessage) {
} else {
out = fmt.Sprintf("<b>%s</b>\n<i>macro inesistente</i>\n(configura con /macro %s <i>contenuto</i>)", 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("<b>%s</b> → %s", macroname, parts[2]), &update.MessageID)
broker.SendTextMessage(update.Chat, fmt.Sprintf("<b>%s</b> → %s", macroname, parts[2]), &tg.MessageOptions{
ReplyID: &update.MessageID,
})
default:
broker.SendTextMessage(update.Chat, "<b>Sintassi</b>\n<b>Leggi</b>: /macro <i>nome-macro</i>\n<b>Scrivi</b>: /macro <i>nome-macro</i> <i>contenuto macro</i>", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>Sintassi</b>\n<b>Leggi</b>: /macro <i>nome-macro</i>\n<b>Scrivi</b>: /macro <i>nome-macro</i> <i>contenuto macro</i>", &tg.MessageOptions{
ReplyID: &update.MessageID,
})
}
}
}

View File

@ -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, "<b>Formato</b>: /meme TESTO IN ALTO<b>;</b>TESTO IN BASSO", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>Formato</b>: /meme TESTO IN ALTO<b>;</b>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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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, "<b>ERROR</b>: Non riesco a leggere l'immagine", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERROR</b>: 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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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,
})
})
}
}

View File

@ -66,6 +66,8 @@ func oroscopo_message(broker *tg.Broker, update tg.APIMessage) {
txt = txt[idx:]
break
}
broker.SendTextMessage(update.Chat, "<b>Ecco cosa dicono le stelle:</b>\n"+txt+".", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>Ecco cosa dicono le stelle:</b>\n"+txt+".", &tg.MessageOptions{
ReplyID: &update.MessageID,
})
}
}

View File

@ -67,7 +67,9 @@ func remind_message(broker *tg.Broker, update tg.APIMessage) {
}
if len(parts) < 3 {
broker.SendTextMessage(update.Chat, "<b>Sintassi</b>\n/ricordami <i>[quando]</i> Messaggio\n\n<b>Formati supportati per [quando]</b>:\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, "<b>Sintassi</b>\n/ricordami <i>[quando]</i> Messaggio\n\n<b>Formati supportati per [quando]</b>:\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 <b>%d</b> 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 <b>%d</b> reminder in coda per te", len(useritems)), &tg.MessageOptions{
ReplyID: &update.MessageID,
})
}
}
}

View File

@ -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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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,
})
}
}

View File

@ -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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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, "<b>ERROR</b>: Non riesco a leggere l'immagine", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERROR</b>: 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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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,
})
})
}
}

View File

@ -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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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,
})
})
}
}

View File

@ -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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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, "<b>ERRORE</b>: Non riesco a leggere l'immagine", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE</b>: 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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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,
})
}
}

View File

@ -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, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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 <i>&lt;PARTENZA&gt;</i> -> <i>&lt;DESTINAZIONE&gt;</i>", &update.MessageID)
broker.SendTextMessage(update.Chat, "Formato: /viaggi <i>&lt;PARTENZA&gt;</i> -> <i>&lt;DESTINAZIONE&gt;</i>", &tg.MessageOptions{
ReplyID: &update.MessageID,
})
}
func parseData(route Romeroute) string {