add products
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
12ffc3461f
commit
c3d00b5dec
|
@ -19,7 +19,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version = "v1.7.0"
|
version = "v1.7.2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package calories
|
package eat_bot_state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -10,13 +10,15 @@ var (
|
||||||
caloriesIn100G int
|
caloriesIn100G int
|
||||||
awgWeightG int
|
awgWeightG int
|
||||||
}{
|
}{
|
||||||
"чай": {caloriesIn100G: 65, awgWeightG: 200},
|
"чай": {caloriesIn100G: 65, awgWeightG: 200},
|
||||||
"яблоко": {caloriesIn100G: 52, awgWeightG: 242},
|
"яблоко": {caloriesIn100G: 52, awgWeightG: 242},
|
||||||
"хлеб": {caloriesIn100G: 245, awgWeightG: 35},
|
"хлеб": {caloriesIn100G: 245, awgWeightG: 35},
|
||||||
|
"огурец": {caloriesIn100G: 15, awgWeightG: 20},
|
||||||
|
"помидор": {caloriesIn100G: 18, awgWeightG: 18},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func CalcCalories(text string) (int, error) {
|
func calcCalories(text string) (int, error) {
|
||||||
product, ok := productsMap[strings.ToLower(text)]
|
product, ok := productsMap[strings.ToLower(text)]
|
||||||
if ok {
|
if ok {
|
||||||
return product.caloriesIn100G * product.awgWeightG / 100, nil
|
return product.caloriesIn100G * product.awgWeightG / 100, nil
|
|
@ -1,4 +1,4 @@
|
||||||
package calories
|
package eat_bot_state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -49,7 +49,7 @@ func TestCalcCalories(t *testing.T) {
|
||||||
tt := tt
|
tt := tt
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
count, err := CalcCalories(tt.text)
|
count, err := calcCalories(tt.text)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("error calc calories: %v", err)
|
t.Errorf("error calc calories: %v", err)
|
||||||
return
|
return
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"valera/internal/calories"
|
|
||||||
"valera/internal/db"
|
"valera/internal/db"
|
||||||
"valera/internal/states"
|
"valera/internal/states"
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ func NewEatBotState(bot *tgbot.BotAPI, dataBase *db.DB) states.BotState {
|
||||||
|
|
||||||
func (s *eatBotState) Do(text string, chatInfo *db.ChatInfo, username string) error {
|
func (s *eatBotState) Do(text string, chatInfo *db.ChatInfo, username string) error {
|
||||||
if chatInfo.Status == string(db.UserStateEat) {
|
if chatInfo.Status == string(db.UserStateEat) {
|
||||||
count, err := calories.CalcCalories(text)
|
count, err := calcCalories(text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package pause
|
package pause_bot_state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -6,7 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetDuration(text string) (time.Duration, error) {
|
func getDuration(text string) (time.Duration, error) {
|
||||||
d := strings.TrimSuffix(text, "ч")
|
d := strings.TrimSuffix(text, "ч")
|
||||||
d = strings.TrimSuffix(d, "д")
|
d = strings.TrimSuffix(d, "д")
|
||||||
count, err := strconv.Atoi(d)
|
count, err := strconv.Atoi(d)
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"valera/internal/db"
|
"valera/internal/db"
|
||||||
"valera/internal/pause"
|
|
||||||
"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"
|
||||||
|
@ -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 {
|
func (s *pauseBotState) Do(text string, chatInfo *db.ChatInfo, username string) error {
|
||||||
if chatInfo.Status == string(db.UserStatePause) {
|
if chatInfo.Status == string(db.UserStatePause) {
|
||||||
duration, err := pause.GetDuration(text)
|
duration, err := getDuration(text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue