Пример #1
0
        public async Task <string> PlayAsync(int query, IVoiceChannel voiceChannel, ITextChannel textChannel, ulong guildId)
        {
            await lavaSocketClient.ConnectAsync(voiceChannel, textChannel);

            if (player == null)
            {
                player = lavaSocketClient.GetPlayer(guildId);
            }

            if (query >= 0 && query < 9)
            {
                var track = searchedTracks[query];
                if (player.IsPlaying)
                {
                    player.Queue.Enqueue(track);
                    isSearching = false;
                    return($"{track.Title} has been queued.");
                }
                else
                {
                    await player.PlayAsync(track);

                    isSearching = false;
                    return($"Now Playing: {track.Title}");
                }
            }
            else
            {
                return("Please choose a number between 0 and 8");
            }
        }
Пример #2
0
        public async Task <LavaPlayer> ConnectAsync(IVoiceChannel voiceChannel, ITextChannel textChannel = null)
        {
            LavaPlayer player = await _lavaSocket.ConnectAsync(voiceChannel, textChannel);

            uint volumeShouldBe = _databaseHandler.Get <GuildEntity>(voiceChannel.GuildId).LastPlayerVolume;

            if (volumeShouldBe != player.CurrentVolume)
            {
                await player.SetVolumeAsync((int)volumeShouldBe);
            }
            player.OnTrackChanged += (_) =>
            {
                return(_audioInfoHandler.RefreshTrack(player));
            };
            player.OnVolumeChanged += (_) =>
            {
                return(_audioInfoHandler.RefreshVolume(player));
            };
            player.OnStatusChanged += (_) =>
            {
                return(_audioInfoHandler.RefreshStatus(player));
            };
            player.OnQueueChanged += () =>
            {
                return(_audioInfoHandler.RefreshQueue(player));
            };
            return(player);
        }
Пример #3
0
        public async Task ConnectAsync(SocketVoiceChannel voiceChannel, ITextChannel channel)
        {
            if (voiceChannel == null)
            {
                return;
            }
            else
            {
                await _lavaSocketClient.ConnectAsync(voiceChannel, channel);

                return;
            }
        }
Пример #4
0
        public async Task <int> Queue(IPlayable song)
        {
            _queue.Enqueue(song);

            if (IsPlaying)
            {
                return(_queue.Count);
            }

            _player = await _lavaClient.ConnectAsync(song.Requester.VoiceChannel);
            await PlayNextTrack();

            await _player.SetVolumeAsync(50);

            return(0);
        }
Пример #5
0
        public async Task <(bool, string)> PlayAsync(SocketVoiceChannel voiceChannel, ITextChannel textChannel, string query, ulong guildId, string prefix, int pos = -1)
        {
            var player = _lavaSocketClient.GetPlayer(guildId);

            if (player is null)
            {
                await _lavaSocketClient.ConnectAsync(voiceChannel, textChannel);

                player = _lavaSocketClient.GetPlayer(guildId);
            }
            LavaTrack    track     = null;
            SearchResult results   = null;
            var          uriResult = GetUriResult(query);

            switch (uriResult)
            {
            case UriResult.PlayList:
                results = await _lavaRestClient.SearchTracksAsync(query, true);

                return(false, await MakePlayList(player, results));

            case UriResult.YoutubeLink:
                results = await _lavaRestClient.SearchYouTubeAsync(query);

                track = results.Tracks.FirstOrDefault();
                break;

            case UriResult.SoundCloud:
                results = await _lavaRestClient.SearchSoundcloudAsync(query);

                track = results.Tracks.FirstOrDefault();
                break;

            default:
                results = await _lavaRestClient.SearchYouTubeAsync(query);

                break;
            }
            if (results.LoadType == LoadType.NoMatches || results.LoadType == LoadType.LoadFailed)
            {
                return(false, "No matches found.");
            }

            var tracks = results.Tracks.ToArray();

            if (pos == -1 && track == null)
            {
                return(true, MakeTrackList(prefix, tracks));
            }

            if (track == null)
            {
                track = tracks[pos];
            }

            if (player.IsPlaying)
            {
                player.Queue.Enqueue(track);
                return(false, $"{track.Title} has been added to the queue.");
            }
            await player.PlayAsync(track);

            return(false, $"Now Playing: **{track.Title}**");
        }
Пример #6
0
 public async Task ConnectAsync(SocketVoiceChannel voiceChannel, ITextChannel textChannel) =>
 await lavaSocketClient.ConnectAsync(voiceChannel, textChannel);