receive from enabled
parent
aef22d0a8b
commit
22b8e0fb70
13
config.json
13
config.json
|
|
@ -1,12 +1,14 @@
|
||||||
{
|
{
|
||||||
"Name": "pa",
|
"Name": "pa",
|
||||||
"Interval": {
|
"Interval": {
|
||||||
"OK": "6h0m0s",
|
"Email": "15m0s..15m0s",
|
||||||
"Error": "6h",
|
"OK": "6h0m0s..6h0m0s",
|
||||||
"Email": "15m"
|
"Error": "6h0m0s..6h0m0s"
|
||||||
},
|
},
|
||||||
"States": [
|
"States": [
|
||||||
"GA"
|
"FL",
|
||||||
|
"GA",
|
||||||
|
"NC"
|
||||||
],
|
],
|
||||||
"Storage": [
|
"Storage": [
|
||||||
"map"
|
"map"
|
||||||
|
|
@ -14,8 +16,9 @@
|
||||||
"Client": "breellocaldev@gmail.com",
|
"Client": "breellocaldev@gmail.com",
|
||||||
"Message": {
|
"Message": {
|
||||||
"Matrix": {
|
"Matrix": {
|
||||||
"Mock": true,
|
"ReceiveEnabled": true,
|
||||||
"Client": "@belandbroc:matrix.org",
|
"Client": "@belandbroc:matrix.org",
|
||||||
|
"Mock": true,
|
||||||
"Homeserver": "https://matrix-client.matrix.org",
|
"Homeserver": "https://matrix-client.matrix.org",
|
||||||
"Username": "@breellocaldev:matrix.org",
|
"Username": "@breellocaldev:matrix.org",
|
||||||
"Token": "syt_YnJlZWxsb2NhbGRldg_HTewKMMePdEcLvceAKEz_2fHsHa",
|
"Token": "syt_YnJlZWxsb2NhbGRldg_HTewKMMePdEcLvceAKEz_2fHsHa",
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ type Config struct {
|
||||||
Client string
|
Client string
|
||||||
Message struct {
|
Message struct {
|
||||||
Matrix struct {
|
Matrix struct {
|
||||||
|
ReceiveEnabled bool
|
||||||
Client string
|
Client string
|
||||||
Mock bool
|
Mock bool
|
||||||
Homeserver string
|
Homeserver string
|
||||||
|
|
|
||||||
41
main.go
41
main.go
|
|
@ -23,6 +23,9 @@ func main() {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(config.Get().Interval.Email.Get())
|
time.Sleep(config.Get().Interval.Email.Get())
|
||||||
|
if err := config.Refresh(); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
} else {
|
||||||
if config.Get().EmailerEnabled {
|
if config.Get().EmailerEnabled {
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
if err := email(); err != nil {
|
if err := email(); err != nil {
|
||||||
|
|
@ -30,6 +33,14 @@ func main() {
|
||||||
}
|
}
|
||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
}
|
}
|
||||||
|
if config.Get().Message.Matrix.ReceiveEnabled {
|
||||||
|
lock.Lock()
|
||||||
|
if err := matrixrecv(); err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
}
|
||||||
|
lock.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if err := _main(); err != nil {
|
if err := _main(); err != nil {
|
||||||
|
|
@ -38,6 +49,36 @@ func main() {
|
||||||
lock.Lock()
|
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 {
|
func email() error {
|
||||||
log.Printf("checking email...")
|
log.Printf("checking email...")
|
||||||
ch, err := config.Get().Emailer.ReadIMAP()
|
ch, err := config.Get().Emailer.ReadIMAP()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue