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

This commit is contained in:
2023-04-09 13:31:01 +07:00
parent 12ffc3461f
commit c3d00b5dec
6 changed files with 14 additions and 14 deletions
+21
View File
@@ -0,0 +1,21 @@
package pause_bot_state
import (
"strconv"
"strings"
"time"
)
func getDuration(text string) (time.Duration, error) {
d := strings.TrimSuffix(text, "ч")
d = strings.TrimSuffix(d, "д")
count, err := strconv.Atoi(d)
if err != nil {
return 0, err
}
res := time.Duration(count) * time.Hour
if strings.HasSuffix(text, "д") {
res *= 24
}
return res, nil
}
@@ -5,7 +5,6 @@ import (
"log"
"net/http"
"valera/internal/db"
"valera/internal/pause"
"valera/internal/states"
tgbot "github.com/go-telegram-bot-api/telegram-bot-api"
@@ -30,7 +29,7 @@ func NewPauseBotState(bot *tgbot.BotAPI, dataBase *db.DB) states.BotState {
func (s *pauseBotState) Do(text string, chatInfo *db.ChatInfo, username string) error {
if chatInfo.Status == string(db.UserStatePause) {
duration, err := pause.GetDuration(text)
duration, err := getDuration(text)
if err != nil {
log.Println(err)
return nil