Lavalink Additions and Fixes
Created by: Neuheit
Summary
This PR implements Lavalink load/region handling, adds a few convenience methods, fixes a bug mentioned in the Discord, and exposes a few private collections. Fixes #557 (closed).
Details
Starting with the load balancing, this adds a new method, LavalinkExtension.GetIdealNodeConnection()
, which will sort through all node's statistics and return the one with the lowest resource usage. I based this off of 2 other Lavalink clients. The method also accepts an optional DiscordVoiceRegion, which can be used to filter nodes if they have a voice region specified in their configuration.
Additionally, this fixes a race condition mentioned in the Discord that prevented the WebSocket closed event from being fired. I removed my previous code from that handler and added logic to the voice state update event handler to ensure that the WebSocket closed event is called first, and the voice state update logic second. There is also a value in the configuration to specify long to wait.
I also exposed the ConnectedNodes
and ConnectedGuilds
collections as read only concurrent dictionaries to allow linq querying, I changed the LavalinkRestClient to accept a public constructor to allow for outside use, and I added a new property to the connection endpoint to allow for secured Lavalink connections. Finally, I moved both Lavalink enums to their own separate file.
Changes proposed
- Adds Lavalink load and region balancing.
- Fixes a race condition with removing a guild connection and firing an event in the node.
- Exposes both Lavalink connection collections.
- Makes the LavalinkRestClient constructor public
- Adds secured handling to the connection endpoint