fix(specialChar): Fix telegram special char
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
50786727bf
commit
452b7336c2
@ -33,7 +33,7 @@ func Init(alertChan chan api.Availability) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// define an interval and the ticker for this interval
|
// define an interval and the ticker for this interval
|
||||||
interval := time.Duration(2) * time.Second
|
interval := time.Duration(3) * time.Second
|
||||||
// create a new Ticker
|
// create a new Ticker
|
||||||
tk := time.NewTicker(interval)
|
tk := time.NewTicker(interval)
|
||||||
|
|
||||||
|
26
bot/bot.go
26
bot/bot.go
@ -70,8 +70,8 @@ func handleAlert(bot *tele.Bot, config *botConfig, alertChan chan api.Availabili
|
|||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"ALERT\\!\\! Found a %s%s in *%s* color is: *%d*€ [View](%s)",
|
"ALERT\\!\\! Found a %s%s in *%s* color is: *%d*€ [View](%s)",
|
||||||
demoStr,
|
demoStr,
|
||||||
availability.TrimName,
|
cleanString(availability.TrimName),
|
||||||
strings.Join(availability.Paint, " and "),
|
cleanString(strings.Join(availability.Paint, " and ")),
|
||||||
availability.Price,
|
availability.Price,
|
||||||
availability.GetOrderLink(),
|
availability.GetOrderLink(),
|
||||||
),
|
),
|
||||||
@ -180,8 +180,8 @@ func price(c tele.Context) error {
|
|||||||
msg = "There is no Tesla Propulsion available\n"
|
msg = "There is no Tesla Propulsion available\n"
|
||||||
} else {
|
} else {
|
||||||
msg = fmt.Sprintf("The lowest price currently found for a *%s* in *%s* color is: *%d*€ [View](%s)\n",
|
msg = fmt.Sprintf("The lowest price currently found for a *%s* in *%s* color is: *%d*€ [View](%s)\n",
|
||||||
propulsion.TrimName,
|
cleanString(propulsion.TrimName),
|
||||||
strings.Join(propulsion.Paint, " and "),
|
cleanString(strings.Join(propulsion.Paint, " and ")),
|
||||||
propulsion.Price,
|
propulsion.Price,
|
||||||
propulsion.GetOrderLink(),
|
propulsion.GetOrderLink(),
|
||||||
)
|
)
|
||||||
@ -192,8 +192,8 @@ func price(c tele.Context) error {
|
|||||||
} else {
|
} else {
|
||||||
msg = fmt.Sprintf("%sThe lowest price currently found for a *%s* in *%s* color is: *%d*€ [View](%s)\n",
|
msg = fmt.Sprintf("%sThe lowest price currently found for a *%s* in *%s* color is: *%d*€ [View](%s)\n",
|
||||||
msg,
|
msg,
|
||||||
longRange.TrimName,
|
cleanString(longRange.TrimName),
|
||||||
strings.Join(longRange.Paint, " and "),
|
cleanString(strings.Join(longRange.Paint, " and ")),
|
||||||
longRange.Price,
|
longRange.Price,
|
||||||
longRange.GetOrderLink(),
|
longRange.GetOrderLink(),
|
||||||
)
|
)
|
||||||
@ -226,9 +226,9 @@ func list(c tele.Context) error {
|
|||||||
"%s%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,
|
demoStr,
|
||||||
availability.TrimName,
|
cleanString(availability.TrimName),
|
||||||
strings.Join(availability.Paint, " and "),
|
cleanString(strings.Join(availability.Paint, " and ")),
|
||||||
strings.ReplaceAll(availability.City, "-", "\\-"),
|
cleanString(availability.City),
|
||||||
availability.Price,
|
availability.Price,
|
||||||
availability.GetOrderLink(),
|
availability.GetOrderLink(),
|
||||||
)
|
)
|
||||||
@ -236,3 +236,11 @@ func list(c tele.Context) error {
|
|||||||
|
|
||||||
return c.Reply(availabilitiesStr, &homeMenu)
|
return c.Reply(availabilitiesStr, &homeMenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cleanString(in string) string {
|
||||||
|
for _, str := range specialChars {
|
||||||
|
in = strings.ReplaceAll(in, str, fmt.Sprintf("\\%s", str))
|
||||||
|
}
|
||||||
|
|
||||||
|
return in
|
||||||
|
}
|
||||||
|
@ -9,6 +9,32 @@ import (
|
|||||||
"git.dev.m-and-m.ovh/mderasse/tesla/api"
|
"git.dev.m-and-m.ovh/mderasse/tesla/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var specialChars = []string{
|
||||||
|
"\\",
|
||||||
|
"_",
|
||||||
|
"*",
|
||||||
|
"[",
|
||||||
|
"]",
|
||||||
|
"(",
|
||||||
|
")",
|
||||||
|
"~",
|
||||||
|
"`",
|
||||||
|
">",
|
||||||
|
"<",
|
||||||
|
"&",
|
||||||
|
"#",
|
||||||
|
"+",
|
||||||
|
"-",
|
||||||
|
"=",
|
||||||
|
"|",
|
||||||
|
"{",
|
||||||
|
"}",
|
||||||
|
".",
|
||||||
|
"!",
|
||||||
|
"(",
|
||||||
|
")",
|
||||||
|
}
|
||||||
|
|
||||||
var carFilter api.AvailabilityQueryParams = api.AvailabilityQueryParams{
|
var carFilter api.AvailabilityQueryParams = api.AvailabilityQueryParams{
|
||||||
Model: "my",
|
Model: "my",
|
||||||
Condition: "new",
|
Condition: "new",
|
||||||
|
Loading…
Reference in New Issue
Block a user