Initial capabilities support for custom implementations
This commit is contained in:
parent
8efc77cacc
commit
7eae103756
11
lavalink.go
11
lavalink.go
|
@ -23,6 +23,8 @@ type Lavalink struct {
|
||||||
nodes []*Node
|
nodes []*Node
|
||||||
players map[string]*Player
|
players map[string]*Player
|
||||||
|
|
||||||
|
capabilities map[string]interface{}
|
||||||
|
|
||||||
BestNodeFunc func([]*Node) (*Node, error)
|
BestNodeFunc func([]*Node) (*Node, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,3 +135,12 @@ func (lavalink *Lavalink) GetPlayer(guild string) (*Player, error) {
|
||||||
|
|
||||||
return p, nil
|
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
|
||||||
|
}
|
||||||
|
|
17
node.go
17
node.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/valyala/fastjson"
|
"github.com/valyala/fastjson"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
@ -71,6 +72,22 @@ func (node *Node) open() error {
|
||||||
header.Set("Num-Shards", node.manager.shards)
|
header.Set("Num-Shards", node.manager.shards)
|
||||||
header.Set("User-Id", node.manager.userID)
|
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)
|
ws, resp, err := websocket.DefaultDialer.Dial(node.config.WebSocket, header)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue