Add locate vehicle command

This commit is contained in:
2021-07-14 12:53:22 -04:00
parent d9eccb37b6
commit 4dda5eef19
2 changed files with 42 additions and 14 deletions

View File

@ -227,7 +227,7 @@ func setupCommands() {
} }
commands = append(commands, trunk) commands = append(commands, trunk)
startCharging := BotCommand { startCharging := BotCommand{
Advert: chat1.AdvertiseCommandAPIParam{ Advert: chat1.AdvertiseCommandAPIParam{
Typ: "public", Typ: "public",
Commands: []chat1.UserBotCommandInput{ Commands: []chat1.UserBotCommandInput{
@ -240,11 +240,10 @@ func setupCommands() {
}, },
Triggers: []string{"startcharge", "startc"}, Triggers: []string{"startcharge", "startc"},
Exec: startCharge, Exec: startCharge,
} }
commands = append(commands, startCharging) commands = append(commands, startCharging)
stopCharging := BotCommand { stopCharging := BotCommand{
Advert: chat1.AdvertiseCommandAPIParam{ Advert: chat1.AdvertiseCommandAPIParam{
Typ: "public", Typ: "public",
Commands: []chat1.UserBotCommandInput{ Commands: []chat1.UserBotCommandInput{
@ -257,11 +256,10 @@ func setupCommands() {
}, },
Triggers: []string{"stopcharge", "stopc"}, Triggers: []string{"stopcharge", "stopc"},
Exec: stopCharge, Exec: stopCharge,
} }
commands = append(commands, stopCharging) commands = append(commands, stopCharging)
delayCommand := BotCommand { delayCommand := BotCommand{
Advert: chat1.AdvertiseCommandAPIParam{ Advert: chat1.AdvertiseCommandAPIParam{
Typ: "public", Typ: "public",
Commands: []chat1.UserBotCommandInput{ Commands: []chat1.UserBotCommandInput{
@ -277,4 +275,20 @@ func setupCommands() {
} }
commands = append(commands, delayCommand) commands = append(commands, delayCommand)
locateCommand := BotCommand{
Advert: chat1.AdvertiseCommandAPIParam{
Typ: "public",
Commands: []chat1.UserBotCommandInput{
{
Name: "locate",
Description: "Locate your Tesla.",
Usage: "",
},
},
},
Triggers: []string{"locate", "map", "where","find"},
Exec: locateVehicle,
}
commands = append(commands, locateCommand)
} }

View File

@ -151,6 +151,20 @@ func formatDuration(d time.Duration) string {
m := d / time.Minute m := d / time.Minute
return fmt.Sprintf("%02dh%02dm", h, m) return fmt.Sprintf("%02dh%02dm", h, m)
} }
func locateVehicle(m chat1.MsgSummary) {
v := getVehicle(m)
if v == nil {
return
}
ds, err := v.DriveState()
if err != nil {
handleError(err, m, "There was an error getting drive state. Contact @rudi9719 for more information with code %+v")
return
}
k.SendMessageByConvID(m.ConvID, fmt.Sprintf("https://www.google.com/maps/search/?api=1&query=%+v,%+v", ds.Latitude, ds.Longitude))
}
func flashLights(m chat1.MsgSummary) { func flashLights(m chat1.MsgSummary) {
v := getVehicle(m) v := getVehicle(m)
if v == nil { if v == nil {