Playlist loading, saving and listing done
This commit is contained in:
parent
b7198ea0ed
commit
80e749a1a1
@ -356,6 +356,20 @@ namespace NadekoBot.Migrations
|
|||||||
b.ToTable("ModulePrefixes");
|
b.ToTable("ModulePrefixes");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.MusicPlaylist", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<string>("Author");
|
||||||
|
|
||||||
|
b.Property<string>("Name");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("MusicPlaylists");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -397,6 +411,30 @@ namespace NadekoBot.Migrations
|
|||||||
b.ToTable("PlayingStatus");
|
b.ToTable("PlayingStatus");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.PlaylistSong", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<int?>("MusicPlaylistId");
|
||||||
|
|
||||||
|
b.Property<string>("Provider");
|
||||||
|
|
||||||
|
b.Property<int>("ProviderType");
|
||||||
|
|
||||||
|
b.Property<string>("Query");
|
||||||
|
|
||||||
|
b.Property<string>("Title");
|
||||||
|
|
||||||
|
b.Property<string>("Uri");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MusicPlaylistId");
|
||||||
|
|
||||||
|
b.ToTable("PlaylistSong");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.Quote", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Quote", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -588,6 +626,13 @@ namespace NadekoBot.Migrations
|
|||||||
.HasForeignKey("BotConfigId");
|
.HasForeignKey("BotConfigId");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.PlaylistSong", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("NadekoBot.Services.Database.Models.MusicPlaylist")
|
||||||
|
.WithMany("Songs")
|
||||||
|
.HasForeignKey("MusicPlaylistId");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.RaceAnimal", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.RaceAnimal", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
|
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
|
||||||
|
@ -614,10 +614,11 @@ namespace NadekoBot.Modules.Administration
|
|||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
foreach (var ch in _client.GetGuilds().Select(async g => await g.GetDefaultChannelAsync().ConfigureAwait(false)))
|
var channels = await Task.WhenAll(_client.GetGuilds().Select(g =>
|
||||||
{
|
g.GetDefaultChannelAsync()
|
||||||
await channel.SendMessageAsync(message).ConfigureAwait(false);
|
)).ConfigureAwait(false);
|
||||||
}
|
|
||||||
|
await Task.WhenAll(channels.Select(c => c.SendMessageAsync($"`Message from {umsg.Author} (Bot Owner):` " + message)));
|
||||||
|
|
||||||
await channel.SendMessageAsync(":ok:").ConfigureAwait(false);
|
await channel.SendMessageAsync(":ok:").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,8 @@ Nadeko Support Server: https://discord.gg/0ehQwTK2RBjAxzEY";
|
|||||||
comToFind = comToFind?.ToLowerInvariant();
|
comToFind = comToFind?.ToLowerInvariant();
|
||||||
if (string.IsNullOrWhiteSpace(comToFind))
|
if (string.IsNullOrWhiteSpace(comToFind))
|
||||||
{
|
{
|
||||||
await (await (umsg.Author as IGuildUser).CreateDMChannelAsync()).SendMessageAsync(HelpString).ConfigureAwait(false);
|
IMessageChannel ch = channel is ITextChannel ? await ((IGuildUser)umsg.Author).CreateDMChannelAsync() : channel;
|
||||||
|
await ch.SendMessageAsync(HelpString).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var com = _commands.Commands.FirstOrDefault(c => c.Text.ToLowerInvariant() == comToFind || c.Aliases.Select(a=>a.ToLowerInvariant()).Contains(comToFind));
|
var com = _commands.Commands.FirstOrDefault(c => c.Text.ToLowerInvariant() == comToFind || c.Aliases.Select(a=>a.ToLowerInvariant()).Contains(comToFind));
|
||||||
|
@ -14,6 +14,7 @@ using System.Net.Http;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NadekoBot.Services.Database;
|
using NadekoBot.Services.Database;
|
||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Music
|
namespace NadekoBot.Modules.Music
|
||||||
{
|
{
|
||||||
@ -520,48 +521,95 @@ namespace NadekoBot.Modules.Music
|
|||||||
await channel.SendMessageAsync($"🎵🔁`Repeat playlist {(currentValue ? "enabled" : "disabled")}`").ConfigureAwait(false);
|
await channel.SendMessageAsync($"🎵🔁`Repeat playlist {(currentValue ? "enabled" : "disabled")}`").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Save(IUserMessage umsg, [Remainder] string name)
|
public async Task Save(IUserMessage umsg, [Remainder] string name)
|
||||||
//{
|
{
|
||||||
// var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
// MusicPlayer musicPlayer;
|
MusicPlayer musicPlayer;
|
||||||
// if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer))
|
if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer))
|
||||||
// return;
|
return;
|
||||||
|
|
||||||
// var curSong = musicPlayer.CurrentSong;
|
var curSong = musicPlayer.CurrentSong;
|
||||||
// var items = musicPlayer.Playlist.Append(curSong);
|
var songs = musicPlayer.Playlist.Append(curSong)
|
||||||
|
.Select(s=> new PlaylistSong() {
|
||||||
|
Provider = s.SongInfo.Provider,
|
||||||
|
ProviderType = s.SongInfo.ProviderType,
|
||||||
|
Title = s.SongInfo.Title,
|
||||||
|
Uri = s.SongInfo.Uri,
|
||||||
|
Query = s.SongInfo.Query,
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
// MusicPlaylist playlist;
|
MusicPlaylist playlist;
|
||||||
// using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
// {
|
{
|
||||||
// playlist = new MusicPlaylist
|
playlist = new MusicPlaylist
|
||||||
// {
|
{
|
||||||
// Name = name,
|
Name = name,
|
||||||
// Songs = items.ToList()
|
Author = umsg.Author.Username,
|
||||||
// };
|
Songs = songs,
|
||||||
// uow.MusicPlaylists.Add(playlist);
|
};
|
||||||
// }
|
uow.MusicPlaylists.Add(playlist);
|
||||||
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
// await channel.SendMessageAsync($"Playlist saved as {name}, id: {playlist.Id}.");
|
await channel.SendMessageAsync(($"🎵 `Saved playlist as {name}.` `Id: {playlist.Id}`")).ConfigureAwait(false);
|
||||||
//}
|
}
|
||||||
|
|
||||||
//[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Load(IUserMessage umsg, [Remainder] string name)
|
public async Task Load(IUserMessage umsg, [Remainder] int id)
|
||||||
//{
|
{
|
||||||
// var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
//}
|
MusicPlaylist mpl;
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
mpl = uow.MusicPlaylists.GetWithSongs(id);
|
||||||
|
}
|
||||||
|
|
||||||
//[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
if (mpl == null)
|
||||||
//[RequireContext(ContextType.Guild)]
|
{
|
||||||
//public async Task Playlists(IUserMessage umsg, [Remainder] string num)
|
await channel.SendMessageAsync("Can't find playlist with that ID").ConfigureAwait(false);
|
||||||
//{
|
return;
|
||||||
// var channel = (ITextChannel)umsg.Channel;
|
}
|
||||||
|
|
||||||
//}
|
var msg = await channel.SendMessageAsync($"`Attempting to load {mpl.Songs.Count} songs...`").ConfigureAwait(false);
|
||||||
|
foreach (var item in mpl.Songs)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var usr = (IGuildUser)umsg.Author;
|
||||||
|
await QueueSong(usr, channel, usr.VoiceChannel, item.Query, true, item.ProviderType).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch { break; }
|
||||||
|
}
|
||||||
|
|
||||||
|
await msg.ModifyAsync(m => m.Content = $"`Done loading playlist {mpl.Name}.`").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task Playlists(IUserMessage umsg, [Remainder] int num = 1)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
|
if (num <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
List<MusicPlaylist> playlists;
|
||||||
|
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num);
|
||||||
|
}
|
||||||
|
|
||||||
|
await channel.SendMessageAsync($@"`Page {num} of saved playlists`
|
||||||
|
|
||||||
|
" + string.Join("\n", playlists.Select(r => $"`#{r.Id}` - `{r.Name}` by {r.Author} - **{r.Songs.Count}** songs"))).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
//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] string pl)
|
||||||
|
@ -42,16 +42,20 @@ namespace NadekoBot
|
|||||||
|
|
||||||
_log.Info("Starting NadekoBot v" + typeof(NadekoBot).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion);
|
_log.Info("Starting NadekoBot v" + typeof(NadekoBot).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion);
|
||||||
|
|
||||||
|
|
||||||
|
Credentials = new BotCredentials();
|
||||||
|
|
||||||
//create client
|
//create client
|
||||||
Client = new ShardedDiscordClient (new DiscordSocketConfig
|
Client = new ShardedDiscordClient (new DiscordSocketConfig
|
||||||
{
|
{
|
||||||
AudioMode = Discord.Audio.AudioMode.Outgoing,
|
AudioMode = Discord.Audio.AudioMode.Outgoing,
|
||||||
MessageCacheSize = 10,
|
MessageCacheSize = 10,
|
||||||
LogLevel = LogSeverity.Warning,
|
LogLevel = LogSeverity.Warning,
|
||||||
|
TotalShards = Credentials.TotalShards,
|
||||||
|
ConnectionTimeout = 60000
|
||||||
});
|
});
|
||||||
|
|
||||||
//initialize Services
|
//initialize Services
|
||||||
Credentials = new BotCredentials();
|
|
||||||
CommandService = new CommandService();
|
CommandService = new CommandService();
|
||||||
Localizer = new Localization();
|
Localizer = new Localization();
|
||||||
Google = new GoogleApiService();
|
Google = new GoogleApiService();
|
||||||
|
@ -48,9 +48,12 @@ namespace NadekoBot.Services
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bool verbose;
|
|
||||||
Permission rootPerm;
|
bool verbose = false;
|
||||||
string permRole;
|
Permission rootPerm = null;
|
||||||
|
string permRole = "";
|
||||||
|
if (guild != null)
|
||||||
|
{
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
var config = uow.GuildConfigs.PermissionsFor(guild.Id);
|
var config = uow.GuildConfigs.PermissionsFor(guild.Id);
|
||||||
@ -58,6 +61,8 @@ namespace NadekoBot.Services
|
|||||||
rootPerm = config.RootPermission;
|
rootPerm = config.RootPermission;
|
||||||
permRole = config.PermissionRole.Trim().ToLowerInvariant();
|
permRole = config.PermissionRole.Trim().ToLowerInvariant();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var t = await ExecuteCommand(usrMsg, usrMsg.Content, guild, usrMsg.Author, rootPerm, permRole, MultiMatchHandling.Best);
|
var t = await ExecuteCommand(usrMsg, usrMsg.Content, guild, usrMsg.Author, rootPerm, permRole, MultiMatchHandling.Best);
|
||||||
var command = t.Item1;
|
var command = t.Item1;
|
||||||
|
@ -22,6 +22,7 @@ namespace NadekoBot.Services.Database
|
|||||||
public DbSet<Currency> Currency { get; set; }
|
public DbSet<Currency> Currency { get; set; }
|
||||||
public DbSet<ConvertUnit> ConversionUnits { get; set; }
|
public DbSet<ConvertUnit> ConversionUnits { get; set; }
|
||||||
public DbSet<TypingArticle> TypingArticles { get; set; }
|
public DbSet<TypingArticle> TypingArticles { get; set; }
|
||||||
|
public DbSet<MusicPlaylist> MusicPlaylists { get; set; }
|
||||||
|
|
||||||
//logging
|
//logging
|
||||||
public DbSet<LogSetting> LogSettings { get; set; }
|
public DbSet<LogSetting> LogSettings { get; set; }
|
||||||
|
@ -38,12 +38,16 @@ namespace NadekoBot.Services.Database
|
|||||||
|
|
||||||
private ICurrencyRepository _currency;
|
private ICurrencyRepository _currency;
|
||||||
public ICurrencyRepository Currency => _currency ?? (_currency = new CurrencyRepository(_context));
|
public ICurrencyRepository Currency => _currency ?? (_currency = new CurrencyRepository(_context));
|
||||||
|
|
||||||
private IUnitConverterRepository _conUnits;
|
private IUnitConverterRepository _conUnits;
|
||||||
public IUnitConverterRepository ConverterUnits => _conUnits ?? (_conUnits = new UnitConverterRepository(_context));
|
public IUnitConverterRepository ConverterUnits => _conUnits ?? (_conUnits = new UnitConverterRepository(_context));
|
||||||
|
|
||||||
private ITypingArticlesRepository _typingArticles;
|
private ITypingArticlesRepository _typingArticles;
|
||||||
public ITypingArticlesRepository TypingArticles => _typingArticles ?? (_typingArticles = new TypingArticlesRepository(_context));
|
public ITypingArticlesRepository TypingArticles => _typingArticles ?? (_typingArticles = new TypingArticlesRepository(_context));
|
||||||
|
|
||||||
|
private IMusicPlaylistRepository _musicPlaylists;
|
||||||
|
public IMusicPlaylistRepository MusicPlaylists => _musicPlaylists ?? (_musicPlaylists = new MusicPlaylistRepository(_context));
|
||||||
|
|
||||||
public UnitOfWork(NadekoContext context)
|
public UnitOfWork(NadekoContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
|
@ -27,6 +27,7 @@ namespace NadekoBot.Services.Impl
|
|||||||
public string SoundCloudClientId { get; }
|
public string SoundCloudClientId { get; }
|
||||||
|
|
||||||
public DB Db { get; }
|
public DB Db { get; }
|
||||||
|
public int TotalShards { get; }
|
||||||
|
|
||||||
public BotCredentials()
|
public BotCredentials()
|
||||||
{
|
{
|
||||||
@ -40,6 +41,7 @@ namespace NadekoBot.Services.Impl
|
|||||||
GoogleApiKey = cm.GoogleApiKey;
|
GoogleApiKey = cm.GoogleApiKey;
|
||||||
MashapeKey = cm.MashapeKey;
|
MashapeKey = cm.MashapeKey;
|
||||||
OsuApiKey = cm.OsuApiKey;
|
OsuApiKey = cm.OsuApiKey;
|
||||||
|
TotalShards = cm.TotalShards < 1 ? 1 : cm.TotalShards;
|
||||||
SoundCloudClientId = cm.SoundCloudClientId;
|
SoundCloudClientId = cm.SoundCloudClientId;
|
||||||
if (cm.Db == null)
|
if (cm.Db == null)
|
||||||
Db = new DB("sqlite", "");
|
Db = new DB("sqlite", "");
|
||||||
@ -60,6 +62,7 @@ namespace NadekoBot.Services.Impl
|
|||||||
public string OsuApiKey { get; set; }
|
public string OsuApiKey { get; set; }
|
||||||
public string SoundCloudClientId { get; set; }
|
public string SoundCloudClientId { get; set; }
|
||||||
public DB Db { get; set; }
|
public DB Db { get; set; }
|
||||||
|
public int TotalShards { get; set; } = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DbModel
|
private class DbModel
|
||||||
|
Loading…
Reference in New Issue
Block a user