From a7768b3ae05c18e048356fd38acf0d21a8220df9 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Fri, 21 Apr 2017 10:05:24 +0200 Subject: [PATCH] stt: Fix crash when called without a voice message --- mods/main.go | 2 +- mods/stt.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mods/main.go b/mods/main.go index a6a50a0..77ba7ff 100644 --- a/mods/main.go +++ b/mods/main.go @@ -72,7 +72,7 @@ func initmods() { func dispatch(broker *tg.Broker, update tg.APIMessage) { for _, mod := range mods { if mod.OnMessage != nil { - mod.OnMessage(broker, update) + go mod.OnMessage(broker, update) } } } diff --git a/mods/stt.go b/mods/stt.go index 15ceced..6925950 100644 --- a/mods/stt.go +++ b/mods/stt.go @@ -32,6 +32,12 @@ func stt(broker *tg.Broker, update tg.APIMessage) { update.Voice = update.ReplyTo.Voice } + // Make sure it's a voice message + if update.Voice == nil { + broker.SendTextMessage(update.Chat, "Non vedo un messaggio vocale da ascoltare", &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) return