add pauseuntil field to pause clients individually
parent
95bb4de13a
commit
9840be93f6
|
|
@ -53,7 +53,7 @@ func (j Job) FormatMultilineText() string {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
out := ""
|
out := ""
|
||||||
clients := config.Get().Clients
|
clients := config.Clients()
|
||||||
for k := range clients {
|
for k := range clients {
|
||||||
log.Printf("job multiline: %+v contains %s then use %v", clients[k].States, j.Pickup.State, k)
|
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) {
|
if strings.Contains(fmt.Sprint(clients[k].States), j.Pickup.State) {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"local/storage"
|
"local/storage"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
|
@ -14,12 +15,7 @@ type Config struct {
|
||||||
OK Duration
|
OK Duration
|
||||||
Error Duration
|
Error Duration
|
||||||
}
|
}
|
||||||
Clients map[string]struct {
|
Clients map[string]Client
|
||||||
States []State
|
|
||||||
IDs struct {
|
|
||||||
Matrix string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Storage []string
|
Storage []string
|
||||||
Message struct {
|
Message struct {
|
||||||
Matrix struct {
|
Matrix struct {
|
||||||
|
|
@ -46,6 +42,14 @@ type Config struct {
|
||||||
db storage.DB
|
db storage.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Client struct {
|
||||||
|
States []State
|
||||||
|
IDs struct {
|
||||||
|
Matrix string
|
||||||
|
}
|
||||||
|
PauseUntil time.Time
|
||||||
|
}
|
||||||
|
|
||||||
var live Config
|
var live Config
|
||||||
|
|
||||||
func configPath() string {
|
func configPath() string {
|
||||||
|
|
@ -56,10 +60,20 @@ func configPath() string {
|
||||||
return p
|
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 {
|
func AllStates() []State {
|
||||||
c := Get()
|
|
||||||
statem := map[State]struct{}{}
|
statem := map[State]struct{}{}
|
||||||
for _, v := range c.Clients {
|
for _, v := range Clients() {
|
||||||
for _, state := range v.States {
|
for _, state := range v.States {
|
||||||
statem[state] = struct{}{}
|
statem[state] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,12 @@ func (m Matrix) Receive() ([]Message, error) {
|
||||||
if m.mock {
|
if m.mock {
|
||||||
log.Printf("matrix.Receive()")
|
log.Printf("matrix.Receive()")
|
||||||
messages := make([]Message, 0)
|
messages := make([]Message, 0)
|
||||||
for k := range config.Get().Clients {
|
for k := range config.Clients() {
|
||||||
messages = append(messages, Message{Sender: k, Content: "OH"})
|
messages = append(messages, Message{Sender: k, Content: "OH"})
|
||||||
}
|
}
|
||||||
return messages, nil
|
return messages, nil
|
||||||
}
|
}
|
||||||
clients := config.Get().Clients
|
clients := config.Clients()
|
||||||
matrixIDs := map[string]struct{}{}
|
matrixIDs := map[string]struct{}{}
|
||||||
for k := range clients {
|
for k := range clients {
|
||||||
matrixIDs[clients[k].IDs.Matrix] = struct{}{}
|
matrixIDs[clients[k].IDs.Matrix] = struct{}{}
|
||||||
|
|
@ -69,7 +69,7 @@ func (m Matrix) Receive() ([]Message, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for i := range messages {
|
for i := range messages {
|
||||||
for k, v := range config.Get().Clients {
|
for k, v := range config.Clients() {
|
||||||
if v.IDs.Matrix == messages[i].Sender {
|
if v.IDs.Matrix == messages[i].Sender {
|
||||||
messages[i].Sender = k
|
messages[i].Sender = k
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue