update calories message
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
a35a5c8efc
commit
3f9447f0b8
|
@ -0,0 +1,16 @@
|
||||||
|
package times
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
func GetStartDay() time.Time {
|
||||||
|
loc, _ := time.LoadLocation("Asia/Novosibirsk")
|
||||||
|
t := time.Now().In(loc)
|
||||||
|
t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, loc)
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetStartWeek() time.Time {
|
||||||
|
t := GetStartDay()
|
||||||
|
t = t.Add(-6 * 24 * time.Hour)
|
||||||
|
return t
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"valera/internal/db"
|
"valera/internal/db"
|
||||||
|
"valera/internal/modules/times"
|
||||||
"valera/internal/states"
|
"valera/internal/states"
|
||||||
|
|
||||||
tgbot "github.com/go-telegram-bot-api/telegram-bot-api"
|
tgbot "github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
|
@ -38,7 +39,12 @@ func (s *eatBotState) Do(text string, chatInfo *db.ChatInfo) error {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
_, _ = s.bot.Send(tgbot.NewMessage(chatInfo.ChatID, fmt.Sprintf("Калории, фу, %d, записал.", count)))
|
stat, err := s.dataBase.GetStatAfter(chatInfo.ChatID, times.GetStartDay())
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
_, _ = s.bot.Send(tgbot.NewMessage(chatInfo.ChatID, fmt.Sprintf("Калории, фу, %d, записал.\nКалорий сегодня: %v", count, stat["Калории"])))
|
||||||
return s.dataBase.SetStatusToChat(chatInfo.ChatID, db.UserStateNone)
|
return s.dataBase.SetStatusToChat(chatInfo.ChatID, db.UserStateNone)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ import (
|
||||||
"valera/internal/db"
|
"valera/internal/db"
|
||||||
"valera/internal/states"
|
"valera/internal/states"
|
||||||
|
|
||||||
|
"valera/internal/modules/times"
|
||||||
|
|
||||||
tgbot "github.com/go-telegram-bot-api/telegram-bot-api"
|
tgbot "github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
@ -34,11 +36,11 @@ func (s *statBotState) Do(text string, chatInfo *db.ChatInfo) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if text == "/stat" {
|
if text == "/stat" {
|
||||||
s.sendStatToChatAfter(chatInfo.ChatID, "Результаты за сегодня:\n", s.getStartDay())
|
s.sendStatToChatAfter(chatInfo.ChatID, "Результаты за сегодня:\n", times.GetStartDay())
|
||||||
}
|
}
|
||||||
|
|
||||||
if text == "/stat_week" {
|
if text == "/stat_week" {
|
||||||
s.sendStatToChatAfter(chatInfo.ChatID, "Результаты за неделю:\n", s.getStartWeek())
|
s.sendStatToChatAfter(chatInfo.ChatID, "Результаты за неделю:\n", times.GetStartWeek())
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -55,15 +57,15 @@ func (s *statBotState) GetHandler() (string, func(http.ResponseWriter, *http.Req
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, chatID := range chats {
|
for _, chatID := range chats {
|
||||||
t := s.getStartDay()
|
t := times.GetStartDay()
|
||||||
if err := s.sendStatToChatAfter(chatID, "Напоминаю:\n- Cегодня больше не жрем!\n\nРезультаты за сегодня:\n", s.getStartDay()); err != nil {
|
if err := s.sendStatToChatAfter(chatID, "Напоминаю:\n- Cегодня больше не жрем!\n\nРезультаты за сегодня:\n", times.GetStartDay()); err != nil {
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
_, _ = fmt.Fprintf(w, `{"result":"error"}`)
|
_, _ = fmt.Fprintf(w, `{"result":"error"}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if t.Weekday() == time.Sunday {
|
if t.Weekday() == time.Sunday {
|
||||||
if err := s.sendStatToChatAfter(chatID, "Результаты за неделю:\n", s.getStartWeek()); err != nil {
|
if err := s.sendStatToChatAfter(chatID, "Результаты за неделю:\n", times.GetStartWeek()); err != nil {
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
_, _ = fmt.Fprintf(w, `{"result":"error"}`)
|
_, _ = fmt.Fprintf(w, `{"result":"error"}`)
|
||||||
|
@ -89,16 +91,3 @@ func (s *statBotState) sendStatToChatAfter(chatID int64, prefix string, t time.T
|
||||||
_, _ = s.bot.Send(tgbot.NewMessage(chatID, msgText))
|
_, _ = s.bot.Send(tgbot.NewMessage(chatID, msgText))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *statBotState) getStartDay() time.Time {
|
|
||||||
loc, _ := time.LoadLocation("Asia/Novosibirsk")
|
|
||||||
t := time.Now().In(loc)
|
|
||||||
t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, loc)
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *statBotState) getStartWeek() time.Time {
|
|
||||||
t := s.getStartDay()
|
|
||||||
t = t.Add(-6 * 24 * time.Hour)
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue