예제 #1
0
        public async Task ImportAsync(CommandContext ctx, [RemainingText, Description("Playlist name to load")] string playlistName)
        {
            // If the user inputs no playlist name in discord
            if (playlistName == null)
            {
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":no_entry:")} Please specify the playlist name you want to load!");

                return;
            }

            IEnumerable <String> trackStrings = await PasteBin.loadTracksAsync(playlistName);

            // Check if there is actually a match in playlist name
            if (trackStrings != null)
            {
                int trackCount = trackStrings.Count();

                try
                {
                    IEnumerable <LavalinkTrack> tracks = await Lavalink.lavaRest.DecodeTracksAsync(trackStrings.ToArray());

                    foreach (var track in tracks)
                    {
                        MusicData.QueueTrack(new TrackItem(track, ctx.Member));
                    }

                    await this.MusicData.CreatePlayerAsync(ctx.Member.VoiceState.Channel).ConfigureAwait(false);

                    var trackNowPlaying = MusicData.NowPlaying;

                    await MusicData.Play();

                    await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":musical_note:")} Loaded playlist {Formatter.Bold(playlistName)} with {Formatter.Bold(trackCount.ToString())} tracks");

                    // Player wasn't playing anything at the time of loading the playlist
                    if (trackNowPlaying.Track == null || trackNowPlaying.Track.TrackString == null)
                    {
                        await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":musical_note:")} Now playing: {Formatter.Bold($"{tracks.First().Title}")} by {Formatter.Bold($"{tracks.First().Author}")} - ({Time_Convert.CompressLavalinkTime(tracks.First().Length)})").ConfigureAwait(false);
                    }

                    return;
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine($"Exception {e} when decoding tracks");
                    await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":no_entry:")} There was an error loading the playlist");
                }
            }
            await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":no_entry:")} Playlist name {Formatter.Bold(playlistName)} does not exist!");
        }
예제 #2
0
        public async Task NowPlayingAsync(CommandContext ctx)
        {
            var track = MusicData.NowPlaying;

            if (MusicData.NowPlaying.Track == null || MusicData.NowPlaying.Track.TrackString == null)
            {
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":no_entry:")} I'm not playing anything right now!").ConfigureAwait(false);
            }
            else
            {
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":musical_note:")} Now playing: {Formatter.Bold($"{track.Track.Title}")} by {Formatter.Bold($"{track.Track.Author}")} - ({Time_Convert.CompressLavalinkTime(track.Track.Length)})").ConfigureAwait(false);
            }
        }
예제 #3
0
        public async Task PlayAsync(CommandContext ctx, [RemainingText, Description("Terms to search for")] string terms)
        {
            var interactivity = ctx.Client.GetInteractivity();

            var results = await this.Youtube.SearchAsync(terms).ConfigureAwait(false);

            if (!results.Any())
            {
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":cry:")} I couldn't find anything with those search keys");

                return;
            }

            var pollDuration = TimeSpan.FromSeconds(30);

            List <DiscordEmoji> listOfSelections = new List <DiscordEmoji>()
            {
                DiscordEmoji.FromName(ctx.Client, ":one:"), DiscordEmoji.FromName(ctx.Client, ":two:"), DiscordEmoji.FromName(ctx.Client, ":three:"), DiscordEmoji.FromName(ctx.Client, ":four:"), DiscordEmoji.FromName(ctx.Client, ":five:")
            };

            // present the poll
            var foo = string.Join("\n", results.Select((x, i) => $"Track {i + 1}: {Formatter.Bold(x.Title)} by {Formatter.Bold(x.Author)} - ({x.Duration})"));

            var searchResults = await ctx.RespondAsync($"Here is what I found:\n\n{foo}");

            // add the options as reactions and add a cancel button
            foreach (DiscordEmoji emoji in listOfSelections)
            {
                await searchResults.CreateReactionAsync(emoji);
            }

            var cancelEmoji = DiscordEmoji.FromName(ctx.Client, ":x:");
            await searchResults.CreateReactionAsync(cancelEmoji);

            // get reactions
            var poll_result = await interactivity.WaitForReactionAsync(xm => listOfSelections.Contains(xm.Emoji) || xm.Emoji == cancelEmoji, searchResults, ctx.User, pollDuration);

            if (poll_result.Result != null)
            {
                await searchResults.DeleteAsync();

                if (poll_result.Result.Emoji == cancelEmoji)
                {
                    await ctx.RespondAsync("Query Cancelled");

                    return;
                }
                int parseSelect = Int32.Parse(poll_result.Result.Emoji.Name.Substring(0, 1)) - 1;
                var url         = new Uri($"https://www.youtube.com/watch?v={results.ElementAt(parseSelect).Id}");

                var getTracks = await this.Lavalink.lavaRest.GetTracksAsync(url).ConfigureAwait(false);

                var tracks = getTracks.Tracks;

                if (getTracks.LoadResultType == LavalinkLoadResultType.LoadFailed || !tracks.Any())
                {
                    await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":cry:")} I couldn't find any tracks with that url").ConfigureAwait(false);

                    return;
                }
                foreach (var trackElement in tracks)
                {
                    MusicData.QueueTrack(new TrackItem(trackElement, ctx.Member));
                }

                await this.MusicData.CreatePlayerAsync(ctx.Member.VoiceState.Channel).ConfigureAwait(false);

                await MusicData.Play();

                var track = tracks.First();
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":musical_note:")} Added {Formatter.Bold(track.Title)} by {Formatter.Bold(track.Author)} - ({Time_Convert.CompressLavalinkTime(track.Length)})");
            }
            else
            {
                await searchResults.DeleteAsync();

                await ctx.RespondAsync("Request Timed Out.");
            }
        }
