Esempio n. 1
0
        public bool ConnectToVoice(ISocketMessageChannel requester, SocketVoiceChannel channel)
        {
            if (m_playbackThread == null)
            {
                m_playbackThread = Task.Factory.StartNew(PlaybackThread, m_playbackCancellationSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
            }

            if (m_loadedPlaylists == false && m_loadingPlaylists == false)
            {
                Utilities.Execute(async() => await LoadPlaylists(requester));
            }

            if (m_connectedChannel != null && m_audioClient?.ConnectionState == ConnectionState.Connected)
            {
                if (channel.Id == m_connectedChannel.Id)
                {
                    return(true);
                }
            }

            m_audioClient = m_guild.ConnectToVoice(channel);
            if (m_audioClient == null)
            {
                Logging.LogError(LogType.Bot, $"Audio client is not connected on server {m_guild.Name}.");
                return(false);
            }

            m_connectedChannel = channel;

            return(true);
        }
Esempio n. 2
0
        public bool ConnectToVoice(ISocketMessageChannel requester, SocketVoiceChannel channel)
        {
            if (channel == null)
            {
                Logging.LogError(LogType.Bot, $"Sent Channel was null something went wrong {m_guild.Name}.");
                return(false);
            }

            if (m_playbackThread == null)
            {
                m_playbackThread = Task.Factory.StartNew(PlaybackThread, m_taskCancellationSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
            }

            if (m_connectedChannel != null && m_audioClient?.ConnectionState == ConnectionState.Connected)
            {
                if (channel.Id == m_connectedChannel.Id)
                {
                    return(true);
                }
                else
                {
                    Stop();
                }
            }

            m_audioClient = m_guild.ConnectToVoice(channel);
            if (m_audioClient == null)
            {
                Logging.LogError(LogType.Bot, $"Audio client is not connected on server {m_guild.Name}.");
                return(false);
            }

            m_connectedChannel = channel;

            return(true);
        }