Пример #1
0
        /// <summary>
        /// Connect to a Lavalink node.
        /// </summary>
        /// <param name="config">Lavalink client configuration.</param>
        /// <returns>The established Lavalink connection.</returns>
        public async Task <LavalinkNodeConnection> ConnectAsync(LavalinkConfiguration config)
        {
            if (this.ConnectedNodes.ContainsKey(config.SocketEndpoint))
            {
                return(this.ConnectedNodes[config.SocketEndpoint]);
            }

            var con = new LavalinkNodeConnection(this.Client, config);

            con.NodeDisconnected += this.Con_NodeDisconnected;
            con.Disconnected     += this.Con_Disconnected;
            this.ConnectedNodes[con.NodeEndpoint] = con;
            try
            {
                await con.StartAsync().ConfigureAwait(false);
            }
            catch
            {
                this.Con_NodeDisconnected(con);
                throw;
            }

            return(con);
        }
Пример #2
0
 private void Con_NodeDisconnected(LavalinkNodeConnection node)
 => this.ConnectedNodes.TryRemove(node.NodeEndpoint, out _);
Пример #3
0
 private Task Con_Disconnected(LavalinkNodeConnection node, NodeDisconnectedEventArgs e)
 => this._nodeDisconnected.InvokeAsync(node, e);