add pauseuntil field to pause clients individually

master
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

@ -53,7 +53,7 @@ func (j Job) FormatMultilineText() string {
)
}
out := ""
clients := config.Get().Clients
clients := config.Clients()
for k := range clients {
log.Printf("job multiline: %+v contains %s then use %v", clients[k].States, j.Pickup.State, k)
if strings.Contains(fmt.Sprint(clients[k].States), j.Pickup.State) {

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{}{}
}

View File

@ -34,12 +34,12 @@ func (m Matrix) Receive() ([]Message, error) {
if m.mock {
log.Printf("matrix.Receive()")
messages := make([]Message, 0)
for k := range config.Get().Clients {
for k := range config.Clients() {
messages = append(messages, Message{Sender: k, Content: "OH"})
}
return messages, nil
}
clients := config.Get().Clients
clients := config.Clients()
matrixIDs := map[string]struct{}{}
for k := range clients {
matrixIDs[clients[k].IDs.Matrix] = struct{}{}
@ -69,7 +69,7 @@ func (m Matrix) Receive() ([]Message, error) {
return nil, err
}
for i := range messages {
for k, v := range config.Get().Clients {
for k, v := range config.Clients() {
if v.IDs.Matrix == messages[i].Sender {
messages[i].Sender = k
}