diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2024-09-27 12:53:52 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2024-09-27 12:53:52 -0400 |
| commit | d62339796f3fd1aa7d669c10a18ae03d301289c3 (patch) | |
| tree | b4a4ab5f04e4eeaff6df59573d5b2dc791815601 /Commands/list.js | |
| parent | 368d580f976070b31d92061509fbf19a7f81fed8 (diff) | |
| download | DLAP-d62339796f3fd1aa7d669c10a18ae03d301289c3.tar.gz DLAP-d62339796f3fd1aa7d669c10a18ae03d301289c3.tar.bz2 DLAP-d62339796f3fd1aa7d669c10a18ae03d301289c3.zip | |
Updated packages; Lists now uses queue; Credits
Diffstat (limited to 'Commands/list.js')
| -rw-r--r-- | Commands/list.js | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/Commands/list.js b/Commands/list.js index e2498d8..6a308e6 100644 --- a/Commands/list.js +++ b/Commands/list.js @@ -22,6 +22,7 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { readdir } from 'node:fs'; import i18next from '../Utilities/i18n.js'; +import { files as queuedFiles } from '../AudioBackend/AudioControl.js'; const musicFolder = './music'; const t = i18next.t; @@ -32,34 +33,48 @@ export default { .addIntegerOption(option => option.setName('page') .setDescription('Input a number to change the page of the list') + ) + .addBooleanOption(option => + option.setName('queue') + .setDescription('Lists the audio tracks from the queue') ), async execute(interaction, bot) { const page = interaction.options.getInteger('page') || 1; // If no page is specified, default to page 1 - readdir(musicFolder, async(err, files) => { - if (err) { - console.error(err); - } else { - const trackList = files.map((file, i) => `${i}: ${file}`); // Create an array of track names - const pageSize = 20; // Number of tracks per page - const numPages = Math.ceil(trackList.length / pageSize); // Total number of pages - if (page < 1 || page > numPages) { // Check if the page number is valid - return await interaction.reply({ content: t('invalidPage', { numPages }), ephemeral: true }); - } - // Split the track list into pages - const pages = []; - for (let i = 0; i < numPages; i++) { - const start = i * pageSize; - const end = start + pageSize; - pages.push(trackList.slice(start, end)); - } - // Send the specified page with the page number and total number of pages - const listEmbed = new EmbedBuilder(); - listEmbed.setAuthor({ name: t('listTitle', { bot: bot.user.username }), iconURL: bot.user.avatarURL() }); - listEmbed.addFields({ name: t('listTracks', { trackList: trackList.length }), value: `\`\`\`\n${pages[page - 1].join('\n')}\n\`\`\`` }); - listEmbed.setFooter({ text: t('listPage') + ` ${page}/${numPages}` }); - listEmbed.setColor('#0066ff'); - await interaction.reply({ embeds: [listEmbed] }); + const queue = interaction.options.getBoolean('queue') !== false; // Check if queue option is true + + const listTracks = (tracks) => { + const trackList = tracks.map((file, i) => `${i}: ${file}`); // Create an array of track names + const pageSize = 20; // Number of tracks per page + const numPages = Math.ceil(trackList.length / pageSize); // Total number of pages + if (page < 1 || page > numPages) { // Check if the page number is valid + return interaction.reply({ content: t('invalidPage', { numPages }), ephemeral: true }); } - }); + // Split the track list into pages + const pages = []; + for (let i = 0; i < numPages; i++) { + const start = i * pageSize; + const end = start + pageSize; + pages.push(trackList.slice(start, end)); + } + // Send the specified page with the page number and total number of pages + const listEmbed = new EmbedBuilder(); + listEmbed.setAuthor({ name: t('listTitle', { bot: bot.user.username }), iconURL: bot.user.avatarURL() }); + listEmbed.addFields({ name: t('listTracks', { trackList: trackList.length }), value: `\`\`\`\n${pages[page - 1].join('\n')}\n\`\`\`` }); + listEmbed.setFooter({ text: t('listPage') + ` ${page}/${numPages}` }); + listEmbed.setColor('#0066ff'); + interaction.reply({ embeds: [listEmbed] }); + }; + + if (queue) { + listTracks(queuedFiles); + } else { + readdir(musicFolder, (err, files) => { + if (err) { + console.error(err); + } else { + listTracks(files); + } + }); + } } }; |
