Beispiel #1
0
        /// <summary>
        /// Joins a voice channel and returns <see cref="LavaPlayer"/> otherwise returns an existing <see cref="LavaPlayer"/>.
        /// </summary>
        /// <param name="voiceChannel">Voice channel to conenct to.</param>
        /// <param name="textChannel">Text channel to send updates to.</param>
        /// <returns><see cref="LavaPlayer"/></returns>
        public async Task <LavaPlayer> JoinAsync(IVoiceChannel voiceChannel, IMessageChannel textChannel = null)
        {
            if (_players.ContainsKey(voiceChannel.GuildId))
            {
                return(_players[voiceChannel.GuildId]);
            }
            var player = new LavaPlayer(this, voiceChannel, textChannel);
            await voiceChannel.ConnectAsync(false, false, true);

            _players.TryAdd(voiceChannel.Guild.Id, player);
            return(player);
        }
Beispiel #2
0
        /// <summary>
        /// Connects to <paramref name="voiceChannel"/> and returns a <see cref="LavaPlayer"/>.
        /// </summary>
        /// <param name="voiceChannel">Voice channel to connect to.</param>
        /// <param name="textChannel">Optional text channel that can send updates.</param>
        public async Task <LavaPlayer> ConnectAsync(IVoiceChannel voiceChannel, ITextChannel textChannel = null)
        {
            if (_players.TryGetValue(voiceChannel.GuildId, out var player))
            {
                return(player);
            }


            player = new LavaPlayer(voiceChannel, textChannel, socketHelper);
            await voiceChannel.ConnectAsync(false, false, true).ConfigureAwait(false);

            _players.TryAdd(voiceChannel.GuildId, player);

            return(player);
        }
Beispiel #3
0
        private async Task DisconnectTaskAsync(LavaPlayer player, CancellationToken token)
        {
            await Task.Delay(this.Configuration.InactivityTimeout, token).ConfigureAwait(false);

            if (token.IsCancellationRequested)
            {
                return;
            }

            if (player.IsPlaying)
            {
                await player.StopAsync().ConfigureAwait(false);
            }

            await this.DisconnectAsync(player.VoiceChannel).ConfigureAwait(false);
        }
Beispiel #4
0
        /// <summary>
        /// Connects to <paramref name="voiceChannel"/> and returns a <see cref="LavaPlayer"/>.
        /// </summary>
        /// <param name="voiceChannel">Voice channel to connect to.</param>
        /// <param name="textChannel">Optional text channel that can send updates.</param>
        public async Task <LavaPlayer> ConnectAsync(IVoiceChannel voiceChannel, ITextChannel textChannel = null)
        {
            if (this.Players.TryGetValue(voiceChannel.GuildId, out LavaPlayer player))
            {
                return(player);
            }

            await voiceChannel.ConnectAsync(this.Configuration.SelfDeaf, false, true).ConfigureAwait(false);

            player = new LavaPlayer(voiceChannel, textChannel, this._socketHelper);
            this.Players.TryAdd(voiceChannel.GuildId, player);
            if (this.Configuration.DefaultVolume != 100)
            {
                await player.SetVolumeAsync(this.Configuration.DefaultVolume);
            }

            return(player);
        }
Beispiel #5
0
        /// <summary>
        /// Connects to <paramref name="voiceChannel"/> and returns a <see cref="LavaPlayer"/>.
        /// </summary>
        /// <param name="voiceChannel">Voice channel to connect to.</param>
        /// <param name="textChannel">Optional text channel that can send updates.</param>
        public async Task <LavaPlayer> ConnectAsync(IVoiceChannel voiceChannel, ITextChannel textChannel = null)
        {
            if (Players.TryGetValue(voiceChannel.GuildId, out var player))
            {
                return(player);
            }

            await voiceChannel.ConnectAsync(Configuration.SelfDeaf, false, true).ConfigureAwait(false);

            player = new LavaPlayer(voiceChannel, textChannel, _socketHelper);
            Players.TryAdd(voiceChannel.GuildId, player);

            player.OnTrackChanged += (track) =>
            {
                return(OnTrackChanged?.Invoke(player, track));
            };

            return(player);
        }