Example #1
0
        /*
         *
         * Playlist methods
         *
         */
        public int isPlaylist(string name)
        {
            ArrayList playlists = (ArrayList)SavePlaylist.get();

            for (int i = 0; i < playlists.Count; i++)
            {
                Playlist playlist = (Playlist)playlists[i];
                Console.WriteLine("(" + playlist.getName() + "==" + name + ")");
                if (playlist.getName().Equals(name))
                {
                    return(i);
                }
            }
            return(-1);
        }
Example #2
0
        public async Task playlist(string action, string modifier)
        {
            ArrayList playlists = (ArrayList)SavePlaylist.get();

            /********************
            ******CREATE********
            ********************/
            if (action.Equals("create", StringComparison.InvariantCultureIgnoreCase))
            {
                //playlist does not exist
                if (isPlaylist(modifier) == -1)
                {
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Creating playlist " + modifier + "...");

                    Playlist playlist = new Playlist(modifier);
                    SavePlaylist.store(playlist);
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Created playlist " + modifier + ".");
                }
                else
                {
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: Playlist already exists.");
                }
            }

            /********************
            *******DELETE********
            ********************/
            else if (action.Equals("delete", StringComparison.InvariantCultureIgnoreCase))
            {
                //playlist does not exist
                int index = isPlaylist(modifier);
                if (index != -1)
                {
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Deleting playlist " + modifier + "...");

                    SavePlaylist.delete(index);
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Deleted playlist " + modifier + ".");
                }
                else
                {
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: Playlist does not exists.");
                }
            }

            /********************
            ********LIST********
            ********************/
            else if (action.Equals("list", StringComparison.InvariantCultureIgnoreCase))
            {
                var builder = new EmbedBuilder();

                // 0 = playlist, 1 = all
                int listType = -1;

                if (modifier.Equals("all", StringComparison.InvariantCultureIgnoreCase))
                {
                    listType = 1;
                }
                else
                {
                    listType = 0;
                }

                if (listType == 1)
                {
                    builder.WithTitle("All Playlists");
                    for (int i = 0; i < playlists.Count; i++)
                    {
                        Playlist playlist = (Playlist)playlists[i];
                        builder.AddInlineField("Playlist " + (i + 1) + ": ", playlist.getName() + "\n");
                    }
                    builder.WithColor(Color.Blue);
                    await Context.Channel.SendMessageAsync("", false, builder);
                }

                if (listType == 0)
                {
                    int index = isPlaylist(modifier);
                    if (index != -1)
                    {
                        Playlist playlist = (Playlist)playlists[index];
                        builder.WithTitle("Playlist " + modifier + " songs");
                        ArrayList songs = playlist.getSongs();
                        Console.WriteLine("(" + songs.Count + ")");
                        if (songs.Count == 0)
                        {
                            builder.AddInlineField("No Songs", "---");
                        }
                        else
                        {
                            for (int i = 0; i < songs.Count; i++)
                            {
                                builder.AddInlineField("Song " + (i + 1) + ": ", songs[i]);
                            }
                        }
                        builder.WithColor(Color.Teal);
                        await Context.Channel.SendMessageAsync("", false, builder);
                    }
                    else
                    {
                        await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: Playlist not found. Try !playlist list all, to list all playlists.");
                    }
                }
            }

            /********************
            ******PLAY**********
            ********************/
            else if (action.Equals("play", StringComparison.InvariantCultureIgnoreCase))
            {
                int index = isPlaylist(modifier);
                if (index != -1)
                {
                    Playlist  playlist = (Playlist)playlists[index];
                    ArrayList songs    = playlist.getSongs();
                    string    url      = "https://www.youtube.com/watch_videos?video_ids=";
                    for (int i = 0; i < songs.Count; i++)
                    {
                        string song = (string)songs[i];
                        string id   = "";
                        int    n    = song.IndexOf("watch?v=");
                        if (n == -1)
                        {
                            await Context.Channel.SendMessageAsync("Song " + (i + 1) + "invalid. Skipping song...");
                        }
                        else
                        {
                            id = song.Substring(n + 8);
                            if (!(i == songs.Count - 1))
                            {
                                id += ",";
                            }
                            url += id;
                        }
                    }
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + "To play this playlist, open this link in your browser and use that browser url for Rythm. \n" + url);
                }
            }
            else
            {
                await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: this playlist command does not exist.");
            }
        }
Example #3
0
        public async Task playlistEdit(string name, string action, string song)
        {
            ArrayList playlists = (ArrayList)SavePlaylist.get();

            if (action.Equals("add", StringComparison.InvariantCultureIgnoreCase))
            {
                int index = isPlaylist(name);
                if (index != -1)
                {
                    if (song.IndexOf("youtube") != -1)
                    {
                        Console.WriteLine("((" + index + "))");
                        Console.WriteLine("((" + playlists.Count + ")) count");
                        Playlist playlist = (Playlist)playlists[index];

                        playlist.addSong(song);

                        await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Added song: " + song);
                    }
                    else
                    {
                        await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: Song must be a youtube link like: www.youtube.com/watch?v=4Tr0otuiQuU");
                    }
                }
            }
            else if (action.Equals("delete", StringComparison.InvariantCultureIgnoreCase))
            {
                int index = isPlaylist(name);
                if (index != -1)
                {
                    Playlist playlist = (Playlist)playlists[index];
                    if (playlist.containsSong(song))
                    {
                        //delete song
                        playlist.deleteSong(song);
                        await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Deleted song: " + song);
                    }
                    else if (int.TryParse(song, out int n))
                    {
                        if (n - 1 < playlists.Count)
                        {
                            await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Deleted song at index " + n + " : " + playlist.getSongs()[n - 1]);

                            playlist.deleteSong(n - 1);
                        }
                        else
                        {
                            await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: Playlist " + playlist.getName() + " only has " + playlist.getSongs().Count + " songs.");
                        }
                    }
                    else
                    {
                        await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: Song does not exist in " + playlist.getName() + ".");
                    }
                }
                else
                {
                    await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: Playlist does not exist.");
                }
            }
            else
            {
                await Context.Channel.SendMessageAsync(Context.Message.Author.Mention + " Error: this playlist command does not exist.");
            }
        }
Example #4
0
 public Commands()
 {
     SavePlaylist.save();
     names = readInNames();
     Console.Write(names.Length);
 }
Example #5
0
 public void deleteSong(int n)
 {
     _songs.RemoveAt(n);
     SavePlaylist.save(this);
 }
Example #6
0
 public void deleteSong(string song)
 {
     _songs.Remove(song);
     SavePlaylist.save(this);
 }
Example #7
0
 public void addSong(string song)
 {
     _songs.Add(song);
     SavePlaylist.save(this);
 }
Example #8
0
 public Playlist(string name)
 {
     _name = name;
     //_songs.Add("sample");
     SavePlaylist.save(this);
 }