delete playlist added @DragonOverlord xD closes #322

This commit is contained in:
Master Kwoth 2016-06-27 00:00:35 +02:00
parent 9bcce1f2d8
commit 21dc657779
2 changed files with 32 additions and 0 deletions

View File

@ -33,6 +33,14 @@ namespace NadekoBot.Classes
conn.CreateTable<PlaylistSongInfo>(); conn.CreateTable<PlaylistSongInfo>();
conn.CreateTable<MusicPlaylist>(); conn.CreateTable<MusicPlaylist>();
conn.Execute(Queries.TransactionTriggerQuery); 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); NEW.DateAdded);
END 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";
} }

View File

@ -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} ---```"); 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<MusicPlaylist>(plnum);
else
DbHandler.Instance.DeleteWhere<MusicPlaylist>(mp => mp.Id == plnum && (long)e.User.Id == mp.CreatorId);
await e.Channel.SendMessage("`Ok.` :ok:");
});
cgb.CreateCommand("goto") cgb.CreateCommand("goto")
.Description("Goes to a specific time in seconds in a song.") .Description("Goes to a specific time in seconds in a song.")
.Parameter("time") .Parameter("time")