fix import loop

This commit is contained in:
Dot-Rar 2020-01-17 21:40:15 +00:00
parent 05b31e02ae
commit 52a88f919b
2 changed files with 22 additions and 12 deletions

13
cache/webchat.go vendored
View File

@ -3,7 +3,6 @@ package cache
import (
"encoding/json"
"fmt"
"github.com/TicketsBot/GoPanel/app/http/endpoints/manage"
)
type TicketMessage struct {
@ -13,7 +12,7 @@ type TicketMessage struct {
Content string `json:"content"`
}
func (c *RedisClient) ListenForMessages() {
func (c *RedisClient) ListenForMessages(message chan TicketMessage) {
pubsub := c.Subscribe("tickets:webchat:inboundmessage")
for {
@ -28,14 +27,6 @@ func (c *RedisClient) ListenForMessages() {
continue
}
manage.SocketsLock.Lock()
for _, socket := range manage.Sockets {
if socket.Guild == decoded.GuildId && socket.Ticket == decoded.TicketId {
if err := socket.Ws.WriteJSON(decoded); err != nil {
fmt.Println(err.Error())
}
}
}
manage.SocketsLock.Unlock()
message<-decoded
}
}

View File

@ -1,7 +1,9 @@
package main
import (
"fmt"
"github.com/TicketsBot/GoPanel/app/http"
"github.com/TicketsBot/GoPanel/app/http/endpoints/manage"
"github.com/TicketsBot/GoPanel/cache"
"github.com/TicketsBot/GoPanel/config"
"github.com/TicketsBot/GoPanel/database"
@ -16,7 +18,24 @@ func main() {
database.ConnectToDatabase()
cache.Client = cache.NewRedisClient()
go cache.Client.ListenForMessages()
go Listen(cache.Client)
http.StartServer()
}
func Listen(client cache.RedisClient) {
ch := make(chan cache.TicketMessage)
go client.ListenForMessages(ch)
for decoded := range ch {
manage.SocketsLock.Lock()
for _, socket := range manage.Sockets {
if socket.Guild == decoded.GuildId && socket.Ticket == decoded.TicketId {
if err := socket.Ws.WriteJSON(decoded); err != nil {
fmt.Println(err.Error())
}
}
}
manage.SocketsLock.Unlock()
}
}