@ -14,12 +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 {
handleError ( err , m , "There was an error resetting your authentication. Contact @rudi9719 for more information with code %+v" )
handleError ( err , m , "There was an error resetting your authentication. Contact @rudi9719 for more information with code %+v" )
return
return
}
}
_ , err = k . KVDelete ( & m . Channel . Name , "teslabot" , "startPass" )
_ , err = k . KVDelete ( & m . Channel . Name , "teslabot" , "startPass" )
if err != nil {
if err != nil {
handleError ( err , m , "There was an error resetting your authentication. Contact @rudi9719 for more information with code %+v" )
handleError ( err , m , "There was an error resetting your authentication. Contact @rudi9719 for more information with code %+v" )
return
return
}
}
}
}
@ -42,13 +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 {
handleError ( err , m , "There was an error logging in. Contact @rudi9719 for more information with code %+v" )
handleError ( err , m , "There was an error logging in. Contact @rudi9719 for more information with code %+v" )
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 {
handleError ( err , m , "There was an error storing your auth token. Contact @rudi9719 for more information with code %+v" )
handleError ( err , m , "There was an error storing your auth token. Contact @rudi9719 for more information with code %+v" )
return
return
}
}
k . ReactByConvID ( m . ConvID , m . Id , ":car:" )
k . ReactByConvID ( m . ConvID , m . Id , ":car:" )
@ -63,7 +63,7 @@ func listVehicles(m chat1.MsgSummary) {
}
}
v , err := c . Vehicles ( )
v , err := c . Vehicles ( )
if err != nil {
if err != nil {
handleError ( err , m , "There was an error listing vehicles. Contact @rudi9719 for more information with code %+v" )
handleError ( err , m , "There was an error listing vehicles. Contact @rudi9719 for more information with code %+v" )
return
return
}
}
ret := "Detected vehicles for account: ```"
ret := "Detected vehicles for account: ```"
@ -83,7 +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 {
handleError ( err , m , "There was an error parsing your time input. Contact @rudi9719 for more information with code %+v" )
handleError ( err , m , "There was an error parsing your time input. Contact @rudi9719 for more information with code %+v" )
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" ) ) )
@ -99,7 +99,7 @@ func honk(m chat1.MsgSummary) {
}
}
err := v . HonkHorn ( )
err := v . HonkHorn ( )
if err != nil {
if err != nil {
handleError ( err , m , "There was an error honking your horn. Contact @rudi9719 for more information with code %+v" )
handleError ( err , m , "There was an error honking your horn. Contact @rudi9719 for more information with code %+v" )
return
return
}
}
k . SendMessageByConvID ( m . ConvID , "I've honked your horn!" )
k . SendMessageByConvID ( m . ConvID , "I've honked your horn!" )
@ -112,7 +112,7 @@ func chargeStatus(m chat1.MsgSummary) {
}
}
state , err := v . ChargeState ( )
state , err := v . ChargeState ( )
if err != nil {
if err != nil {
handleError ( err , m , "There was an error getting charge state. Contact @rudi9719 for more information with code %+v" )
handleError ( err , m , "There was an error getting charge state. Contact @rudi9719 for more information with code %+v" )
return
return
}
}
ret := fmt . Sprintf ( "Status for %+v: ```" , v . DisplayName )
ret := fmt . Sprintf ( "Status for %+v: ```" , v . DisplayName )
@ -144,7 +144,7 @@ func flashLights(m chat1.MsgSummary) {
}
}
err := v . FlashLights ( )
err := v . FlashLights ( )
if err != nil {
if err != nil {
handleError ( err , m , "There was an error flashing your lights. Contact @rudi9719 for more information with code %+v" )
handleError ( err , m , "There was an error flashing your lights. Contact @rudi9719 for more information with code %+v" )
return
return
}
}
@ -158,7 +158,7 @@ func currentTemp(m chat1.MsgSummary) {
}
}
guiSettings , err := v . GuiSettings ( )
guiSettings , err := v . GuiSettings ( )
if err != nil {
if err != nil {
handleError ( err , m , "There was an error getting your preferences. Contact @rudi9719 for more information with code %+v" )
handleError ( err , m , "There was an error getting your preferences. Contact @rudi9719 for more information with code %+v" )
return
return
}
}
climateState , err := v . ClimateState ( )
climateState , err := v . ClimateState ( )
@ -388,13 +388,16 @@ func handleError(err error, m chat1.MsgSummary, msg string) {
return
return
}
}
if strings . HasPrefix ( err . Error ( ) , "408" ) {
if strings . HasPrefix ( err . Error ( ) , "408" ) {
k . SendMessageByConvID ( m . ConvID , "Unable to wake vehicle within the timeframe. Trying to run the command again." )
if ! m . Content . Attachment . Uploaded {
handleChat ( m )
k . SendMessageByConvID ( m . ConvID , "Unable to wake vehicle within the timeframe. Trying to run the command again." )
return
m . Content . Attachment . Uploaded = true
handleChat ( m )
return
}
}
}
if strings . HasPrefix ( err . Error ( ) , "400" ) {
if strings . HasPrefix ( err . Error ( ) , "400" ) {
k . SendMessageByConvID ( m . ConvID , "Tesla returned an error. The command you tried to use may need an update. Please contact @rudi9719 with tracking ID %+v and the bad command." , tracker )
k . SendMessageByConvID ( m . ConvID , "Tesla returned an error. The command you tried to use may need an update. Please contact @rudi9719 with tracking ID %+v and the bad command." , tracker )
return
return
}
}
k . SendMessageByConvID ( m . ConvID , msg , tracker )
k . SendMessageByConvID ( m . ConvID , msg , tracker )
}
}