From 47fe2c8a8521768b53defac866c2c2c034fc4726 Mon Sep 17 00:00:00 2001 From: Nicolas MASSE Date: Fri, 20 Dec 2019 12:18:24 +0100 Subject: [PATCH] cleanup + doc --- README.md | 2 ++ main.go | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4cd68ec..ffda8e0 100644 --- a/README.md +++ b/README.md @@ -94,3 +94,5 @@ service photo-bot start ## Documentation - https://core.telegram.org/bots/api +- https://go-telegram-bot-api.github.io +- https://github.com/go-telegram-bot-api/telegram-bot-api diff --git a/main.go b/main.go index a0fc8ed..129ed51 100644 --- a/main.go +++ b/main.go @@ -115,16 +115,17 @@ func main() { } if text != "" { - if strings.HasPrefix(text, "/") { + if update.Message.IsCommand() { log.Printf("[%s] command: %s", username, text) - if strings.HasPrefix(text, "/start") || strings.HasPrefix(text, "/aide") || strings.HasPrefix(text, "/help") { + switch update.Message.Command() { + case "start", "aide", "help": replyWithMessage(bot, update.Message, viper.GetString("MsgHelp")) - } else if strings.HasPrefix(text, "/nouvelAlbum") { + case "nouvelAlbum": if len(text) < 14 { replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgMissingAlbumName")) continue } - albumName := text[13:len(text)] + albumName := update.Message.CommandArguments() if albumAlreadyOpen() { replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgAlbumAlreadyCreated")) @@ -139,7 +140,7 @@ func main() { } replyWithMessage(bot, update.Message, viper.GetString("MsgAlbumCreated")) - } else if strings.HasPrefix(text, "/info") { + case "info": if albumAlreadyOpen() { albumName, err := getInfo() if err != nil { @@ -151,7 +152,7 @@ func main() { } else { replyWithMessage(bot, update.Message, viper.GetString("MsgInfoNoAlbum")) } - } else if strings.HasPrefix(text, "/cloreAlbum") { + case "cloreAlbum": if !albumAlreadyOpen() { replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgNoAlbum")) continue @@ -165,7 +166,7 @@ func main() { } replyWithMessage(bot, update.Message, viper.GetString("MsgAlbumClosed")) - } else { + default: replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgDoNotUnderstand")) continue }