up
This commit is contained in:
@@ -15,10 +15,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
version = "v1.0.0"
|
||||
version = "v1.0.1"
|
||||
)
|
||||
|
||||
|
||||
type Opts struct {
|
||||
Token string `short:"t" long:"token" description:"Telegram api token"`
|
||||
Name string `short:"n" long:"name" description:"Telegram bot name" default:"@body_weight_loss_bot"`
|
||||
@@ -81,8 +80,7 @@ func run() {
|
||||
|
||||
text := update.Message.Text
|
||||
chatID := update.Message.Chat.ID
|
||||
// username := update.Message.From.UserName
|
||||
|
||||
username := update.Message.From.UserName
|
||||
|
||||
userInfoDTO, err := db.GetUserInfo(chatID)
|
||||
if err != nil {
|
||||
@@ -92,15 +90,19 @@ func run() {
|
||||
if userInfoDTO.GetStatus() == db.UserStateGo {
|
||||
count, err := strconv.Atoi(text)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
if err := db.AddWorkoutInUser(chatID, db.NewWorkout("Отжимания", count)); err != nil {
|
||||
if err := db.AddWorkout(chatID, db.NewWorkout("Отжимания", count, username)); err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
msg := tgbot.NewMessage(chatID, fmt.Sprintf("Отлично, %s, записал.", text))
|
||||
msg.ReplyMarkup = tgbot.NewHideKeyboard(false)
|
||||
_, _ = bot.Send(msg)
|
||||
db.SetStatusInUser(chatID, db.UserStateNone)
|
||||
if err := db.SetStatusInUser(chatID, db.UserStateNone); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -108,8 +110,11 @@ func run() {
|
||||
switch command {
|
||||
case commands.Start:
|
||||
_, _ = bot.Send(tgbot.NewMessage(chatID, fmt.Sprintf("Здорова, я Валера (%s), твой тренер (%d).", version, chatID)))
|
||||
if err := db.SetStatusInUser(chatID, db.UserStateNone); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
case commands.Help:
|
||||
_, _ = bot.Send(tgbot.NewMessage(chatID, "Вот что я умею:\n\n1) Предлагать размяться"))
|
||||
_, _ = bot.Send(tgbot.NewMessage(chatID, "Вот что я умею:\n\n1) Предлагать размяться\n2) Показывать статистику"))
|
||||
case commands.Ping:
|
||||
_, _ = bot.Send(tgbot.NewMessage(chatID, "pong"))
|
||||
case commands.Go:
|
||||
@@ -119,11 +124,26 @@ func run() {
|
||||
tgbot.NewKeyboardButton("1"),
|
||||
tgbot.NewKeyboardButton("2"),
|
||||
tgbot.NewKeyboardButton("3"),
|
||||
tgbot.NewKeyboardButton("5"),
|
||||
tgbot.NewKeyboardButton("8"),
|
||||
),
|
||||
)
|
||||
if _, err = bot.Send(msg); err == nil {
|
||||
db.SetStatusInUser(chatID, db.UserStateGo)
|
||||
if err := db.SetStatusInUser(chatID, db.UserStateGo); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
case commands.Stat:
|
||||
stat, err := db.GetStat(chatID)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
msgText := "Результаты за сегодня:\n"
|
||||
for k, v := range stat {
|
||||
msgText += fmt.Sprintf("- %s: %d\n", k, v)
|
||||
}
|
||||
_, _ = bot.Send(tgbot.NewMessage(chatID, msgText))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user