From 610ea960f1c4eca60274f825fb8accb19d91a7a5 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Fri, 9 Jul 2021 22:45:05 -0400 Subject: [PATCH] Better error logging --- commands.go | 31 +++++++++++++++++-------------- main.go | 3 +++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/commands.go b/commands.go index 72fd529..afe1b06 100644 --- a/commands.go +++ b/commands.go @@ -14,12 +14,12 @@ import ( func reset(m chat1.MsgSummary) { _, err := k.KVDelete(&m.Channel.Name, "teslabot", "authtok") 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 } _, err = k.KVDelete(&m.Channel.Name, "teslabot", "startPass") 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 } } @@ -42,13 +42,13 @@ func authenticate(m chat1.MsgSummary) { password := parts[2] t, err := login(context.Background(), username, password) 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 } log.LogDebug("Token created for %+v", m.Sender.Username) _, err = k.KVPut(&m.Channel.Name, "teslabot", "authtok", t) 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 } k.ReactByConvID(m.ConvID, m.Id, ":car:") @@ -63,7 +63,7 @@ func listVehicles(m chat1.MsgSummary) { } v, err := c.Vehicles() 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 } ret := "Detected vehicles for account: ```" @@ -83,7 +83,7 @@ func deferTime(m chat1.MsgSummary) { m.Content.Text.Body = fmt.Sprintf("!%+v", command) timer, err := time.ParseDuration(t) 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 } 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() 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 } k.SendMessageByConvID(m.ConvID, "I've honked your horn!") @@ -112,7 +112,7 @@ func chargeStatus(m chat1.MsgSummary) { } state, err := v.ChargeState() 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 } ret := fmt.Sprintf("Status for %+v: ```", v.DisplayName) @@ -144,7 +144,7 @@ func flashLights(m chat1.MsgSummary) { } err := v.FlashLights() 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 } @@ -158,7 +158,7 @@ func currentTemp(m chat1.MsgSummary) { } guiSettings, err := v.GuiSettings() 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 } climateState, err := v.ClimateState() @@ -388,13 +388,16 @@ func handleError(err error, m chat1.MsgSummary, msg string) { return } if strings.HasPrefix(err.Error(), "408") { - k.SendMessageByConvID(m.ConvID, "Unable to wake vehicle within the timeframe. Trying to run the command again.") - handleChat(m) - return + if !m.Content.Attachment.Uploaded { + k.SendMessageByConvID(m.ConvID, "Unable to wake vehicle within the timeframe. Trying to run the command again.") + m.Content.Attachment.Uploaded = true + handleChat(m) + return + } } 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) return } k.SendMessageByConvID(m.ConvID, msg, tracker) -} \ No newline at end of file +} diff --git a/main.go b/main.go index 16bd0da..0f4bb53 100644 --- a/main.go +++ b/main.go @@ -44,6 +44,9 @@ func main() { func handleChat(m chat1.MsgSummary) { defer log.PanicSafe() + if m.Content.TypeName != "text" { + return + } parts := strings.Split(m.Content.Text.Body, " ") command := strings.Replace(parts[0], "!", "", -1) for _, v := range commands {