Browse Source

Add locate vehicle command

master
Gregory Rudolph 4 years ago
parent
commit
4dda5eef19
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 42
      botCommands.go
  2. 14
      commands.go

42
botCommands.go

@ -227,54 +227,68 @@ 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{
{ {
Name: "startcharge", Name: "startcharge",
Description: "Start charging (if plugged in)", Description: "Start charging (if plugged in)",
Usage: "", Usage: "",
}, },
}, },
}, },
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{
{ {
Name: "stopcharge", Name: "stopcharge",
Description: "Stop charging (if plugged in)", Description: "Stop charging (if plugged in)",
Usage: "", Usage: "",
}, },
}, },
}, },
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{
{ {
Name: "in", Name: "in",
Description: "Delay a command to run at another time.", Description: "Delay a command to run at another time.",
Usage: "2h3m startcharge", Usage: "2h3m startcharge",
}, },
}, },
}, },
Triggers: []string{"in", "delay", "wait"}, Triggers: []string{"in", "delay", "wait"},
Exec: deferTime, Exec: deferTime,
} }
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)
} }

14
commands.go

@ -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 {

Loading…
Cancel
Save