diff --git a/lavalink.go b/lavalink.go index 4a4369b..28e189d 100644 --- a/lavalink.go +++ b/lavalink.go @@ -23,6 +23,8 @@ type Lavalink struct { nodes []*Node players map[string]*Player + capabilities map[string]interface{} + BestNodeFunc func([]*Node) (*Node, error) } @@ -133,3 +135,12 @@ func (lavalink *Lavalink) GetPlayer(guild string) (*Player, error) { return p, nil } + +// Add capabilities mappings to the client, letting the server know what we support +func (lavalink *Lavalink) AddCapability(key string, i interface{}) { + if lavalink.capabilities == nil { + lavalink.capabilities = make(map[string]interface{}) + } + + lavalink.capabilities[key] = i +} diff --git a/node.go b/node.go index f296f72..8bcd4ea 100644 --- a/node.go +++ b/node.go @@ -6,6 +6,7 @@ import ( "github.com/valyala/fastjson" "net/http" "strconv" + "strings" "github.com/gorilla/websocket" ) @@ -71,6 +72,22 @@ func (node *Node) open() error { header.Set("Num-Shards", node.manager.shards) header.Set("User-Id", node.manager.userID) + if node.manager.capabilities != nil { + v := make([]string, 0) + + for k, vals := range node.manager.capabilities { + b, err := json.Marshal(vals) + + if err != nil { + continue + } + + v = append(v, k+"="+string(b)) + } + + header.Set("Capabilities", strings.Join(v, ";")) + } + ws, resp, err := websocket.DefaultDialer.Dial(node.config.WebSocket, header) if err != nil {