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 (
|
||||
version = "v1.7.0"
|
||||
version = "v1.7.2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package calories
|
||||
package eat_bot_state
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
@ -13,10 +13,12 @@ var (
|
|||
"чай": {caloriesIn100G: 65, awgWeightG: 200},
|
||||
"яблоко": {caloriesIn100G: 52, awgWeightG: 242},
|
||||
"хлеб": {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)]
|
||||
if ok {
|
||||
return product.caloriesIn100G * product.awgWeightG / 100, nil
|
|
@ -1,4 +1,4 @@
|
|||
package calories
|
||||
package eat_bot_state
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -49,7 +49,7 @@ func TestCalcCalories(t *testing.T) {
|
|||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
count, err := CalcCalories(tt.text)
|
||||
count, err := calcCalories(tt.text)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("error calc calories: %v", err)
|
||||
return
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"valera/internal/calories"
|
||||
"valera/internal/db"
|
||||
"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 {
|
||||
if chatInfo.Status == string(db.UserStateEat) {
|
||||
count, err := calories.CalcCalories(text)
|
||||
count, err := calcCalories(text)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package pause
|
||||
package pause_bot_state
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
@ -6,7 +6,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func GetDuration(text string) (time.Duration, error) {
|
||||
func getDuration(text string) (time.Duration, error) {
|
||||
d := strings.TrimSuffix(text, "ч")
|
||||
d = strings.TrimSuffix(d, "д")
|
||||
count, err := strconv.Atoi(d)
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue