예제 #1
0
        public async Task Remove(CommandContext ctx, int pos, [RemainingText] string pl = null)
        {
            if (pl == null)
            {
                pl = await SelectPL(ctx);

                if (pl == null)
                {
                    return;
                }
            }
            pos = pos - 1;
            var p = await PlaylistDB.GetPlaylistsSimple(ctx.Member.Id);

            if (!p.Any(x => x == pl))
            {
                await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Remove Song").WithDescription("**Error** You dont have a playlist with that name!").Build());

                return;
            }
            var ents = await PlaylistDB.GetPlaylist(ctx.Member.Id, pl);

            var en = await ents.GetEntries();

            await PlaylistDB.RemoveFromList(pos, pl, ctx.Member.Id);

            await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Remove Song").WithDescription($"Entry removed! -> {en[pos].track.Title}").Build());
        }
예제 #2
0
        public async Task Insert(CommandContext ctx, int pos, [RemainingText] string name = null)
        {
            if (name == null)
            {
                name = await SelectPL(ctx);

                if (name == null)
                {
                    return;
                }
            }
            pos = pos - 1;
            var inter = ctx.Client.GetInteractivity();
            var p     = await PlaylistDB.GetPlaylistsSimple(ctx.Member.Id);

            if (!p.Any(x => x == name))
            {
                await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Insert Song").WithDescription("**Error** You dont have a playlist with that name!").Build());

                return;
            }
            var pls = await PlaylistDB.GetPlaylist(ctx.Member.Id, name);

            if (pls.ExternalService != ExtService.None)
            {
                await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Insert Song").WithDescription("**Error** This playlist is a fixed one, you cant add songs to this!").Build());

                return;
            }
            var msg = await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Insert Song").WithDescription($"Please enter the song searchterm or URL now\n" +
                                                                                                                        $"No prefix needed!").Build());

            var hm2 = await inter.WaitForMessageAsync(x => x.Author == ctx.Member, TimeSpan.FromSeconds(30));

            await msg.DeleteAsync();

            var got = await PlaylistDB.GetSong(hm2.Result.Content, ctx);

            if (got == null)
            {
                return;
            }
            got.Tracks.Reverse();
            await PlaylistDB.InsertEntry(name, ctx.Member.Id, got.Tracks, pos);

            var ent = await pls.GetEntries();

            if (got.Tracks.Count > 1)
            {
                await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Insert Song").WithDescription($"Inserted entry -> {got.Tracks[0].Title} at {pos + 1}!\n" +
                                                                                                                  $"And {got.Tracks.Count - 2} more!").Build());
            }
            else
            {
                await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Insert Song").WithDescription($"Inserted entry -> {got.Tracks[0].Title} at {pos + 1}!").Build());
            }
        }
예제 #3
0
        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());
        }
예제 #4
0
        public async Task Move(CommandContext ctx, int oldpos, int newpos, [RemainingText] string pl = null)
        {
            if (pl == null)
            {
                pl = await SelectPL(ctx);

                if (pl == null)
                {
                    return;
                }
            }
            oldpos = oldpos - 1;
            newpos = newpos - 1;
            var p = await PlaylistDB.GetPlaylistsSimple(ctx.Member.Id);

            if (!p.Any(x => x == pl))
            {
                await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Insert Song").WithDescription("**Error** You dont have a playlist with that name!").Build());

                return;
            }
            var pls = await PlaylistDB.GetPlaylist(ctx.Member.Id, pl);

            if (pls.ExternalService != ExtService.None)
            {
                await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Insert Song").WithDescription("**Error** This playlist is a fixed one, you cant move songs!").Build());

                return;
            }
            var e = await pls.GetEntries();

            if (e[newpos] == null | e[oldpos] == null)
            {
                return;
            }
            await PlaylistDB.MoveListItems(pl, ctx.Member.Id, oldpos, newpos);

            await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Move Song").WithDescription($"Moved entry -> {e[oldpos].track.Title} to position {newpos+1}!").Build());
        }
예제 #5
0
        public async Task Rename(CommandContext ctx, [RemainingText] string name = null)
        {
            if (name == null)
            {
                name = await SelectPL(ctx);

                if (name == null)
                {
                    return;
                }
            }
            var inter = ctx.Client.GetInteractivity();
            var p     = await PlaylistDB.GetPlaylistsSimple(ctx.Member.Id);

            if (!p.Any(x => x == name))
            {
                await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Rename Playlist").WithDescription("**Error** You dont have a playlist with that name!").Build());

                return;
            }
            var pls = await PlaylistDB.GetPlaylist(ctx.Member.Id, name);

            await pls.GetEntries();

            var msg = await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Rename Playlist").WithDescription($"Please enter the new playlistname now!\n" +
                                                                                                                            $"No prefix needed!").Build());

            var hm = await inter.WaitForMessageAsync(x => x.Author == ctx.Member, TimeSpan.FromSeconds(30));

            await msg.DeleteAsync();

            await PlaylistDB.RenameList(name, ctx.Member.Id, hm.Result.Content);

            await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Rename Playlist").WithDescription($"Renamed Playlist to\n" +
                                                                                                                  $"{name} -> {hm.Result.Content}!").Build());
        }
예제 #6
0
        public async Task Show(CommandContext ctx, [RemainingText] string name = null)
        {
            if (name == null)
            {
                name = await SelectPL(ctx);

                if (name == null)
                {
                    return;
                }
            }
            var pls = await PlaylistDB.GetPlaylistsSimple(ctx.Member.Id);

            if (!pls.Any(x => x == name))
            {
                await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Show Playlist").WithDescription("**Error** You dont have a playlist with that name!").Build());

                return;
            }
            var q = await PlaylistDB.GetPlaylist(ctx.Member.Id, name);

            var queue = await q.GetEntries();

            if (queue.Count == 0)
            {
                await ctx.RespondAsync("Playlist empty!");

                return;
            }
            var inter        = ctx.Client.GetInteractivity();
            int songsPerPage = 0;
            int currentPage  = 1;
            int songAmount   = 0;
            int totalP       = queue.Count / 5;

            if ((queue.Count % 5) != 0)
            {
                totalP++;
            }
            var         emb   = new DiscordEmbedBuilder();
            List <Page> Pages = new List <Page>();

            foreach (var Track in queue)
            {
                string time = "";
                if (Track.track.Length.Hours < 1)
                {
                    time = Track.track.Length.ToString(@"mm\:ss");
                }
                else
                {
                    time = Track.track.Length.ToString(@"hh\:mm\:ss");
                }
                emb.AddField($"**{songAmount+1}.{Track.track.Title.Replace("*", "").Replace("|", "")}** by {Track.track.Author.Replace("*", "").Replace("|", "")} [{time}]",
                             $"Added on {Track.additionDate} [Link]({Track.track.Uri.AbsoluteUri})");
                songsPerPage++;
                songAmount++;
                emb.WithTitle($"Songs in {name}");
                if (songsPerPage == 5)
                {
                    songsPerPage = 0;
                    emb.WithFooter($"Page {currentPage}/{totalP}");
                    Pages.Add(new Page(embed: emb));
                    emb.ClearFields();
                    currentPage++;
                }
                if (songAmount == queue.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));
        }