Beispiel #1
0
        public async Task <Embed> PlayAsync(string query, ulong guildId)
        {
            var player  = _lavaSocketClient.GetPlayer(guildId);
            var results = await _lavaRestClient.SearchYouTubeAsync(query);

            var embed = new EmbedBuilder();

            if (results.LoadType == LoadType.NoMatches || results.LoadType == LoadType.LoadFailed)
            {
                embed.WithDescription("No songs matched your search query!");
                return(embed.Build());
            }

            var track = results.Tracks.FirstOrDefault();

            if (player.IsPlaying)
            {
                player.Queue.Enqueue(track);
                embed.WithDescription($"[{track.Title}]({track.Uri}) has been added to the queue!");
                return(embed.Build());
            }
            else
            {
                await player.PlayAsync(track);

                embed.WithDescription($"Now playing: [{track.Title}]({track.Uri})");
                return(embed.Build());
            }
        }
Beispiel #2
0
        public async Task <string> PlayAsync(string query, ulong guildId)
        {
            Player = lavaSocketClient.GetPlayer(guildId);
            SearchResult results = await lavaRestClient.SearchYouTubeAsync(query);

            if (results.LoadType == LoadType.NoMatches || results.LoadType == LoadType.LoadFailed)
            {
                return("No matches found.");
            }
            LavaTrack track = results.Tracks.FirstOrDefault();

            if (track is null)
            {
                return("The possibility of you seeing this is less than 0% but Jetbrains won't shut up about it.");
            }

            if (Player.IsPlaying)
            {
                Player.Queue.Enqueue(track);
                return($"{track.Title} has been added to the queue.");
            }

            await Player.PlayAsync(track);

            return($"Now player: {track.Title}");
        }
Beispiel #3
0
        public async Task <LavaTrack> GetTrack(string url, bool prioritiseSoundcloud = false)
        {
            try
            {
                LavaTrack track = null;

                if (Uri.TryCreate(url, UriKind.Absolute, out Uri uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps))
                {
                    track = (await LavaRestClient.SearchTracksAsync(url)).Tracks.FirstOrDefault();
                }
                else
                {
                    if (prioritiseSoundcloud)
                    {
                        track = (await LavaRestClient.SearchSoundcloudAsync(url)).Tracks.FirstOrDefault();
                    }
                    else
                    {
                        track = (await LavaRestClient.SearchYouTubeAsync(url)).Tracks.FirstOrDefault();
                    }
                }

                return(track);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #4
0
        public async Task <Embed> JoinOrPlayAsync(SocketGuildUser user, IMessageChannel textChannel, ulong guildId, string query = null)
        {
            if (user.VoiceChannel == null)
            {
                return(await EmbedHandler.CreateErrorEmbed("Music Join/Play", "You must first join a voice channel!"));
            }

            if (Options.TryGetValue(user.Guild.Id, out var options) && options.Summoner.Id != user.Id)
            {
                return(await EmbedHandler.CreateErrorEmbed("Music, Join/Play", $"I can't join another voice channel until {options.Summoner} disconnects me."));
            }
            try
            {
                _lavaPlayer = _lavaShardClient.GetPlayer(guildId);
                if (_lavaPlayer == null)
                {
                    await _lavaShardClient.ConnectAsync(user.VoiceChannel);

                    Options.TryAdd(user.Guild.Id, new AudioOptions
                    {
                        Summoner = user
                    });
                    _lavaPlayer = _lavaShardClient.GetPlayer(guildId);
                }

                LavaTrack track;
                var       search = await _lavaRestClient.SearchYouTubeAsync(query);

                if (search.LoadType == LoadType.NoMatches && query != null)
                {
                    return(await EmbedHandler.CreateErrorEmbed("Music", $"I wasn't able to find anything for {query}."));
                }
                if (search.LoadType == LoadType.LoadFailed && query != null)
                {
                    return(await EmbedHandler.CreateErrorEmbed("Music", $"I failed to load {query}."));
                }

                track = search.Tracks.FirstOrDefault();

                if (_lavaPlayer.CurrentTrack != null && _lavaPlayer.IsPlaying || _lavaPlayer.IsPaused)
                {
                    _lavaPlayer.Queue.Enqueue(track);
                    return(await EmbedHandler.CreateBasicEmbed("Music", $"{track.Title} has been added to queue."));
                }
                await _lavaPlayer.PlayAsync(track);

                return(await EmbedHandler.CreateMusicEmbed("Music", $"Now Playing: {track.Title}\nUrl: {track.Uri}"));
            }
            catch (Exception e)
            {
                return(await EmbedHandler.CreateErrorEmbed("Music, Join/Play", e.Message));
            }
        }
Beispiel #5
0
        public async Task <string> SearchAsync(string query)
        {
            searchedTracks = new List <LavaTrack>();
            var search = await lavaRestClient.SearchYouTubeAsync(query);

            if (search.LoadType == LoadType.NoMatches ||
                search.LoadType == LoadType.LoadFailed)
            {
                return("Nothing found");
            }

            var tracks = search.Tracks.Take(9).ToList();

            searchedTracks.AddRange(tracks);
            string tracksToChoose = String.Empty;

            for (int i = 0; i < tracks.Count(); ++i)
            {
                tracksToChoose += "`" + i + "`" + "\t" + tracks[i].Title.Replace("`", "\\`") + " by " + tracks[i].Author.Replace("`", "``") + "\t " + tracks[i].Length + "\n";
            }

            isSearching = true;
            return(tracksToChoose);
        }
        public async Task <string> PlayAsync(string query, ulong guildId)
        {
            var _player = _lavaSocketClient.GetPlayer(guildId);
            var results = await _lavaRestClient.SearchYouTubeAsync(query);

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

            var track = results.Tracks.FirstOrDefault();

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

                return($"Now Playing: {track.Title}");
            }
        }
Beispiel #7
0
        public async Task <Embed> PlayAsync(string query, ulong guildId)
        {
            _player = _lavaSocketClient.GetPlayer(guildId);
            var results = await _lavaRestClient.SearchYouTubeAsync(query);

            if (results.LoadType == LoadType.NoMatches || results.LoadType == LoadType.LoadFailed)
            {
                return(await EmbedHandler.CreateBasicEmbed("No Results", "Your search returned no results.", Color.Blue));
            }

            var track = results.Tracks.FirstOrDefault();

            if (_player.IsPlaying)
            {
                _player.Queue.Enqueue(track);
                return(await EmbedHandler.CreateMusicQueueEmbed(":arrow_right: " + track.Title + " added to queue", track.Uri.ToString()));
            }
            else
            {
                await _player.PlayAsync(track);

                return(await EmbedHandler.CreateMusicEmbed(":musical_note: Now playing " + track.Title + " :musical_note:", track.Uri.ToString()));
            }
        }
Beispiel #8
0
        public async Task <string> PlayAsync(string query, ulong guildId)
        {
            _player = _lavaSocketClient.GetPlayer(guildId);
            var results = await _lavaRestClient.SearchYouTubeAsync(query);

            if (results.LoadType == LoadType.NoMatches || results.LoadType == LoadType.LoadFailed)
            {
                return("⚠️ No se han encontrado resultados.");
            }

            var track = results.Tracks.FirstOrDefault();

            if (_player.IsPlaying)
            {
                _player.Queue.Enqueue(track);
                return($"🔔 {track.Title} se agregó a la cola.");
            }
            else
            {
                await _player.PlayAsync(track);

                return($"🔔 Ahora está sonando: {track.Title}");
            }
        }
Beispiel #9
0
 public async Task <SearchResult> GetTracks(string query)
 {
     return(await _lavaRestClient.SearchYouTubeAsync(query));
 }
Beispiel #10
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}**");
        }
Beispiel #11
0
        public async Task PlayAsync([Remainder] string query)
        {
            var regExp = new Regex(@"youtu(.*)(be|com).*(list=([a-zA-Z0-9_\-]+))");
            var match  = regExp.Match(query);

            Victoria.Entities.SearchResult search;
            if (match.Success)
            {
                search = await RestClient.SearchTracksAsync(query, false);
            }
            else
            {
                search = await RestClient.SearchYouTubeAsync(query);
            }

            if (search.LoadType == LoadType.NoMatches ||
                search.LoadType == LoadType.LoadFailed)
            {
                await ReplyAsync("Nothing found");

                return;
            }

            //If there is no player, join the current channel and set the player
            if (player == null)
            {
                await Join();

                player = LavaShardClient.GetPlayer(Context.Guild.Id);
            }

            var track = search.Tracks.FirstOrDefault();

            if (player.IsPlaying)
            {
                if (search.LoadType == LoadType.PlaylistLoaded)
                {
                    foreach (var playlistTrack in search.Tracks)
                    {
                        player.Queue.Enqueue(playlistTrack);
                    }
                    await ReplyAsync($"{search.Tracks.Count()} tracks added from playlist: {search.PlaylistInfo.Name}");
                }
                else
                {
                    player.Queue.Enqueue(track);
                    await ReplyAsync($"{track.Title} has been queued.");
                }
            }
            else
            {
                await player.PlayAsync(track);
                await ReplyAsync($"Now Playing: {track.Title}");

                if (search.LoadType == LoadType.PlaylistLoaded)
                {
                    foreach (var playlistTrack in search.Tracks.Where(x => x.Id != track.Id))
                    {
                        player.Queue.Enqueue(playlistTrack);
                    }
                    await ReplyAsync($"{search.Tracks.Count()} tracks added from playlist: {search.PlaylistInfo.Name}");
                }
            }
        }