Standardize handleError() command to repeat timeouts or have better messages
This commit is contained in:
113
commands.go
113
commands.go
@ -14,16 +14,12 @@ import (
|
|||||||
func reset(m chat1.MsgSummary) {
|
func reset(m chat1.MsgSummary) {
|
||||||
_, err := k.KVDelete(&m.Channel.Name, "teslabot", "authtok")
|
_, err := k.KVDelete(&m.Channel.Name, "teslabot", "authtok")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err,m,"There was an error resetting your authentication. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error resetting your authentication. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = k.KVDelete(&m.Channel.Name, "teslabot", "startPass")
|
_, err = k.KVDelete(&m.Channel.Name, "teslabot", "startPass")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err,m,"There was an error resetting your authentication. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error resetting your authentication. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,17 +42,13 @@ func authenticate(m chat1.MsgSummary) {
|
|||||||
password := parts[2]
|
password := parts[2]
|
||||||
t, err := login(context.Background(), username, password)
|
t, err := login(context.Background(), username, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err,m,"There was an error logging in. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error logging in. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.LogDebug("Token created for %+v", m.Sender.Username)
|
log.LogDebug("Token created for %+v", m.Sender.Username)
|
||||||
_, err = k.KVPut(&m.Channel.Name, "teslabot", "authtok", t)
|
_, err = k.KVPut(&m.Channel.Name, "teslabot", "authtok", t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err,m,"There was an error storing your auth token. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error storing your auth token. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
k.ReactByConvID(m.ConvID, m.Id, ":car:")
|
k.ReactByConvID(m.ConvID, m.Id, ":car:")
|
||||||
@ -71,9 +63,7 @@ func listVehicles(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
v, err := c.Vehicles()
|
v, err := c.Vehicles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err,m,"There was an error listing vehicles. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error listing vehicles. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ret := "Detected vehicles for account: ```"
|
ret := "Detected vehicles for account: ```"
|
||||||
@ -93,9 +83,7 @@ func deferTime(m chat1.MsgSummary) {
|
|||||||
m.Content.Text.Body = fmt.Sprintf("!%+v", command)
|
m.Content.Text.Body = fmt.Sprintf("!%+v", command)
|
||||||
timer, err := time.ParseDuration(t)
|
timer, err := time.ParseDuration(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err,m,"There was an error parsing your time input. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error parsing your time input. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
k.SendMessageByConvID(m.ConvID, fmt.Sprintf("I will run `%+v` at %+v", command, time.Now().Add(timer).Format("Jan _2 15:04:05")))
|
k.SendMessageByConvID(m.ConvID, fmt.Sprintf("I will run `%+v` at %+v", command, time.Now().Add(timer).Format("Jan _2 15:04:05")))
|
||||||
@ -111,9 +99,7 @@ func honk(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
err := v.HonkHorn()
|
err := v.HonkHorn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m,"There was an error honking your horn. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error honking your horn. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
k.SendMessageByConvID(m.ConvID, "I've honked your horn!")
|
k.SendMessageByConvID(m.ConvID, "I've honked your horn!")
|
||||||
@ -126,9 +112,7 @@ func chargeStatus(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
state, err := v.ChargeState()
|
state, err := v.ChargeState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err,m,"There was an error getting charge state. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error getting charge state. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ret := fmt.Sprintf("Status for %+v: ```", v.DisplayName)
|
ret := fmt.Sprintf("Status for %+v: ```", v.DisplayName)
|
||||||
@ -160,9 +144,7 @@ func flashLights(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
err := v.FlashLights()
|
err := v.FlashLights()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err,m,"There was an error flashing your lights. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error flashing your lights. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,16 +158,12 @@ func currentTemp(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
guiSettings, err := v.GuiSettings()
|
guiSettings, err := v.GuiSettings()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err,m,"There was an error getting your preferences. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error getting your preferences. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
climateState, err := v.ClimateState()
|
climateState, err := v.ClimateState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error getting your Climate State. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error getting your Climate State. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tempSetting := climateState.DriverTempSetting
|
tempSetting := climateState.DriverTempSetting
|
||||||
@ -210,9 +188,7 @@ func setClimate(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
guiSettings, err := v.GuiSettings()
|
guiSettings, err := v.GuiSettings()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error getting your preferences. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error getting your preferences. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
parts := strings.Split(m.Content.Text.Body, " ")
|
parts := strings.Split(m.Content.Text.Body, " ")
|
||||||
@ -220,18 +196,14 @@ func setClimate(m chat1.MsgSummary) {
|
|||||||
if val == "on" {
|
if val == "on" {
|
||||||
err := v.StartAirConditioning()
|
err := v.StartAirConditioning()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error starting your Climate. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error starting your Climate. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if val == "off" {
|
if val == "off" {
|
||||||
err := v.StopAirConditioning()
|
err := v.StopAirConditioning()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error turning off your Climate. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error turning off your Climate. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,25 +213,19 @@ func setClimate(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
err = v.SetTemperature(float64(temp), float64(temp))
|
err = v.SetTemperature(float64(temp), float64(temp))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error setting your Climate. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error setting your Climate. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = v.StartAirConditioning()
|
err = v.StartAirConditioning()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error starting your Climate. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error starting your Climate. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
climateState, err := v.ClimateState()
|
climateState, err := v.ClimateState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error getting your Climate State. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error getting your Climate State. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tempSetting := climateState.DriverTempSetting
|
tempSetting := climateState.DriverTempSetting
|
||||||
@ -283,9 +249,7 @@ func lockVehicle(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
err := v.LockDoors()
|
err := v.LockDoors()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error locking your doors. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error locking your doors. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -297,9 +261,7 @@ func unlockVehicle(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
err := v.UnlockDoors()
|
err := v.UnlockDoors()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error unlocking your doors. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error unlocking your doors. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -311,17 +273,13 @@ func startCharge(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
state, err := v.ChargeState()
|
state, err := v.ChargeState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error getting charge state. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error getting charge state. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if state.ChargingState != "Disconnected" && state.FastChargerBrand != "Tesla" {
|
if state.ChargingState != "Disconnected" && state.FastChargerBrand != "Tesla" {
|
||||||
err := v.StartCharging()
|
err := v.StartCharging()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error starting your charge. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error starting your charge. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -337,17 +295,13 @@ func stopCharge(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
state, err := v.ChargeState()
|
state, err := v.ChargeState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error getting charge state. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error getting charge state. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if state.ChargingState != "Disconnected" && state.FastChargerBrand != "Tesla" {
|
if state.ChargingState != "Disconnected" && state.FastChargerBrand != "Tesla" {
|
||||||
err := v.StopCharging()
|
err := v.StopCharging()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error stopping your charge. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error stopping your charge. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -367,9 +321,7 @@ func enableStart(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
_, err := k.KVPut(&m.Channel.Name, "teslabot", "startPass", parts[2])
|
_, err := k.KVPut(&m.Channel.Name, "teslabot", "startPass", parts[2])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error storing your password. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error storing your password. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,9 +330,7 @@ func enableStart(m chat1.MsgSummary) {
|
|||||||
func disableStart(m chat1.MsgSummary) {
|
func disableStart(m chat1.MsgSummary) {
|
||||||
_, err := k.KVDelete(&m.Channel.Name, "teslabot", "startPass")
|
_, err := k.KVDelete(&m.Channel.Name, "teslabot", "startPass")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error deleting your password. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error deleting your password. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -397,9 +347,7 @@ func startVehicle(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
err := v.Start(test.EntryValue)
|
err := v.Start(test.EntryValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error starting your vehicle. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error starting your vehicle. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
k.SendMessageByConvID(m.ConvID, "Your vehicle has been started!")
|
k.SendMessageByConvID(m.ConvID, "Your vehicle has been started!")
|
||||||
@ -423,9 +371,7 @@ func openTrunk(m chat1.MsgSummary) {
|
|||||||
case "front":
|
case "front":
|
||||||
err := v.OpenTrunk(strings.ToLower(trunk))
|
err := v.OpenTrunk(strings.ToLower(trunk))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tracker := uuid.NewString()
|
handleError(err, m, "There was an error opening your trunk. Contact @rudi9719 for more information with code %+v")
|
||||||
k.SendMessageByConvID(m.ConvID, "There was an error opening your trunk. Contact @rudi9719 for more information with code %+v", tracker)
|
|
||||||
log.LogError("%+v: %+v", tracker, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -434,3 +380,8 @@ func openTrunk(m chat1.MsgSummary) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
func handleError(err error, m chat1.MsgSummary, msg string) {
|
||||||
|
tracker := uuid.NewString()
|
||||||
|
k.SendMessageByConvID(m.ConvID, msg, tracker)
|
||||||
|
log.LogError("%+v: %+v", tracker, err)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user