Ejemplo n.º 1
0
        /// <summary>
        ///     Triggers the <see cref="NodeDisconnected"/> event asynchronously.
        /// </summary>
        /// <param name="eventArgs">the event arguments</param>
        /// <returns>a task that represents the asynchronous operation</returns>
        protected virtual async Task OnNodeDisconnectedAsync(NodeDisconnectedEventArgs eventArgs)
        {
            // stay-online feature
            if (StayOnline && eventArgs.ByRemote)
            {
                _logger?.Log(this, "(Stay-Online) Node died! Moving players to a new node...", LogLevel.Warning);

                var players = eventArgs.Node.GetPlayers <LavalinkPlayer>();

                // move all players
                var tasks = players.Select(player => MovePlayerToNewNodeAsync(eventArgs.Node, player)).ToArray();

                // await until all players were moved to a new node
                await Task.WhenAll(tasks);
            }

            // invoke event
            await NodeDisconnected.InvokeAsync(this, eventArgs);
        }