Combine queued messages into one to save on message spam (fix #18)

This commit is contained in:
Noah 2024-04-08 15:44:12 -05:00
parent fc91613a66
commit 8875a40fea

View File

@ -188,17 +188,28 @@ func initMatrix() {
}) })
go func() { go func() {
for range time.Tick(time.Second * 6) { for range time.Tick(time.Second * 2) {
log.Printf("Scanning for queued messages...") log.Printf("Scanning for queued messages...")
for _, msg := range MatrixOut { if len(MatrixOut) > 0 {
_, err := client.SendMessageEvent(context.Background(), id.RoomID(configuration.matrix.room_id), event.EventMessage, format.RenderMarkdown(msg.text, true, false)) text := ""
for i, msg := range MatrixOut {
text += msg.text
if i != len(MatrixOut) {
text += "\n"
}
}
MatrixOut = []MatrixMessage{}
_, err := client.SendMessageEvent(context.Background(),
id.RoomID(configuration.matrix.room_id),
event.EventMessage,
format.RenderMarkdown(text, true, false),
)
if err != nil { if err != nil {
log.Printf("[Matrix] ERROR : %s", err) log.Printf("[Matrix] ERROR : %s", err)
continue continue
} }
log.Print("[Matrix] Sent queued message successfully.") log.Print("[Matrix] Sent queued message(s) successfully.")
} }
MatrixOut = []MatrixMessage{}
} }
}() }()