@@ -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
|
||||
|
||||
Reference in New Issue
Block a user