50 lines
917 B
Go
50 lines
917 B
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
|
|
"git.saintnet.tech/stryan/vega/botlib"
|
|
"maunium.net/go/mautrix"
|
|
)
|
|
|
|
type TestBot struct {
|
|
Bot *botlib.Bot
|
|
Conf *botlib.Config
|
|
Jobs chan *mautrix.Event
|
|
}
|
|
|
|
func (t *TestBot) Shutdown() {
|
|
log.Printf("%v is shutting down", t.Conf.Name)
|
|
t.Bot.Client.StopSync()
|
|
t.DumpState()
|
|
os.Exit(0)
|
|
}
|
|
|
|
func (t *TestBot) DumpState() {
|
|
id := []byte(t.Bot.ManagementRoomID)
|
|
err := ioutil.WriteFile("state", id, 0644)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
}
|
|
|
|
func (t *TestBot) LoadState() {
|
|
dat, err := ioutil.ReadFile("state")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
t.Bot.ManagementRoomID = strings.Trim(string(dat), "")
|
|
}
|
|
|
|
func (t *TestBot) InitActions() {
|
|
ActionList = make(map[string]Action)
|
|
ActionList["version"] = func(inputs ...string) string { return "0.0.1" }
|
|
ActionList["echo"] = func(inputs ...string) string {
|
|
return strings.Join(inputs[:], "")
|
|
}
|
|
}
|