specifiy state file in config

This commit is contained in:
stryan 2020-04-21 16:18:09 -04:00
parent 15b839d9a7
commit 03a5e56614
3 changed files with 7 additions and 4 deletions

View File

@ -7,3 +7,4 @@ prefix: "!tb"
owm_api_key: "OpenWeatherMap API key" owm_api_key: "OpenWeatherMap API key"
lat: "39.004608" lat: "39.004608"
long: "-76.875671" long: "-76.875671"
statefile: "state"

View File

@ -31,9 +31,10 @@ func main() {
} }
b := botlib.NewBot(c) b := botlib.NewBot(c)
tb := &TestBot{ tb := &TestBot{
Bot: b, Bot: b,
Conf: c, Conf: c,
Jobs: make(chan *mautrix.Event, 100), Jobs: make(chan *mautrix.Event, 100),
StateFile: viper.GetString("statefile"),
} }
tb.InitActions() tb.InitActions()
tb.InitScheduler() tb.InitScheduler()

View File

@ -19,6 +19,7 @@ type TestBot struct {
Conf *botlib.Config Conf *botlib.Config
Jobs chan *mautrix.Event Jobs chan *mautrix.Event
Scheduler *gocron.Scheduler Scheduler *gocron.Scheduler
StateFile string
schan chan struct{} //for stoping scheduler schan chan struct{} //for stoping scheduler
} }
@ -43,7 +44,7 @@ func (t *TestBot) DumpState() {
} }
func (t *TestBot) LoadState() { func (t *TestBot) LoadState() {
dat, err := ioutil.ReadFile("state") dat, err := ioutil.ReadFile(t.StateFile)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }