add pauseuntil field to pause clients individually

This commit is contained in:
Bel LaPointe
2022-01-11 23:03:50 -05:00
parent 95bb4de13a
commit 9840be93f6
3 changed files with 26 additions and 12 deletions

View File

@@ -6,6 +6,7 @@ import (
"local/storage"
"os"
"sync"
"time"
)
type Config struct {
@@ -14,12 +15,7 @@ type Config struct {
OK Duration
Error Duration
}
Clients map[string]struct {
States []State
IDs struct {
Matrix string
}
}
Clients map[string]Client
Storage []string
Message struct {
Matrix struct {
@@ -46,6 +42,14 @@ type Config struct {
db storage.DB
}
type Client struct {
States []State
IDs struct {
Matrix string
}
PauseUntil time.Time
}
var live Config
func configPath() string {
@@ -56,10 +60,20 @@ func configPath() string {
return p
}
func Clients() map[string]Client {
clients := Get().Clients
result := map[string]Client{}
for k := range clients {
if clients[k].PauseUntil.IsZero() || time.Now().After(clients[k].PauseUntil) {
result[k] = clients[k]
}
}
return result
}
func AllStates() []State {
c := Get()
statem := map[State]struct{}{}
for _, v := range c.Clients {
for _, v := range Clients() {
for _, state := range v.States {
statem[state] = struct{}{}
}