stt: Fix crash when called without a voice message

This commit is contained in:
Hamcha 2017-04-21 10:05:24 +02:00
parent 7c4cf6bc99
commit a7768b3ae0
2 changed files with 7 additions and 1 deletions

View file

@ -72,7 +72,7 @@ func initmods() {
func dispatch(broker *tg.Broker, update tg.APIMessage) { func dispatch(broker *tg.Broker, update tg.APIMessage) {
for _, mod := range mods { for _, mod := range mods {
if mod.OnMessage != nil { if mod.OnMessage != nil {
mod.OnMessage(broker, update) go mod.OnMessage(broker, update)
} }
} }
} }

View file

@ -32,6 +32,12 @@ func stt(broker *tg.Broker, update tg.APIMessage) {
update.Voice = update.ReplyTo.Voice 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 { 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", &update.MessageID)
return return