From d62339796f3fd1aa7d669c10a18ae03d301289c3 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Fri, 27 Sep 2024 12:53:52 -0400 Subject: Updated packages; Lists now uses queue; Credits --- Commands/about.js | 2 +- Commands/list.js | 65 +++++++++++++++++++++++++++++++++--------------------- bun.lockb | Bin 0 -> 132508 bytes package.json | 10 ++++----- 4 files changed, 46 insertions(+), 31 deletions(-) create mode 100755 bun.lockb diff --git a/Commands/about.js b/Commands/about.js index 8b63ca2..4b8a9ea 100644 --- a/Commands/about.js +++ b/Commands/about.js @@ -36,7 +36,7 @@ export default { { name: t('aboutInfo'), value: t('aboutInfoValue') }, { name: t('aboutBotVersion'), value: `DLAP ${npmPackage.version}` }, { name: t('aboutCreator'), value: 'Andrew Lee (alee)' }, // Do not remove this since I created this :) - { name: t('aboutContributors'), value: 'Victor Moraes (Vicktor#7232) (Improving README)\nParlance Translation Team' }, + { name: t('aboutContributors'), value: 'Victor Moraes (Vicktor#7232) (Improving README)\nAizuddin Akmal (AizuddinAkmal) (Improved Dockerfile)\nParlance Translation Team' }, // { name: t('aboutForked'), value: '[your name] (username)' }, { name: t('aboutFrameworks'), value: `Discord.JS ${version}\nmusic-metadata\ni18next` }, { name: t('aboutLicense'), value: 'GNU General Public License v3.0' } 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); + } + }); + } } }; diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..0cc3daa Binary files /dev/null and b/bun.lockb differ diff --git a/package.json b/package.json index 4c309cb..44eff27 100644 --- a/package.json +++ b/package.json @@ -10,12 +10,12 @@ }, "dependencies": { "@discordjs/opus": "^0.9.0", - "@discordjs/voice": "^0.16.1", - "discord.js": "^14.14.1", + "@discordjs/voice": "^0.17.0", + "discord.js": "^14.16.2", "ffmpeg-static": "^5.2.0", - "i18next": "^23.8.2", - "i18next-fs-backend": "^2.3.1", - "music-metadata": "^7.14.0", + "i18next": "^23.15.1", + "i18next-fs-backend": "^2.3.2", + "music-metadata": "^10.5.0", "sodium": "^3.0.2" }, "devDependencies": { -- cgit v1.2.3