Browse Source

add a message + log user first and last name

master
Nicolas Massé 6 years ago
parent
commit
7b72c0c33b
  1. 14
      main.go

14
main.go

@ -31,6 +31,7 @@ func main() {
viper.SetDefault("MsgAlbumClosed", "Album closed") viper.SetDefault("MsgAlbumClosed", "Album closed")
viper.SetDefault("MsgDoNotUnderstand", "Unknown command") viper.SetDefault("MsgDoNotUnderstand", "Unknown command")
viper.SetDefault("MsgNoUsername", "Sorry, you need to set your username") viper.SetDefault("MsgNoUsername", "Sorry, you need to set your username")
viper.SetDefault("MsgThankYou", "Thanks!")
viper.SetConfigName("photo-bot") // name of config file (without extension) viper.SetConfigName("photo-bot") // name of config file (without extension)
viper.AddConfigPath("/etc/photo-bot/") viper.AddConfigPath("/etc/photo-bot/")
@ -136,7 +137,7 @@ func main() {
continue continue
} }
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgAlbumCreated")) replyWithMessage(bot, update.Message, viper.GetString("MsgAlbumCreated"))
} else if strings.HasPrefix(text, "/cloreAlbum") { } else if strings.HasPrefix(text, "/cloreAlbum") {
if !albumAlreadyOpen() { if !albumAlreadyOpen() {
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgNoAlbum")) replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgNoAlbum"))
@ -150,7 +151,7 @@ func main() {
continue continue
} }
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgAlbumClosed")) replyWithMessage(bot, update.Message, viper.GetString("MsgAlbumClosed"))
} else { } else {
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgDoNotUnderstand")) replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgDoNotUnderstand"))
continue continue
@ -168,6 +169,7 @@ func main() {
continue continue
} }
//dispatchMessage(bot, update.Message) //dispatchMessage(bot, update.Message)
replyWithMessage(bot, update.Message, viper.GetString("MsgThankYou"))
} }
} else if update.Message.Photo != nil { } else if update.Message.Photo != nil {
if !albumAlreadyOpen() { if !albumAlreadyOpen() {
@ -182,6 +184,7 @@ func main() {
continue continue
} }
dispatchMessage(bot, update.Message) dispatchMessage(bot, update.Message)
replyWithMessage(bot, update.Message, viper.GetString("MsgThankYou"))
} else if update.Message.Video != nil { } else if update.Message.Video != nil {
if !albumAlreadyOpen() { if !albumAlreadyOpen() {
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgNoAlbum")) replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgNoAlbum"))
@ -195,6 +198,7 @@ func main() {
continue continue
} }
dispatchMessage(bot, update.Message) dispatchMessage(bot, update.Message)
replyWithMessage(bot, update.Message, viper.GetString("MsgThankYou"))
} }
} }
} }
@ -284,6 +288,8 @@ func handlePhoto(bot *tgbotapi.BotAPI, message *tgbotapi.Message) error {
"type": "photo", "type": "photo",
"date": t.Format("2006-01-02T15:04:05-0700"), "date": t.Format("2006-01-02T15:04:05-0700"),
"username": message.From.UserName, "username": message.From.UserName,
"firstname": message.From.FirstName,
"lastname": message.From.LastName,
"filename": photoFileName, "filename": photoFileName,
}} }}
@ -313,6 +319,8 @@ func handleVideo(bot *tgbotapi.BotAPI, message *tgbotapi.Message) error {
"type": "video", "type": "video",
"date": t.Format("2006-01-02T15:04:05-0700"), "date": t.Format("2006-01-02T15:04:05-0700"),
"username": message.From.UserName, "username": message.From.UserName,
"firstname": message.From.FirstName,
"lastname": message.From.LastName,
"filename": videoFileName, "filename": videoFileName,
"thumb_filename": thumbFileName, "thumb_filename": thumbFileName,
}} }}
@ -445,6 +453,8 @@ func addMessageToAlbum(message *tgbotapi.Message) error {
"type": "text", "type": "text",
"date": t.Format("2006-01-02T15:04:05-0700"), "date": t.Format("2006-01-02T15:04:05-0700"),
"username": message.From.UserName, "username": message.From.UserName,
"firstname": message.From.FirstName,
"lastname": message.From.LastName,
"message": message.Text, "message": message.Text,
}} }}

Loading…
Cancel
Save