Пример #1
0
        private async Task OnUVSU(SocketUser user, SocketVoiceState oldState, SocketVoiceState newState)
        {
            if (user.Id != _baseClient.CurrentUser.Id)
            {
                return;
            }

            switch (oldState)
            {
            case var state when state.VoiceChannel is null && !(newState.VoiceChannel is null):
                _voiceState = newState;
                _lavalink.LogDebug($"Voice state updated. Voice session Id: {_voiceState.VoiceSessionId}");
                break;

            case var state when !(state.VoiceChannel is null) && newState.VoiceChannel is null:
                if (!_players.TryGetValue(state.VoiceChannel.Guild.Id, out var oldPlayer))
                {
                    return;
                }
                await oldPlayer.DisconnectAsync().ConfigureAwait(false);

                _players.TryRemove(state.VoiceChannel.Guild.Id, out _);
                LavaSocket.SendPayload(new DestroyPayload(state.VoiceChannel.Guild.Id));
                break;

            case var state when state.VoiceChannel?.Id != newState.VoiceChannel?.Id:
                if (!_players.TryGetValue(state.VoiceChannel.Guild.Id, out var updatePlayer))
                {
                    return;
                }
                updatePlayer.VoiceChannel = newState.VoiceChannel;
                _players.TryUpdate(state.VoiceChannel.Guild.Id, updatePlayer, updatePlayer);
                _lavalink.LogInfo(
                    $"Moved from {state.VoiceChannel.Name} to {newState.VoiceChannel.Name}.");
                break;
            }
        }
Пример #2
0
 /// <summary>
 /// Plays the specified track.
 /// </summary>
 /// <param name="track"><see cref="LavaTrack"/></param>
 /// <exception cref="InvalidOperationException">Throws if player isn't connected.</exception>
 public void Play(LavaTrack track)
 {
     CurrentTrack = track;
     Volatile.Write(ref _isDisposed, false);
     _lavaSocket.SendPayload(new PlayPayload(Guild.Id, track));
 }