diff --git a/.gitignore b/.gitignore index a8e78718..df5ec176 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ Tests/bin src/NadekoBot/credentials.json src/NadekoBot/project.lock.json src/NadekoBot/data/NadekoBot.db -src/NadekoBot/musicdata/* +src/NadekoBot/musicdata src/NadekoBot/project.lock.json # NuGet Packages diff --git a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs index 949720d0..de39d0e6 100644 --- a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs +++ b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs @@ -363,6 +363,8 @@ namespace NadekoBot.Migrations b.Property("Author"); + b.Property("AuthorId"); + b.Property("Name"); b.HasKey("Id"); diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 21e8e26f..ec7e7373 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -547,6 +547,7 @@ namespace NadekoBot.Modules.Music { Name = name, Author = umsg.Author.Username, + AuthorId = umsg.Author.Id, Songs = songs, }; uow.MusicPlaylists.Add(playlist); @@ -610,13 +611,35 @@ namespace NadekoBot.Modules.Music } //todo only author or owner - //[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] - //[RequireContext(ContextType.Guild)] - //public async Task DeletePlaylist(IUserMessage umsg, [Remainder] string pl) - //{ - // var channel = (ITextChannel)umsg.Channel; + [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] + [RequireContext(ContextType.Guild)] + public async Task DeletePlaylist(IUserMessage umsg, [Remainder] int id) + { + var channel = (ITextChannel)umsg.Channel; - //} + bool success = false; + MusicPlaylist pl = null; + using (var uow = DbHandler.UnitOfWork()) + { + pl = uow.MusicPlaylists.Get(id); + + if (pl != null) + { + if (NadekoBot.Credentials.IsOwner(umsg.Author) || pl.AuthorId == umsg.Author.Id) + { + uow.MusicPlaylists.Remove(pl.Id); + await uow.CompleteAsync().ConfigureAwait(false); + } + else + success = false; + } + } + + if (success) + await channel.SendMessageAsync("Failed to delete that playlist. It either doesn't exist, or you are not its author.").ConfigureAwait(false); + else + await channel.SendMessageAsync("`Playlist successfully deleted.`").ConfigureAwait(false); + } [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] [RequireContext(ContextType.Guild)]