Better error logging
This commit is contained in:
23
commands.go
23
commands.go
@ -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,10 +388,13 @@ func handleError(err error, m chat1.MsgSummary, msg string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(err.Error(), "408") {
|
if strings.HasPrefix(err.Error(), "408") {
|
||||||
|
if !m.Content.Attachment.Uploaded {
|
||||||
k.SendMessageByConvID(m.ConvID, "Unable to wake vehicle within the timeframe. Trying to run the command again.")
|
k.SendMessageByConvID(m.ConvID, "Unable to wake vehicle within the timeframe. Trying to run the command again.")
|
||||||
|
m.Content.Attachment.Uploaded = true
|
||||||
handleChat(m)
|
handleChat(m)
|
||||||
return
|
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
|
||||||
|
|||||||
3
main.go
3
main.go
@ -44,6 +44,9 @@ func main() {
|
|||||||
|
|
||||||
func handleChat(m chat1.MsgSummary) {
|
func handleChat(m chat1.MsgSummary) {
|
||||||
defer log.PanicSafe()
|
defer log.PanicSafe()
|
||||||
|
if m.Content.TypeName != "text" {
|
||||||
|
return
|
||||||
|
}
|
||||||
parts := strings.Split(m.Content.Text.Body, " ")
|
parts := strings.Split(m.Content.Text.Body, " ")
|
||||||
command := strings.Replace(parts[0], "!", "", -1)
|
command := strings.Replace(parts[0], "!", "", -1)
|
||||||
for _, v := range commands {
|
for _, v := range commands {
|
||||||
|
|||||||
Reference in New Issue
Block a user