internal LavalinkNodeConnection(DiscordClient client, LavalinkExtension extension, LavalinkConfiguration config)
        {
            this.Discord       = client;
            this.Parent        = extension;
            this.Configuration = new LavalinkConfiguration(config);

            if (config.Region != null && this.Discord.VoiceRegions.Values.Contains(config.Region))
            {
                this.Region = config.Region;
            }

            this.ConnectedGuilds = new ReadOnlyConcurrentDictionary <ulong, LavalinkGuildConnection>(this._connectedGuilds);
            this.Statistics      = new LavalinkStatistics();

            this._lavalinkSocketError = new AsyncEvent <LavalinkNodeConnection, SocketErrorEventArgs>("LAVALINK_SOCKET_ERROR", TimeSpan.Zero, this.Discord.EventErrorHandler);
            this._disconnected        = new AsyncEvent <LavalinkNodeConnection, NodeDisconnectedEventArgs>("LAVALINK_NODE_DISCONNECTED", TimeSpan.Zero, this.Discord.EventErrorHandler);
            this._statsReceived       = new AsyncEvent <LavalinkNodeConnection, StatisticsReceivedEventArgs>("LAVALINK_STATS_RECEIVED", TimeSpan.Zero, this.Discord.EventErrorHandler);
            this._playerUpdated       = new AsyncEvent <LavalinkGuildConnection, PlayerUpdateEventArgs>("LAVALINK_PLAYER_UPDATED", TimeSpan.Zero, this.Discord.EventErrorHandler);
            this._playbackStarted     = new AsyncEvent <LavalinkGuildConnection, TrackStartEventArgs>("LAVALINK_PLAYBACK_STARTED", TimeSpan.Zero, this.Discord.EventErrorHandler);
            this._playbackFinished    = new AsyncEvent <LavalinkGuildConnection, TrackFinishEventArgs>("LAVALINK_PLAYBACK_FINISHED", TimeSpan.Zero, this.Discord.EventErrorHandler);
            this._trackStuck          = new AsyncEvent <LavalinkGuildConnection, TrackStuckEventArgs>("LAVALINK_TRACK_STUCK", TimeSpan.Zero, this.Discord.EventErrorHandler);
            this._trackException      = new AsyncEvent <LavalinkGuildConnection, TrackExceptionEventArgs>("LAVALINK_TRACK_EXCEPTION", TimeSpan.Zero, this.Discord.EventErrorHandler);

            this.VoiceServerUpdates          = new ConcurrentDictionary <ulong, TaskCompletionSource <VoiceServerUpdateEventArgs> >();
            this.VoiceStateUpdates           = new ConcurrentDictionary <ulong, TaskCompletionSource <VoiceStateUpdateEventArgs> >();
            this.Discord.VoiceStateUpdated  += this.Discord_VoiceStateUpdated;
            this.Discord.VoiceServerUpdated += this.Discord_VoiceServerUpdated;

            this.Rest = new LavalinkRestClient(this.Configuration, this.Discord);

            Volatile.Write(ref this._isDisposed, false);
        }
Exemple #2
0
        /// <summary>
        /// Creates a new Lavalink client with specified settings.
        /// </summary>
        /// <param name="client">Discord client to create Lavalink instance for.</param>
        /// <returns>Lavalink client instance.</returns>
        public static LavalinkExtension UseLavalink(this DiscordClient client)
        {
            if (client.GetExtension <LavalinkExtension>() != null)
            {
                throw new InvalidOperationException("Lavalink is already enabled for that client.");
            }

            var lava = new LavalinkExtension();

            client.AddExtension(lava);
            return(lava);
        }
        /// <summary>
        /// Creates a new Lavalink client with specified settings.
        /// </summary>
        /// <param name="client">Discord client to create Lavalink instance for.</param>
        /// <returns>Lavalink client instance.</returns>
        public static LavalinkExtension UseLavalink(this DiscordClient client)
        {
            if (client.GetExtension <LavalinkExtension>() != null)
            {
                throw new InvalidOperationException("Lavalink is already enabled for that client.");
            }

            if (!client.Configuration.Intents.HasIntent(DiscordIntents.GuildVoiceStates))
            {
                client.Logger.LogCritical(LavalinkEvents.Intents, "The Lavalink extension is registered but the guild voice states intent is not enabled. It is highly recommended to enable it.");
            }

            var lava = new LavalinkExtension();

            client.AddExtension(lava);
            return(lava);
        }