public async Task Play(CommandContext ctx, [RemainingText] string pl = null) { if (pl == null) { pl = await SelectPL(ctx); if (pl == null) { return; } } var ps = await PlaylistDB.GetPlaylists(ctx.Member.Id); if (!ps.Any(x => x.Key == pl)) { await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Play Playlist").WithDescription("**Error** You dont have a playlist with that name!").Build()); return; } var pls = await PlaylistDB.GetPlaylist(ctx.Member.Id, pl); var p = await pls.GetEntries(); Console.WriteLine("Done"); if (!Bot.Guilds.Any(x => x.Key == ctx.Guild.Id)) { Bot.Guilds.TryAdd(ctx.Guild.Id, new Guild(ctx.Client.ShardId)); } var g = Bot.Guilds[ctx.Guild.Id]; if (g.musicInstance == null) { g.musicInstance = new MusicInstance(Bot.LLEU[ctx.Client.ShardId], ctx.Client.ShardId); } if (!g.musicInstance.guildConnection?.IsConnected == null || !g.musicInstance.guildConnection.IsConnected == false) { await g.musicInstance.ConnectToChannel(ctx.Member.VoiceState.Channel); } g.musicInstance.usedChannel = ctx.Channel; await Database.AddToQueue(ctx.Guild, ctx.Member.Id, p); if (g.musicInstance.guildConnection.IsConnected && (g.musicInstance.playstate == Playstate.NotPlaying || g.musicInstance.playstate == Playstate.Stopped)) { await g.musicInstance.PlaySong(); } await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Play Playlist").WithDescription($"Playing playlist/Added to queue!").Build()); }
public async Task <string> SelectPL(CommandContext ctx) { var inter = ctx.Client.GetInteractivity(); await ctx.TriggerTypingAsync(); var plls = await PlaylistDB.GetPlaylistsSimple(ctx.Member.Id); if (plls.Count == 0) { await ctx.RespondAsync("You dont have any playlists"); return(null); } var pls = await PlaylistDB.GetPlaylists(ctx.Member.Id); string plss = ""; int i = 1; foreach (var pl in pls) { plss += $"**{i}.{pl.Key} ({pl.Value.SongCount}Songs)**\n" + $"Created at {pl.Value.Creation}\n" + $"Last modified at {pl.Value.Modify}\n"; i++; } var msg = await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Select Playlist || Timeout 25 seconds").WithDescription("Please select a playlist either by **Number** or **Name**\n\n" + $"{plss}")); var res = await inter.WaitForMessageAsync(x => x.Author == ctx.User, TimeSpan.FromSeconds(25)); int got = -1; try { got = Convert.ToInt32(res.Result.Content); } catch { } await msg.DeleteAsync(); await res.Result.DeleteAsync(); if (got == -1) { if (pls.Any(x => x.Key == res.Result.Content)) { return(res.Result.Content); } else { return(null); } } else if (got != -1 && pls.ElementAtOrDefault(got - 1).Value != null) { return(pls.ElementAtOrDefault(got - 1).Key); } else { return(null); } }
public async Task List(CommandContext ctx) { var pls = await PlaylistDB.GetPlaylists(ctx.Member.Id); if (pls.Count == 0) { await ctx.RespondAsync("You dont have any playlists"); return; } Console.WriteLine(pls.Count); var inter = ctx.Client.GetInteractivity(); int songsPerPage = 0; int currentPage = 1; int songAmount = 0; int totalP = pls.Count / 5; if ((pls.Count % 5) != 0) { totalP++; } var emb = new DiscordEmbedBuilder(); List <Page> Pages = new List <Page>(); Console.WriteLine(pls == null); foreach (var Track in pls) { //Console.WriteLine(Track.Value == null); //Console.WriteLine(Track.Key); int songam = 0; var ent = await Track.Value.GetEntries(); songam = ent.Count; string sub = ""; if (Track.Value.ExternalService == ExtService.None) { sub = $"Created on: {Track.Value.Creation}\n" + $"Last modified on: {Track.Value.Modify}"; } else { sub = $"Created on: {Track.Value.Creation}\n" + $"{Track.Value.ExternalService} [Link]({Track.Value.Url})"; } emb.AddField($"**{songAmount + 1}.{Track.Key}** ({songam} Songs)", sub); songsPerPage++; songAmount++; emb.WithTitle($"List Playlists"); if (songsPerPage == 5) { songsPerPage = 0; emb.WithFooter($"Page {currentPage}/{totalP}"); Pages.Add(new Page(embed: emb)); emb.ClearFields(); currentPage++; } if (songAmount == pls.Count) { emb.WithFooter($"Page {currentPage}/{totalP}"); Pages.Add(new Page(embed: emb)); //Console.WriteLine(emb.Fields.Count); emb.ClearFields(); } } if (currentPage == 1) { await ctx.RespondAsync(embed : Pages.First().Embed); return; } else if (currentPage == 2 && songsPerPage == 0) { await ctx.RespondAsync(embed : Pages.First().Embed); return; } foreach (var eP in Pages.Where(x => x.Embed.Fields.Count() == 0).ToList()) { Pages.Remove(eP); } await inter.SendPaginatedMessageAsync(ctx.Channel, ctx.User, Pages, timeoutoverride : TimeSpan.FromMinutes(5)); }