fix import loop
This commit is contained in:
parent
05b31e02ae
commit
52a88f919b
13
cache/webchat.go
vendored
13
cache/webchat.go
vendored
@ -3,7 +3,6 @@ package cache
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/TicketsBot/GoPanel/app/http/endpoints/manage"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TicketMessage struct {
|
type TicketMessage struct {
|
||||||
@ -13,7 +12,7 @@ type TicketMessage struct {
|
|||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RedisClient) ListenForMessages() {
|
func (c *RedisClient) ListenForMessages(message chan TicketMessage) {
|
||||||
pubsub := c.Subscribe("tickets:webchat:inboundmessage")
|
pubsub := c.Subscribe("tickets:webchat:inboundmessage")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@ -28,14 +27,6 @@ func (c *RedisClient) ListenForMessages() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
manage.SocketsLock.Lock()
|
message<-decoded
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/TicketsBot/GoPanel/app/http"
|
"github.com/TicketsBot/GoPanel/app/http"
|
||||||
|
"github.com/TicketsBot/GoPanel/app/http/endpoints/manage"
|
||||||
"github.com/TicketsBot/GoPanel/cache"
|
"github.com/TicketsBot/GoPanel/cache"
|
||||||
"github.com/TicketsBot/GoPanel/config"
|
"github.com/TicketsBot/GoPanel/config"
|
||||||
"github.com/TicketsBot/GoPanel/database"
|
"github.com/TicketsBot/GoPanel/database"
|
||||||
@ -16,7 +18,24 @@ func main() {
|
|||||||
database.ConnectToDatabase()
|
database.ConnectToDatabase()
|
||||||
|
|
||||||
cache.Client = cache.NewRedisClient()
|
cache.Client = cache.NewRedisClient()
|
||||||
go cache.Client.ListenForMessages()
|
go Listen(cache.Client)
|
||||||
|
|
||||||
http.StartServer()
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user