add calories
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-03-12 13:53:50 +07:00
parent daa52ecbde
commit f1f3fb5db4
4 changed files with 107 additions and 9 deletions
+28 -2
View File
@@ -133,7 +133,8 @@ func run() {
log.Println(err)
continue
}
if userInfoDTO.GetStatus() == db.UserStateGo {
switch userInfoDTO.GetStatus() {
case db.UserStateGo:
count, err := strconv.Atoi(text)
if err != nil {
log.Println(err)
@@ -154,6 +155,25 @@ func run() {
log.Println(err)
}
continue
case db.UserStateEat:
count, err := strconv.Atoi(text)
if err != nil {
log.Println(err)
continue
}
if err := db.AddCalories(chatID, db.NewCalories(count, username)); err != nil {
log.Println(err)
continue
}
if count <= 0 {
_, _ = bot.Send(tgbot.NewMessage(chatID, "Все фигня, давай по новой"))
continue
}
_, _ = bot.Send(tgbot.NewMessage(chatID, fmt.Sprintf("Калории, фу, %s, записал.", text)))
if err := db.SetStatusToChat(chatID, db.UserStateNone); err != nil {
log.Println(err)
}
continue
}
command := commands.Command(strings.Replace(text, opts.Name, "", 1))
@@ -164,7 +184,7 @@ func run() {
log.Println(err)
}
case commands.Help:
_, _ = bot.Send(tgbot.NewMessage(chatID, "Вот что я умею:\n\n1) Предлагать размяться\n2) Показывать статистику"))
_, _ = bot.Send(tgbot.NewMessage(chatID, "Вот что я умею:\n\n1) Предлагать размяться\n2) Показывать статистику\n3) Считать калории"))
case commands.Ping:
_, _ = bot.Send(tgbot.NewMessage(chatID, "pong"))
case commands.Go:
@@ -174,6 +194,12 @@ func run() {
fmt.Println(err)
continue
}
case commands.Eat:
if _, err := bot.Send(tgbot.NewMessage(chatID, "Вижу ты поел, отпишись сколько калорий было")); err == nil {
if err := db.SetStatusToChat(chatID, db.UserStateEat); err != nil {
log.Println(err)
}
}
}
}
}