Add start/stop charge commands and delay command for delayed execution.
This commit is contained in:
@ -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)
|
||||
|
||||
}
|
||||
|
||||
44
commands.go
44
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 {
|
||||
|
||||
Reference in New Issue
Block a user