playlist saving done
This commit is contained in:
parent
df32d2cf13
commit
4e2820080b
@ -29,6 +29,9 @@ namespace NadekoBot.Classes
|
|||||||
conn.CreateTable<UserPokeTypes>();
|
conn.CreateTable<UserPokeTypes>();
|
||||||
conn.CreateTable<UserQuote>();
|
conn.CreateTable<UserQuote>();
|
||||||
conn.CreateTable<Reminder>();
|
conn.CreateTable<Reminder>();
|
||||||
|
conn.CreateTable<SongInfo>();
|
||||||
|
conn.CreateTable<PlaylistSongInfo>();
|
||||||
|
conn.CreateTable<MusicPlaylist>();
|
||||||
conn.Execute(Queries.TransactionTriggerQuery);
|
conn.Execute(Queries.TransactionTriggerQuery);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,6 +128,23 @@ namespace NadekoBot.Classes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates an existing object or creates a new one
|
||||||
|
/// </summary>
|
||||||
|
internal void SaveAll<T>(IEnumerable<T> ocol) where T : IDataModel, new()
|
||||||
|
{
|
||||||
|
using (var conn = new SQLiteConnection(FilePath))
|
||||||
|
{
|
||||||
|
conn.RunInTransaction(() =>
|
||||||
|
{
|
||||||
|
foreach (var o in ocol)
|
||||||
|
{
|
||||||
|
conn.InsertOrReplace(o, typeof(T));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal T GetRandom<T>(Expression<Func<T, bool>> p) where T : IDataModel, new()
|
internal T GetRandom<T>(Expression<Func<T, bool>> p) where T : IDataModel, new()
|
||||||
{
|
{
|
||||||
using (var conn = new SQLiteConnection(FilePath))
|
using (var conn = new SQLiteConnection(FilePath))
|
||||||
|
@ -125,6 +125,8 @@ namespace NadekoBot.Classes.Music
|
|||||||
{
|
{
|
||||||
playlist.Clear();
|
playlist.Clear();
|
||||||
CurrentSong = null;
|
CurrentSong = null;
|
||||||
|
RepeatPlaylist = false;
|
||||||
|
RepeatSong = false;
|
||||||
if (!SongCancelSource.IsCancellationRequested)
|
if (!SongCancelSource.IsCancellationRequested)
|
||||||
SongCancelSource.Cancel();
|
SongCancelSource.Cancel();
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,9 @@
|
|||||||
using SQLite;
|
namespace NadekoBot.Classes._DataModels
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace NadekoBot.Classes._DataModels
|
|
||||||
{
|
{
|
||||||
internal class MusicPlaylist : IDataModel
|
internal class MusicPlaylist : IDataModel
|
||||||
{
|
{
|
||||||
[Unique]
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public long CreatorId { get; set; }
|
public long CreatorId { get; set; }
|
||||||
public string CreatorName { get; set; }
|
public string CreatorName { get; set; }
|
||||||
public List<SongInfo> Songs { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[System.Serializable]
|
|
||||||
internal class SongInfo
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
public string Link { get; set; }
|
|
||||||
public SongType Type { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal enum SongType
|
|
||||||
{
|
|
||||||
Local,
|
|
||||||
Radio,
|
|
||||||
Query
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
NadekoBot/Classes/_DataModels/PlaylistSongInfo.cs
Normal file
8
NadekoBot/Classes/_DataModels/PlaylistSongInfo.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace NadekoBot.Classes._DataModels
|
||||||
|
{
|
||||||
|
internal class PlaylistSongInfo : IDataModel
|
||||||
|
{
|
||||||
|
public int PlaylistId { get; set; }
|
||||||
|
public int SongInfoId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
13
NadekoBot/Classes/_DataModels/SongInfo.cs
Normal file
13
NadekoBot/Classes/_DataModels/SongInfo.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using SQLite;
|
||||||
|
|
||||||
|
namespace NadekoBot.Classes._DataModels
|
||||||
|
{
|
||||||
|
internal class SongInfo : IDataModel
|
||||||
|
{
|
||||||
|
public string Provider { get; internal set; }
|
||||||
|
public int ProviderType { get; internal set; }
|
||||||
|
public string Title { get; internal set; }
|
||||||
|
[Unique]
|
||||||
|
public string Uri { get; internal set; }
|
||||||
|
}
|
||||||
|
}
|
@ -418,9 +418,61 @@ namespace NadekoBot.Modules
|
|||||||
await e.Channel.SendMessage($"🎵🔁`Repeat playlist {(currentValue ? "enabled" : "disabled")}`");
|
await e.Channel.SendMessage($"🎵🔁`Repeat playlist {(currentValue ? "enabled" : "disabled")}`");
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("pls")
|
cgb.CreateCommand("save")
|
||||||
.Alias("playlistsave")
|
.Description("Saves a playlist under a certain name. Name must be no longer than 20 characters and mustn't contain dashes.\n**Usage**: `!m save classical1`")
|
||||||
.Description("Saves a playlist under a certain name. Name must be no longer than 20 characters and mustn't contain dashes.\n**Usage**: `!m pls classical1`")
|
.Parameter("name", ParameterType.Unparsed)
|
||||||
|
.Do(async e =>
|
||||||
|
{
|
||||||
|
var name = e.GetArg("name")?.Trim();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(name) ||
|
||||||
|
name.Length > 20 ||
|
||||||
|
name.Contains("-"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
MusicPlayer musicPlayer;
|
||||||
|
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer))
|
||||||
|
return;
|
||||||
|
|
||||||
|
//to avoid concurrency issues
|
||||||
|
var currentPlaylist = new List<Song>(musicPlayer.Playlist);
|
||||||
|
var curSong = musicPlayer.CurrentSong;
|
||||||
|
if (curSong != null)
|
||||||
|
currentPlaylist.Insert(0, curSong);
|
||||||
|
|
||||||
|
if (!currentPlaylist.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
var songInfos = currentPlaylist.Select(s => new Classes._DataModels.SongInfo
|
||||||
|
{
|
||||||
|
Provider = s.SongInfo.Provider,
|
||||||
|
ProviderType = (int)s.SongInfo.ProviderType,
|
||||||
|
Title = s.SongInfo.Title,
|
||||||
|
Uri = s.SongInfo.Uri
|
||||||
|
});
|
||||||
|
|
||||||
|
var playlist = new Classes._DataModels.MusicPlaylist
|
||||||
|
{
|
||||||
|
CreatorId = (long)e.User.Id,
|
||||||
|
CreatorName = e.User.Name,
|
||||||
|
Name = name,
|
||||||
|
};
|
||||||
|
|
||||||
|
DbHandler.Instance.SaveAll(songInfos);
|
||||||
|
DbHandler.Instance.Save(playlist);
|
||||||
|
DbHandler.Instance.InsertMany(songInfos.Select(s => new Classes._DataModels.PlaylistSongInfo
|
||||||
|
{
|
||||||
|
PlaylistId = playlist.Id,
|
||||||
|
SongInfoId = s.Id
|
||||||
|
}));
|
||||||
|
|
||||||
|
await e.Channel.SendMessage($"🎵 `Saved playlist as {name}-{playlist.Id}`");
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
cgb.CreateCommand("load")
|
||||||
|
.Description("Loads a playlist under a certain name. Name must be no longer than 20 characters and mustn't contain dashes.\n**Usage**: `!m load classical1`")
|
||||||
.Parameter("name", ParameterType.Unparsed)
|
.Parameter("name", ParameterType.Unparsed)
|
||||||
.Do(async e =>
|
.Do(async e =>
|
||||||
{
|
{
|
||||||
@ -442,7 +494,10 @@ namespace NadekoBot.Modules
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//cgb.CreateCommand("debug")
|
//cgb.CreateCommand("debug")
|
||||||
// .Description("Does something magical. **BOT OWNER ONLY**")
|
// .Description("Does something magical. **BOT OWNER ONLY**")
|
||||||
// .AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
|
// .AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
|
||||||
|
@ -152,9 +152,11 @@
|
|||||||
<Compile Include="Classes\_DataModels\Donator.cs" />
|
<Compile Include="Classes\_DataModels\Donator.cs" />
|
||||||
<Compile Include="Classes\_DataModels\IDataModel.cs" />
|
<Compile Include="Classes\_DataModels\IDataModel.cs" />
|
||||||
<Compile Include="Classes\_DataModels\MusicPlaylist.cs" />
|
<Compile Include="Classes\_DataModels\MusicPlaylist.cs" />
|
||||||
|
<Compile Include="Classes\_DataModels\PlaylistSongInfo.cs" />
|
||||||
<Compile Include="Classes\_DataModels\PokeTypes.cs" />
|
<Compile Include="Classes\_DataModels\PokeTypes.cs" />
|
||||||
<Compile Include="Classes\_DataModels\Reminder.cs" />
|
<Compile Include="Classes\_DataModels\Reminder.cs" />
|
||||||
<Compile Include="Classes\_DataModels\RequestModel.cs" />
|
<Compile Include="Classes\_DataModels\RequestModel.cs" />
|
||||||
|
<Compile Include="Classes\_DataModels\SongInfo.cs" />
|
||||||
<Compile Include="Classes\_DataModels\StatsModel.cs" />
|
<Compile Include="Classes\_DataModels\StatsModel.cs" />
|
||||||
<Compile Include="Classes\_DataModels\TypingArticleModel.cs" />
|
<Compile Include="Classes\_DataModels\TypingArticleModel.cs" />
|
||||||
<Compile Include="Classes\_DataModels\UserQuoteModel.cs" />
|
<Compile Include="Classes\_DataModels\UserQuoteModel.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user