parent
b4007a8eb5
commit
ac9ccf633a
43
main.go
43
main.go
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"local/truckstop/message"
|
"local/truckstop/message"
|
||||||
"log"
|
"log"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -66,19 +67,30 @@ func matrixrecv() error {
|
||||||
states[state] = struct{}{}
|
states[state] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(states) == 0 {
|
setNewStates(states)
|
||||||
return nil
|
|
||||||
}
|
|
||||||
conf := *config.Get()
|
|
||||||
conf.States = []config.State{}
|
|
||||||
for k := range states {
|
|
||||||
conf.States = append(conf.States, k)
|
|
||||||
}
|
|
||||||
log.Printf("%+v, %+v", states, conf)
|
|
||||||
config.Set(conf)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setNewStates(states map[config.State]struct{}) {
|
||||||
|
if len(states) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
newstates := []config.State{}
|
||||||
|
for k := range states {
|
||||||
|
newstates = append(newstates, k)
|
||||||
|
}
|
||||||
|
sort.Slice(newstates, func(i, j int) bool {
|
||||||
|
return newstates[i] < newstates[j]
|
||||||
|
})
|
||||||
|
conf := *config.Get()
|
||||||
|
if fmt.Sprint(newstates) == fmt.Sprint(conf.States) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conf.States = newstates
|
||||||
|
log.Printf("updating config new states: %+v", conf)
|
||||||
|
config.Set(conf)
|
||||||
|
}
|
||||||
|
|
||||||
func email() error {
|
func email() error {
|
||||||
log.Printf("checking email...")
|
log.Printf("checking email...")
|
||||||
ch, err := config.Get().Emailer.ReadIMAP()
|
ch, err := config.Get().Emailer.ReadIMAP()
|
||||||
|
|
@ -101,16 +113,7 @@ func email() error {
|
||||||
states[state] = struct{}{}
|
states[state] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(states) == 0 {
|
setNewStates(states)
|
||||||
return nil
|
|
||||||
}
|
|
||||||
conf := *config.Get()
|
|
||||||
conf.States = []config.State{}
|
|
||||||
for k := range states {
|
|
||||||
conf.States = append(conf.States, k)
|
|
||||||
}
|
|
||||||
log.Printf("%+v, %+v", states, conf)
|
|
||||||
config.Set(conf)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue