Browse Source

Add start/stop charge commands and delay command for delayed execution.

master
Gregory Rudolph 3 years ago
parent
commit
92b4d0a25e
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 51
      botCommands.go
  2. 44
      commands.go
  3. BIN
      helabot
  4. 2
      main.go

51
botCommands.go

@ -226,4 +226,55 @@ func setupCommands() { @@ -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

@ -3,6 +3,7 @@ package main @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"time"
"strconv"
"strings"
@ -84,6 +85,21 @@ func listVehicles(m chat1.MsgSummary) { @@ -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) { @@ -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 {

BIN
helabot

Binary file not shown.

2
main.go

@ -49,7 +49,7 @@ func handleChat(m chat1.MsgSummary) { @@ -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
}
}

Loading…
Cancel
Save