Updated packages; Lists now uses queue; Credits

This commit is contained in:
Andrew Lee 2024-09-27 12:53:52 -04:00
parent 368d580f97
commit d62339796f
Signed by: andrew
SSH key fingerprint: SHA256:bbGg1DYG5CuKl2jo1DqzvUsaTeyvhM3tjCsej5lYMg4
4 changed files with 46 additions and 31 deletions

View file

@ -36,7 +36,7 @@ export default {
{ name: t('aboutInfo'), value: t('aboutInfoValue') }, { name: t('aboutInfo'), value: t('aboutInfoValue') },
{ name: t('aboutBotVersion'), value: `DLAP ${npmPackage.version}` }, { name: t('aboutBotVersion'), value: `DLAP ${npmPackage.version}` },
{ name: t('aboutCreator'), value: 'Andrew Lee (alee)' }, // Do not remove this since I created this :) { 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('aboutForked'), value: '[your name] (username)' },
{ name: t('aboutFrameworks'), value: `Discord.JS ${version}\nmusic-metadata\ni18next` }, { name: t('aboutFrameworks'), value: `Discord.JS ${version}\nmusic-metadata\ni18next` },
{ name: t('aboutLicense'), value: 'GNU General Public License v3.0' } { name: t('aboutLicense'), value: 'GNU General Public License v3.0' }

View file

@ -22,6 +22,7 @@
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { readdir } from 'node:fs'; import { readdir } from 'node:fs';
import i18next from '../Utilities/i18n.js'; import i18next from '../Utilities/i18n.js';
import { files as queuedFiles } from '../AudioBackend/AudioControl.js';
const musicFolder = './music'; const musicFolder = './music';
const t = i18next.t; const t = i18next.t;
@ -32,34 +33,48 @@ export default {
.addIntegerOption(option => .addIntegerOption(option =>
option.setName('page') option.setName('page')
.setDescription('Input a number to change the page of the list') .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) { async execute(interaction, bot) {
const page = interaction.options.getInteger('page') || 1; // If no page is specified, default to page 1 const page = interaction.options.getInteger('page') || 1; // If no page is specified, default to page 1
readdir(musicFolder, async(err, files) => { const queue = interaction.options.getBoolean('queue') !== false; // Check if queue option is true
if (err) {
console.error(err); const listTracks = (tracks) => {
} else { const trackList = tracks.map((file, i) => `${i}: ${file}`); // Create an array of track names
const trackList = files.map((file, i) => `${i}: ${file}`); // Create an array of track names const pageSize = 20; // Number of tracks per page
const pageSize = 20; // Number of tracks per page const numPages = Math.ceil(trackList.length / pageSize); // Total number of pages
const numPages = Math.ceil(trackList.length / pageSize); // Total number of pages if (page < 1 || page > numPages) { // Check if the page number is valid
if (page < 1 || page > numPages) { // Check if the page number is valid return interaction.reply({ content: t('invalidPage', { numPages }), ephemeral: true });
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] });
} }
}); // 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);
}
});
}
} }
}; };

BIN
bun.lockb Executable file

Binary file not shown.

View file

@ -10,12 +10,12 @@
}, },
"dependencies": { "dependencies": {
"@discordjs/opus": "^0.9.0", "@discordjs/opus": "^0.9.0",
"@discordjs/voice": "^0.16.1", "@discordjs/voice": "^0.17.0",
"discord.js": "^14.14.1", "discord.js": "^14.16.2",
"ffmpeg-static": "^5.2.0", "ffmpeg-static": "^5.2.0",
"i18next": "^23.8.2", "i18next": "^23.15.1",
"i18next-fs-backend": "^2.3.1", "i18next-fs-backend": "^2.3.2",
"music-metadata": "^7.14.0", "music-metadata": "^10.5.0",
"sodium": "^3.0.2" "sodium": "^3.0.2"
}, },
"devDependencies": { "devDependencies": {