Make Matrix interactive.

change-name
Robert Jacob 5 years ago
parent e906871502
commit e2726904c0
  1. 38
      matrix/matrix.go

@ -44,6 +44,44 @@ func Listener(storage *spaceapi.Storage, homeServer, userID, token, room string)
syncer := cli.Syncer.(*gomatrix.DefaultSyncer)
syncer.OnEventType("m.room.message", func(ev *gomatrix.Event) {
if ev.Sender == userID {
return
}
msgType, ok := ev.MessageType()
if !ok || msgType != "m.text" {
return
}
body, ok := ev.Body()
if !ok {
log.Printf("[matrix] Message with no body: %s", ev)
return
}
switch body {
case txt.CommandState:
state := storage.Status().State
msg := txt.StateUnknown
if state.Open != nil {
switch *state.Open {
case true:
msg = txt.StateOpen
case false:
msg = txt.StateClosed
}
}
if _, err := cli.SendText(room, msg); err != nil {
log.Printf("Error sending message: %s", err)
}
case txt.CommandClose:
storage.Modify(func(status *spaceapi.SpaceStatus) {
open := false
status.State.Open = &open
})
}
// TODO react to events
})

Loading…
Cancel
Save