update stat
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
01e132628c
commit
87157b2081
11
db/db.go
11
db/db.go
|
@ -2,6 +2,7 @@ package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
|
@ -132,7 +133,7 @@ func (db *DB) SetStatusToChat(chatID int64, status UserState) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) GetStat(chatID int64) (map[string]int, error) {
|
func (db *DB) GetStat(chatID int64, cron bool) (map[string]int, error) {
|
||||||
if err := db.AddChat(chatID); err != nil {
|
if err := db.AddChat(chatID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -145,7 +146,13 @@ func (db *DB) GetStat(chatID int64) (map[string]int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
loc, _ := time.LoadLocation("Asia/Novosibirsk")
|
loc, _ := time.LoadLocation("Asia/Novosibirsk")
|
||||||
t := time.Now().In(loc).Add(-24 * time.Hour)
|
t := time.Now().In(loc)
|
||||||
|
if cron {
|
||||||
|
t = t.Add(-24 * time.Hour)
|
||||||
|
}
|
||||||
|
if !cron {
|
||||||
|
t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, loc)
|
||||||
|
}
|
||||||
|
|
||||||
res := map[string]int{}
|
res := map[string]int{}
|
||||||
|
|
||||||
|
|
8
main.go
8
main.go
|
@ -128,7 +128,7 @@ func run() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, chatID := range chats {
|
for _, chatID := range chats {
|
||||||
if err := sendStatToChat(bot, dataBase, chatID, "Напоминаю:\n- Cегодня больше не жрем!\n\n"); err != nil {
|
if err := sendStatToChat(bot, dataBase, chatID, "Напоминаю:\n- Cегодня больше не жрем!\n\n", true); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
@ -236,7 +236,7 @@ func run() {
|
||||||
case commands.Go:
|
case commands.Go:
|
||||||
sendGoToChat(bot, dataBase, chatID)
|
sendGoToChat(bot, dataBase, chatID)
|
||||||
case commands.Stat:
|
case commands.Stat:
|
||||||
if err := sendStatToChat(bot, dataBase, chatID, ""); err != nil {
|
if err := sendStatToChat(bot, dataBase, chatID, "", false); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -288,8 +288,8 @@ func sendGoToChat(bot *tgbot.BotAPI, dataBase *db.DB, chatID int64) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendStatToChat(bot *tgbot.BotAPI, dataBase *db.DB, chatID int64, prefix string) error {
|
func sendStatToChat(bot *tgbot.BotAPI, dataBase *db.DB, chatID int64, prefix string, cron bool) error {
|
||||||
stat, err := dataBase.GetStat(chatID)
|
stat, err := dataBase.GetStat(chatID, cron)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue