diff --git a/botCommands.go b/botCommands.go index b22f3e1..4d55aaf 100644 --- a/botCommands.go +++ b/botCommands.go @@ -226,4 +226,55 @@ func setupCommands() { Exec: openTrunk, } commands = append(commands, trunk) + + startCharging := BotCommand { + Advert: chat1.AdvertiseCommandAPIParam{ + Typ: "public", + Commands: []chat1.UserBotCommandInput{ + { + Name: "startcharge", + Description: "Start charging (if plugged in)", + Usage: "", + }, + }, + }, + Triggers: []string{"startcharge", "startc"}, + Exec: startCharge, + + } + commands = append(commands, startCharging) + + stopCharging := BotCommand { + Advert: chat1.AdvertiseCommandAPIParam{ + Typ: "public", + Commands: []chat1.UserBotCommandInput{ + { + Name: "stopcharge", + Description: "Stop charging (if plugged in)", + Usage: "", + }, + }, + }, + Triggers: []string{"stopcharge", "stopc"}, + Exec: stopCharge, + + } + commands = append(commands, stopCharging) + + delayCommand := BotCommand { + Advert: chat1.AdvertiseCommandAPIParam{ + Typ: "public", + Commands: []chat1.UserBotCommandInput{ + { + Name: "in", + Description: "Delay a command to run at another time.", + Usage: "2h3m startcharge", + }, + }, + }, + Triggers: []string{"in", "delay", "wait"}, + Exec: deferTime, + } + commands = append(commands, delayCommand) + } diff --git a/commands.go b/commands.go index c2db79c..62a7887 100644 --- a/commands.go +++ b/commands.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "time" "strconv" "strings" @@ -84,6 +85,21 @@ func listVehicles(m chat1.MsgSummary) { k.SendMessageByConvID(m.ConvID, ret) } +func deferTime(m chat1.MsgSummary) { + parts := strings.Split(m.Content.Text.Body, " ") + t := parts[1] + m.Content.Text.Body = fmt.Sprintf("!%+v", strings.Join(parts[1:], " ")) + timer, err := time.ParseDuration(t) + if err != nil { + tracker := uuid.NewString() + 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 + } + time.Sleep(timer) + handleChat(m) +} + func honk(m chat1.MsgSummary) { v := getVehicle(m) if v == nil { @@ -283,6 +299,34 @@ func unlockVehicle(m chat1.MsgSummary) { } } +func startCharge(m chat1.MsgSummary) { + v := getVehicle(m) + if v == nil { + return + } + err := v.StartCharging() + if err != nil { + tracker := uuid.NewString() + 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 + } +} + +func stopCharge(m chat1.MsgSummary) { + v := getVehicle(m) + if v == nil { + return + } + err := v.StopCharging() + if err != nil { + tracker := uuid.NewString() + 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 + } +} + func enableStart(m chat1.MsgSummary) { parts := strings.Split(m.Content.Text.Body, " ") if len(parts) != 3 { diff --git a/helabot b/helabot index eb58a50..37ece4a 100755 Binary files a/helabot and b/helabot differ diff --git a/main.go b/main.go index 719419d..16bd0da 100644 --- a/main.go +++ b/main.go @@ -49,7 +49,7 @@ func handleChat(m chat1.MsgSummary) { for _, v := range commands { for _, test := range v.Triggers { if command == test { - v.Exec(m) + go v.Exec(m) return } }