From 26362f1bb997eaed4fac97bc93d0e0099c013fef Mon Sep 17 00:00:00 2001 From: "Andrey Ivanov (NetMoose)" Date: Mon, 14 Feb 2022 20:04:53 +0500 Subject: [PATCH] Fix nil pointer --- inlinebotenru.go | 61 ++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/inlinebotenru.go b/inlinebotenru.go index 2e02e7b..e9ff4a6 100644 --- a/inlinebotenru.go +++ b/inlinebotenru.go @@ -44,36 +44,37 @@ func main() { user := "Unknown" if update.Message != nil { user = update.Message.From.String() - } - if update.Message.Photo != nil { - fmt.Printf("User: %s send into bot directly photo\n", user) - } - if update.Message.Animation != nil { - fmt.Printf("User: %s send into bot directly animation\n", user) - } - if update.Message.Audio != nil { - fmt.Printf("User: %s send into bot directly audio\n", user) - } - if update.Message.Document != nil { - fmt.Printf("User: %s send into bot directly document\n", user) - } - if update.Message.Location != nil { - fmt.Printf("User: %s send into bot directly location:%f, %f\n", user, update.Message.Location.Latitude, update.Message.Location.Longitude) - } - if update.Message.Sticker != nil { - fmt.Printf("User: %s send into bot directly sticker\n", user) - } - if update.Message.Video != nil { - fmt.Printf("User: %s send into bot directly video\n", user) - } - if update.Message.Voice != nil { - fmt.Printf("User: %s send into bot directly voice message\n", user) - } - if update.Message.Text != "" { - msg := tgbotapi.NewMessage(update.Message.Chat.ID, reply) - bot.Send(msg) - message := update.Message.Text - fmt.Printf("User: %s send into bot directly: %s\n", user, message) + + if update.Message.Photo != nil { + fmt.Printf("User: %s send into bot directly photo\n", user) + } + if update.Message.Animation != nil { + fmt.Printf("User: %s send into bot directly animation\n", user) + } + if update.Message.Audio != nil { + fmt.Printf("User: %s send into bot directly audio\n", user) + } + if update.Message.Document != nil { + fmt.Printf("User: %s send into bot directly document\n", user) + } + if update.Message.Location != nil { + fmt.Printf("User: %s send into bot directly location:%f, %f\n", user, update.Message.Location.Latitude, update.Message.Location.Longitude) + } + if update.Message.Sticker != nil { + fmt.Printf("User: %s send into bot directly sticker\n", user) + } + if update.Message.Video != nil { + fmt.Printf("User: %s send into bot directly video\n", user) + } + if update.Message.Voice != nil { + fmt.Printf("User: %s send into bot directly voice message\n", user) + } + if update.Message.Text != "" { + msg := tgbotapi.NewMessage(update.Message.Chat.ID, reply) + bot.Send(msg) + message := update.Message.Text + fmt.Printf("User: %s send into bot directly: %s\n", user, message) + } } continue }