예제 #1
0
        public LavalinkManager(DiscordShardedClient discordShardedClient, LavalinkManagerConfig config = null)
        {
            this.config       = config ?? new LavalinkManagerConfig();
            baseDiscordClient = discordShardedClient;

            SetupManager();
        }
예제 #2
0
        /// <summary>
        /// Initiates a new Lavalink node connection
        /// </summary>
        /// <param name="discordClient"></param>
        /// <param name="config"></param>
        public LavalinkManager(DiscordSocketClient discordClient, LavalinkManagerConfig config = null)
        {
            this.config        = config ?? new LavalinkManagerConfig();
            this.discordClient = discordClient;

            // Setup the socket client events
            discordClient.VoiceServerUpdated += async(voiceServer) =>
            {
                Console.WriteLine(new LogMessage(LogSeverity.Debug, "Lavalink", "VOICE_SERVER_UPDATE(" + voiceServer.Guild.Id + ")"));

                await players[voiceServer.Guild.Id].UpdateSessionAsync(SessionChange.Connect, voiceServer);
            };

            discordClient.UserVoiceStateUpdated += async(user, oldVoiceState, newVoiceState) =>
            {
                // We only need voice state updates for the current user
                if (user.Id == discordClient.CurrentUser.Id)
                {
                    if (oldVoiceState.VoiceChannel == null && newVoiceState.VoiceChannel != null)
                    {
                        Console.WriteLine(new LogMessage(LogSeverity.Debug, "Lavalink", "VOICE_STATE_UPDATE(" + newVoiceState.VoiceChannel.Guild.Id + ", Connected)"));

                        // Connected
                        LavalinkPlayer player = players[newVoiceState.VoiceChannel.Guild.Id];
                        player?.SetSessionId(newVoiceState.VoiceSessionId);
                    }
                    else if (oldVoiceState.VoiceChannel != null && newVoiceState.VoiceChannel == null)
                    {
                        Console.WriteLine(new LogMessage(LogSeverity.Debug, "Lavalink", "VOICE_STATE_UPDATE(" + oldVoiceState.VoiceChannel.Guild.Id + ", Disconnected)"));

                        // Disconnected
                        LavalinkPlayer player = players[oldVoiceState.VoiceChannel.Guild.Id];
                        player?.SetSessionId("");

                        await player.UpdateSessionAsync(SessionChange.Disconnect, oldVoiceState.VoiceChannel.Guild.Id);

                        players.Remove(oldVoiceState.VoiceChannel.Guild.Id);
                    }
                }
            };

            discordClient.Disconnected += (exception) =>
            {
                foreach (KeyValuePair <ulong, LavalinkPlayer> player in players)
                {
                    player.Value.DisconnectAsync().GetAwaiter();
                }

                players.Clear();

                return(Task.CompletedTask);
            };
        }
예제 #3
0
 internal LavalinkWebSocket(LavalinkManager manager, LavalinkManagerConfig config)
 {
     this.manager = manager;
     this.config  = config;
     hostUri      = new Uri($"ws://{config.WebSocketHost}:{config.WebSocketPort}");
 }