Compare commits

..

No commits in common. "922e770405d2cdd4d7410d37788e2132a41d3448" and "f066e01d21faa908ada387541f7b68c7896bcbb6" have entirely different histories.

1 changed files with 26 additions and 45 deletions

53
main.go
View File

@ -15,15 +15,8 @@ import (
"valera/db" "valera/db"
) )
var (
workoutTypes = []string{
"Отжимания",
"Пресс",
}
)
const ( const (
version = "v1.4.0" version = "v1.3.0"
) )
type Opts struct { type Opts struct {
@ -159,16 +152,14 @@ func run() {
log.Println(err) log.Println(err)
continue continue
} }
switch userInfoDTO.GetStatus() {
isWorkout := false case db.UserStateGo:
for _, workoutType := range workoutTypes {
if userInfoDTO.GetStatus() == db.UserState(workoutType) {
count, err := strconv.Atoi(text) count, err := strconv.Atoi(text)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
continue continue
} }
if err := dataBase.AddWorkout(chatID, db.NewWorkout(workoutType, count, username)); err != nil { if err := dataBase.AddWorkout(chatID, db.NewWorkout("Отжимания", count, username)); err != nil {
log.Println(err) log.Println(err)
continue continue
} }
@ -176,26 +167,12 @@ func run() {
if count <= 0 { if count <= 0 {
msgText = "Плохо, хочешь быть толстым и не красивым?" msgText = "Плохо, хочешь быть толстым и не красивым?"
} }
_, _ = bot.Send(tgbot.NewMessage(chatID, msgText)) msg := tgbot.NewMessage(chatID, msgText)
msg.ReplyMarkup = tgbot.NewRemoveKeyboard(false)
_, _ = bot.Send(msg)
if err := dataBase.SetStatusToChat(chatID, db.UserStateNone); err != nil { if err := dataBase.SetStatusToChat(chatID, db.UserStateNone); err != nil {
log.Println(err) log.Println(err)
} }
isWorkout = true
break
}
}
if isWorkout {
continue
}
switch userInfoDTO.GetStatus() {
case db.UserStateGo:
if err := dataBase.SetStatusToChat(chatID, db.UserState(text)); err != nil {
log.Println(err)
}
msg := tgbot.NewMessage(chatID, fmt.Sprintf("%s, отпишись сколько раз ты выполнил упражнение", text))
msg.ReplyMarkup = tgbot.NewRemoveKeyboard(false)
_, _ = bot.Send(msg)
continue continue
case db.UserStateEat: case db.UserStateEat:
count, err := strconv.Atoi(text) count, err := strconv.Atoi(text)
@ -247,12 +224,16 @@ func run() {
} }
func sendGoToChat(bot *tgbot.BotAPI, dataBase *db.DB, chatID int64) { func sendGoToChat(bot *tgbot.BotAPI, dataBase *db.DB, chatID int64) {
msg := tgbot.NewMessage(chatID, "Давай немного разомнемся, выбирай:") msg := tgbot.NewMessage(chatID, "Давай немного разомнемся, отжимания, отпишись сколько раз ты выполнил упражнение")
row := tgbot.NewKeyboardButtonRow() msg.ReplyMarkup = tgbot.NewReplyKeyboard(
for _, workoutType := range workoutTypes { tgbot.NewKeyboardButtonRow(
row = append(row, tgbot.NewKeyboardButton(workoutType)) tgbot.NewKeyboardButton("1"),
} tgbot.NewKeyboardButton("2"),
msg.ReplyMarkup = tgbot.NewReplyKeyboard(row) tgbot.NewKeyboardButton("3"),
tgbot.NewKeyboardButton("5"),
tgbot.NewKeyboardButton("8"),
),
)
if _, err := bot.Send(msg); err == nil { if _, err := bot.Send(msg); err == nil {
if err := dataBase.SetStatusToChat(chatID, db.UserStateGo); err != nil { if err := dataBase.SetStatusToChat(chatID, db.UserStateGo); err != nil {
log.Println(err) log.Println(err)