예제 #4
0
        public async Task SeeQueueAsync(CommandContext ctx)
        {
            var queueString   = String.Empty;
            var num           = 1;
            var interactivity = ctx.Client.GetInteractivity();

            if (MusicData.RepeatMode == "single")
            {
                var repeatingTrack = MusicData.NowPlaying;
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":musical_note:")} Queue currently is repeating {Formatter.Bold($"{repeatingTrack.Track.Title}")} by {Formatter.Bold($"{repeatingTrack.Track.Author}")}").ConfigureAwait(false);

                return;
            }

            if (MusicData.PublicQueue.Count == 0)
            {
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":no_entry:")} Queue is currently empty!");

                return;
            }

            try
            {
                foreach (var track in MusicData.PublicQueue)
                {
                    queueString += $"{num}. {Formatter.Bold($"{track.Track.Title}")} by {Formatter.Bold($"{track.Track.Author}")} - ({Time_Convert.CompressLavalinkTime(track.Track.Length)})\n";
                    num++;
                }
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":musical_note:")} Here is the list of currently queued tracks: \n");

                var queuePages = interactivity.GeneratePagesInEmbed(queueString, SplitType.Line);

                await interactivity.SendPaginatedMessageAsync(ctx.Channel, ctx.User, queuePages, null, PaginationBehaviour.WrapAround);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.InnerException);
            }
        }
예제 #5
0
        public async Task PlayAsync(CommandContext ctx, [Description("The url to play from")] Uri url) //There's no error handling on this yet
        {
            var getTracks = await Lavalink.lavaRest.GetTracksAsync(url).ConfigureAwait(false);

            var tracks = getTracks.Tracks;

            if (getTracks.LoadResultType == LavalinkLoadResultType.LoadFailed || !tracks.Any())
            {
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":cry:")} I couldn't find any tracks with that url").ConfigureAwait(false);

                return;
            }
            foreach (var trackElement in tracks)
            {
                MusicData.QueueTrack(new TrackItem(trackElement, ctx.Member));
            }

            await this.MusicData.CreatePlayerAsync(ctx.Member.VoiceState.Channel).ConfigureAwait(false);

            await MusicData.Play();

            var track = tracks.First();
            await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":musical_note:")} Added {Formatter.Bold(track.Title)} by {Formatter.Bold(track.Author)} - ({Time_Convert.CompressLavalinkTime(track.Length)})");

            // Acknowledge that we loaded a playlist
            if (getTracks.LoadResultType == LavalinkLoadResultType.PlaylistLoaded)
            {
                await ctx.RespondAsync($"Plus an additional {Formatter.Bold((tracks.Count() - 1).ToString())} tracks from the playlist {Formatter.Bold(getTracks.PlaylistInfo.Name)}");
            }
            //await playHandler(ctx, url.ToString());
        }