Example #1
0
        public async Task DeletePlaylist(CommandContext ctx, [RemainingText, Description("Playlist name to delete")] string playlistName)
        {
            var interactive = ctx.Client.GetInteractivity();

            if (playlistName == null)
            {
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":no_entry:")} Please specify the playlist name you want to delete!");

                return;
            }

            if (await PasteBin.playlistExists(playlistName))
            {
                string         deleteConfirm = $"{DiscordEmoji.FromName(ctx.Client, ":warning:")} Are you sure you want to delete the playlist {Formatter.Bold(playlistName)}?";
                PlaylistResult deleteResult  = await MusicCommandHelpers.DeletePlaylistHelperAsync(ctx, deleteConfirm, playlistName, PasteBin);

                switch (deleteResult)
                {
                case PlaylistResult.Cancelled:
                    await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":warning:")} Deletion cancelled");

                    break;

                case PlaylistResult.Failed:
                    await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":no_entry:")} There was a problem deleting the playlist");

                    break;

                case PlaylistResult.Successful:
                    await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":musical_note:")} Deleted the playlist {Formatter.Bold(playlistName)}");

                    break;

                default:
                    await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":REEE:")} You done goofed");

                    break;
                }
            }
            else
            {
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":no_entry:")} Playlist {Formatter.Bold(playlistName)} doesn't exist!");
            }
        }
Example #2
0
        public async Task ExportAsync(CommandContext ctx, [RemainingText, Description("Name of the Playlist")] string playlistName)
        {
            var interactive = ctx.Client.GetInteractivity();

            List <string> trackQueue = new List <string>();

            //Check if queue is empty and there's nothing playing
            if (MusicData.PublicQueue.Count == 0 && MusicData.NowPlaying.Track == null)
            {
                await ctx.RespondAsync($"{ DiscordEmoji.FromName(ctx.Client, ":no_entry:")} There's nothing in the queue or playing right now to save!").ConfigureAwait(false);

                return;
            }

            if (String.IsNullOrWhiteSpace(playlistName))
            {
                await ctx.RespondAsync($"{ DiscordEmoji.FromName(ctx.Client, ":no_entry:")} Playlist name is empty!").ConfigureAwait(false);

                return;
            }

            // If there's a song playing currently add it to the queue
            if (MusicData.NowPlaying.Track != null || MusicData.NowPlaying.Track.TrackString != null)
            {
                trackQueue.Add(MusicData.NowPlaying.Track.TrackString);
            }

            // Add each song in the queue
            foreach (var track in MusicData.PublicQueue)
            {
                trackQueue.Add(track.Track.TrackString);
            }

            // Check if playlist name already exists
            if (await PasteBin.playlistExists(playlistName))
            {
                string         overwriteConfirm = $"{DiscordEmoji.FromName(ctx.Client, ":warning:")} There's already a playlist with the name {Formatter.Bold(playlistName)}. Would you like to overwrite it?";
                PlaylistResult deleteResult     = await MusicCommandHelpers.DeletePlaylistHelperAsync(ctx, overwriteConfirm, playlistName, PasteBin);

                switch (deleteResult)
                {
                case PlaylistResult.Cancelled:
                    await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":warning:")} Overwrite cancelled");

                    return;

                case PlaylistResult.Failed:
                    await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":no_entry:")} There was a problem deleting the playlist");

                    return;

                case PlaylistResult.Successful:
                    // Don't say anything if delete goes through - delete is just an intermediate step to overwriting
                    break;

                default:
                    await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":REEE:")} You done goofed");

                    return;
                }
            }

            // Save the playlist
            var saveResult = await PasteBin.saveTracksAsync(trackQueue, playlistName);

            if (saveResult == PlaylistResult.Successful)
            {
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":musical_note:")} Playlist {Formatter.Bold(playlistName)} saved!");
            }
            else
            {
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":no_entry:")} There was a problem saving the playlist {Formatter.Bold(playlistName)}.");
            }
        }