Browse Source

cleanup + doc

master
Nicolas Massé 6 years ago
parent
commit
47fe2c8a85
  1. 2
      README.md
  2. 15
      main.go

2
README.md

@ -94,3 +94,5 @@ service photo-bot start
## Documentation ## Documentation
- https://core.telegram.org/bots/api - https://core.telegram.org/bots/api
- https://go-telegram-bot-api.github.io
- https://github.com/go-telegram-bot-api/telegram-bot-api

15
main.go

@ -115,16 +115,17 @@ func main() {
} }
if text != "" { if text != "" {
if strings.HasPrefix(text, "/") { if update.Message.IsCommand() {
log.Printf("[%s] command: %s", username, text) 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")) replyWithMessage(bot, update.Message, viper.GetString("MsgHelp"))
} else if strings.HasPrefix(text, "/nouvelAlbum") { case "nouvelAlbum":
if len(text) < 14 { if len(text) < 14 {
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgMissingAlbumName")) replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgMissingAlbumName"))
continue continue
} }
albumName := text[13:len(text)] albumName := update.Message.CommandArguments()
if albumAlreadyOpen() { if albumAlreadyOpen() {
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgAlbumAlreadyCreated")) replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgAlbumAlreadyCreated"))
@ -139,7 +140,7 @@ func main() {
} }
replyWithMessage(bot, update.Message, viper.GetString("MsgAlbumCreated")) replyWithMessage(bot, update.Message, viper.GetString("MsgAlbumCreated"))
} else if strings.HasPrefix(text, "/info") { case "info":
if albumAlreadyOpen() { if albumAlreadyOpen() {
albumName, err := getInfo() albumName, err := getInfo()
if err != nil { if err != nil {
@ -151,7 +152,7 @@ func main() {
} else { } else {
replyWithMessage(bot, update.Message, viper.GetString("MsgInfoNoAlbum")) replyWithMessage(bot, update.Message, viper.GetString("MsgInfoNoAlbum"))
} }
} else if strings.HasPrefix(text, "/cloreAlbum") { case "cloreAlbum":
if !albumAlreadyOpen() { if !albumAlreadyOpen() {
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgNoAlbum")) replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgNoAlbum"))
continue continue
@ -165,7 +166,7 @@ func main() {
} }
replyWithMessage(bot, update.Message, viper.GetString("MsgAlbumClosed")) replyWithMessage(bot, update.Message, viper.GetString("MsgAlbumClosed"))
} else { default:
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgDoNotUnderstand")) replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgDoNotUnderstand"))
continue continue
} }

Loading…
Cancel
Save