fix(Alert): Alert on demo
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Matthieu 'JP' DERASSE 2023-06-26 07:59:36 +00:00
parent 01f047037a
commit 4a62daed22
Signed by: mderasse
GPG Key ID: 55141C777B16A705
2 changed files with 16 additions and 3 deletions

View File

@ -70,7 +70,7 @@ func checkPrice(alertChan chan api.Availability) {
LrAlert := false LrAlert := false
for _, availability := range availabilities.Results { for _, availability := range availabilities.Results {
if availability.IsDemo { if availability.IsDemo && availability.Odometer > 100 {
continue continue
} }

View File

@ -60,10 +60,16 @@ func handleAlert(bot *tele.Bot, config *botConfig, alertChan chan api.Availabili
for _, chatId := range config.AlertChatIds { for _, chatId := range config.AlertChatIds {
log.Infof("Sending alert to chat %d", chatId) log.Infof("Sending alert to chat %d", chatId)
demoStr := ""
if availability.IsDemo {
demoStr = fmt.Sprintf("Demo \\(%d %s\\) ", availability.Odometer, availability.OdometerTypeShort)
}
_, err := bot.Send( _, err := bot.Send(
tele.ChatID(chatId), tele.ChatID(chatId),
fmt.Sprintf( fmt.Sprintf(
"ALERT\\!\\! Found a %s in *%s* color is: *%d*€ [View](%s)", "ALERT\\!\\! Found a %s%s in *%s* color is: *%d*€ [View](%s)",
demoStr,
availability.TrimName, availability.TrimName,
strings.Join(availability.Paint, " and "), strings.Join(availability.Paint, " and "),
availability.Price, availability.Price,
@ -210,9 +216,16 @@ func list(c tele.Context) error {
availabilitiesStr := fmt.Sprintf("Found *%s* cars\n", availabilities.TotalMatchesFound) availabilitiesStr := fmt.Sprintf("Found *%s* cars\n", availabilities.TotalMatchesFound)
for _, availability := range availabilities.Results { for _, availability := range availabilities.Results {
demoStr := ""
if availability.IsDemo {
demoStr = fmt.Sprintf("Demo \\(%d %s\\) ", availability.Odometer, availability.OdometerTypeShort)
}
availabilitiesStr = fmt.Sprintf( availabilitiesStr = fmt.Sprintf(
"%s%s, color *%s* available in *%s* for *%d*€ [View](%s)\n", "%s%s%s, color *%s* available in *%s* for *%d*€ [View](%s)\n",
availabilitiesStr, availabilitiesStr,
demoStr,
availability.TrimName, availability.TrimName,
strings.Join(availability.Paint, " and "), strings.Join(availability.Paint, " and "),
strings.ReplaceAll(availability.City, "-", "\\-"), strings.ReplaceAll(availability.City, "-", "\\-"),