Esempio n. 1
0
        // Finds all the local songs and prints out a set at a time by page number.
        public void PrintLocalSongs(int page)
        {
            // Get all the songs in this directory.
            string[] items     = m_AudioDownloader.GetAllItems();
            int      itemCount = items.Length;

            if (itemCount == 0)
            {
                Log("No local files found.", (int)E_LogOutput.Reply);
                return;
            }

            // Count the number of total digits.
            int countDigits = (int)(Math.Floor(Math.Log10(items.Length) + 1));

            // Set pages to print.
            int pageSize = 20;
            int pages    = (itemCount / pageSize) + 1;

            if (page < 1 || page > pages)
            {
                Log($"There are {pages} pages. Select page 1 to {pages}.", (int)E_LogOutput.Reply);
                return;
            }

            // Start printing.
            for (int p = page - 1; p < page; p++)
            {
                // Create an embed builder.
                var emb = new EmbedBuilder();

                for (int i = 0; i < pageSize; i++)
                {
                    // Get the index for the file.
                    int index = (p * pageSize) + i;
                    if (index >= itemCount)
                    {
                        break;
                    }

                    // Prepend 0's so it matches in length. This will be the 'index'.
                    string zeros     = "";
                    int    numDigits = (index == 0) ? 1 : (int)(Math.Floor(Math.Log10(index) + 1));
                    while (numDigits < countDigits)
                    {
                        zeros += "0";
                        ++numDigits;
                    }

                    // Filename.
                    string file = items[index].Split(Path.DirectorySeparatorChar).Last(); // Get just the file name.
                    emb.AddField(zeros + index, file);
                }

                DiscordReply($"Page {p+1}", emb);
            }
        }