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

This commit is contained in:
2023-04-06 01:18:25 +07:00
parent 9e6681da30
commit b771745c47
5 changed files with 106 additions and 10 deletions
+48 -3
View File
@@ -12,6 +12,7 @@ import (
"valera/calories"
"valera/commands"
"valera/db"
"valera/pause"
tgbot "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/umputun/go-flags"
@@ -27,7 +28,7 @@ var (
)
const (
version = "v1.5.0"
version = "v1.6.0"
)
type Opts struct {
@@ -105,7 +106,7 @@ func run() {
}
go func() {
http.HandleFunc("/go", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/go", func(w http.ResponseWriter, _ *http.Request) {
chats, err := dataBase.GetAllChats()
if err != nil {
w.Header().Add("Content-Type", "application/json")
@@ -121,7 +122,7 @@ func run() {
_, _ = fmt.Fprintf(w, `{"result":"ok"}`)
})
http.HandleFunc("/stat", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/stat", func(w http.ResponseWriter, _ *http.Request) {
chats, err := dataBase.GetAllChats()
if err != nil {
fmt.Println(err)
@@ -161,6 +162,16 @@ func run() {
chatID := update.Message.Chat.ID
username := update.Message.From.UserName
if text == "/c" {
msg := tgbot.NewMessage(chatID, "Чистка")
msg.ReplyMarkup = tgbot.NewRemoveKeyboard(false)
_, _ = bot.Send(msg)
if err := dataBase.SetStatusToChat(chatID, db.UserStateNone); err != nil {
log.Println(err)
}
continue
}
userInfoDTO, err := dataBase.GetChatInfo(chatID)
if err != nil {
log.Println(err)
@@ -223,6 +234,22 @@ func run() {
log.Println(err)
}
continue
case db.UserStatePause:
duration, err := pause.GetDuration(text)
if err != nil {
log.Println(err)
continue
}
if err := dataBase.SetPause(chatID, duration); err != nil {
log.Println(err)
}
msg := tgbot.NewMessage(chatID, fmt.Sprintf("Поставил паузу %v, отдыхай", duration))
msg.ReplyMarkup = tgbot.NewRemoveKeyboard(false)
_, _ = bot.Send(msg)
if err := dataBase.SetStatusToChat(chatID, db.UserStateNone); err != nil {
log.Println(err)
}
continue
}
command := commands.Command(strings.Replace(text, opts.Name, "", 1))
@@ -249,6 +276,24 @@ func run() {
log.Println(err)
}
}
case commands.Pause:
msg := tgbot.NewMessage(chatID, "Хочешь отдохнуть? Сколько времени тебе нужно?")
msg.ReplyMarkup = tgbot.NewReplyKeyboard([][]tgbot.KeyboardButton{
tgbot.NewKeyboardButtonRow(
tgbot.NewKeyboardButton("1ч"),
tgbot.NewKeyboardButton("4ч"),
),
tgbot.NewKeyboardButtonRow(
tgbot.NewKeyboardButton("1д"),
tgbot.NewKeyboardButton("2д"),
tgbot.NewKeyboardButton("7д"),
),
}...)
if _, err := bot.Send(msg); err == nil {
if err := dataBase.SetStatusToChat(chatID, db.UserStatePause); err != nil {
log.Println(err)
}
}
}
}
}