From 21dc657779fb7f9070c0691ddf72dc2841001ba7 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Mon, 27 Jun 2016 00:00:35 +0200 Subject: [PATCH] delete playlist added @DragonOverlord xD closes #322 --- NadekoBot/Classes/DBHandler.cs | 15 +++++++++++++++ NadekoBot/Modules/Music/MusicModule.cs | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/NadekoBot/Classes/DBHandler.cs b/NadekoBot/Classes/DBHandler.cs index b87dce4f..96f7d8dd 100644 --- a/NadekoBot/Classes/DBHandler.cs +++ b/NadekoBot/Classes/DBHandler.cs @@ -33,6 +33,14 @@ namespace NadekoBot.Classes conn.CreateTable(); conn.CreateTable(); conn.Execute(Queries.TransactionTriggerQuery); + try + { + conn.Execute(Queries.DeletePlaylistTriggerQuery); + } + catch (Exception ex) + { + Console.WriteLine(ex); + } } } @@ -208,4 +216,11 @@ INSERT OR REPLACE INTO CurrencyState (Id, UserId, Value, DateAdded) NEW.DateAdded); END "; + public static string DeletePlaylistTriggerQuery = @" +CREATE TRIGGER music_playlist +AFTER DELETE ON MusicPlaylist +FOR EACH ROW +BEGIN + DELETE FROM PlaylistSongInfo WHERE PlaylistId = OLD.Id; +END"; } diff --git a/NadekoBot/Modules/Music/MusicModule.cs b/NadekoBot/Modules/Music/MusicModule.cs index f8a78ad0..ebd700f0 100644 --- a/NadekoBot/Modules/Music/MusicModule.cs +++ b/NadekoBot/Modules/Music/MusicModule.cs @@ -610,6 +610,23 @@ namespace NadekoBot.Modules.Music e.Channel.SendMessage($"```js\n--- List of saved playlists ---\n\n" + string.Join("\n", result.Select(r => $"'{r.Name}-{r.Id}' by {r.Creator} ({r.SongCnt} songs)")) + $"\n\n --- Page {num} ---```"); }); + cgb.CreateCommand("deleteplaylist") + .Alias("delpls") + .Description("Deletes a saved playlist. Only if you made it or if you are the bot owner. | `!m delpls animu-5`") + .Parameter("pl", ParameterType.Required) + .Do(async e => + { + var pl = e.GetArg("pl").Trim().Split('-')[1]; + if (string.IsNullOrWhiteSpace(pl)) + return; + var plnum = int.Parse(pl); + if (NadekoBot.IsOwner(e.User.Id)) + DbHandler.Instance.Delete(plnum); + else + DbHandler.Instance.DeleteWhere(mp => mp.Id == plnum && (long)e.User.Id == mp.CreatorId); + await e.Channel.SendMessage("`Ok.` :ok:"); + }); + cgb.CreateCommand("goto") .Description("Goes to a specific time in seconds in a song.") .Parameter("time")