receive from enabled

This commit is contained in:
Bel LaPointe
2022-01-11 09:42:42 -05:00
parent aef22d0a8b
commit 22b8e0fb70
3 changed files with 62 additions and 17 deletions

51
main.go
View File

@@ -23,12 +23,23 @@ func main() {
go func() {
for {
time.Sleep(config.Get().Interval.Email.Get())
if config.Get().EmailerEnabled {
lock.Lock()
if err := email(); err != nil {
log.Print(err)
if err := config.Refresh(); err != nil {
log.Println(err)
} else {
if config.Get().EmailerEnabled {
lock.Lock()
if err := email(); err != nil {
log.Print(err)
}
lock.Unlock()
}
if config.Get().Message.Matrix.ReceiveEnabled {
lock.Lock()
if err := matrixrecv(); err != nil {
log.Print(err)
}
lock.Unlock()
}
lock.Unlock()
}
}
}()
@@ -38,6 +49,36 @@ func main() {
lock.Lock()
}
func matrixrecv() error {
log.Printf("checking matrix...")
defer log.Printf("/checking matrix...")
sender := message.NewMatrix()
messages, err := sender.Receive()
if err != nil {
return err
}
states := map[config.State]struct{}{}
for _, msg := range messages {
if len(states) > 0 {
continue
}
for _, state := range parseOutStates([]byte(msg)) {
states[state] = struct{}{}
}
}
if len(states) == 0 {
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
}
func email() error {
log.Printf("checking email...")
ch, err := config.Get().Emailer.ReadIMAP()