Deleting playlist implemented, needs testing

This commit is contained in:
Kwoth 2016-10-01 19:35:11 +02:00
parent 80e749a1a1
commit 31cd9b2856
3 changed files with 32 additions and 7 deletions

2
.gitignore vendored
View File

@ -17,7 +17,7 @@ Tests/bin
src/NadekoBot/credentials.json src/NadekoBot/credentials.json
src/NadekoBot/project.lock.json src/NadekoBot/project.lock.json
src/NadekoBot/data/NadekoBot.db src/NadekoBot/data/NadekoBot.db
src/NadekoBot/musicdata/* src/NadekoBot/musicdata
src/NadekoBot/project.lock.json src/NadekoBot/project.lock.json
# NuGet Packages # NuGet Packages

View File

@ -363,6 +363,8 @@ namespace NadekoBot.Migrations
b.Property<string>("Author"); b.Property<string>("Author");
b.Property<ulong>("AuthorId");
b.Property<string>("Name"); b.Property<string>("Name");
b.HasKey("Id"); b.HasKey("Id");

View File

@ -547,6 +547,7 @@ namespace NadekoBot.Modules.Music
{ {
Name = name, Name = name,
Author = umsg.Author.Username, Author = umsg.Author.Username,
AuthorId = umsg.Author.Id,
Songs = songs, Songs = songs,
}; };
uow.MusicPlaylists.Add(playlist); uow.MusicPlaylists.Add(playlist);
@ -610,13 +611,35 @@ namespace NadekoBot.Modules.Music
} }
//todo only author or owner //todo only author or owner
//[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
//[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
//public async Task DeletePlaylist(IUserMessage umsg, [Remainder] string pl) public async Task DeletePlaylist(IUserMessage umsg, [Remainder] int id)
//{ {
// var channel = (ITextChannel)umsg.Channel; 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] [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]