From 72ea1090753ccca3c5573801ae0b0a4439e1b736 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Tue, 13 Feb 2024 22:35:50 -0500 Subject: Fully working i18n (hopefully); Docker on walkthrough --- Commands/status.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'Commands/status.js') diff --git a/Commands/status.js b/Commands/status.js index aeb909d..d762187 100644 --- a/Commands/status.js +++ b/Commands/status.js @@ -22,9 +22,11 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { parseFile } from 'music-metadata'; import { audio, metadataEmpty, duration, audioTitle, currentTrack } from '../AudioBackend/PlayAudio.js'; -import { files, playerState } from '../AudioBackend/AudioControl.js'; +import { files, playerState, playerStatus } from '../AudioBackend/AudioControl.js'; import { votes } from '../Utilities/Voting.js'; +import i18next from '../Utilities/i18n.js'; +const t = i18next.t; export default { data: new SlashCommandBuilder() .setName('status') @@ -44,7 +46,7 @@ export default { const votesRequired = Math.ceil((members.size - votes.size) / 2); if (audioID >= files.length) { - audioName = 'Playlist Finished'; + audioName = t('playlistDone'); } else { audioName = files[audioID]; if (!metadataEmpty) { @@ -60,25 +62,27 @@ export default { } const controlEmbed = new EmbedBuilder() - .setAuthor({ name: `${bot.user.username} Status`, iconURL: bot.user.avatarURL() }) + .setAuthor({ name: t('statusTitle', { bot: bot.user.username }), iconURL: bot.user.avatarURL() }) .addFields( - { name: 'State', value: `${playerState}` }, - { name: 'Tracks', value: `${audioID}/${files.length}` }, - { name: 'Duration', value: `${duration}` }, - { name: 'Votes Needed', value: `${votesRequired}` } + { name: t('statusState'), value: `${playerState}` }, + { name: t('statusTracks'), value: `${audioID}/${files.length}` }, + { name: t('musicDuration'), value: `${duration}` }, + { name: t('statusVotesNeeded'), value: `${votesRequired}` } ) .setColor('#0066ff'); - if (metadataEmpty) { - controlEmbed.addFields( - { name: 'Currently Playing', value: `${audio}` }, - { name: 'Up Next', value: `${audioName}` } - ); - } else { - controlEmbed.addFields( - { name: 'Currently Playing', value: `${audioTitle}` }, - { name: 'Up Next', value: `${audioName}` } - ); + if (playerStatus === 0 || playerStatus === 1) { + if (metadataEmpty) { + controlEmbed.addFields( + { name: t('currentlyPlaying'), value: `${audio}` }, + { name: t('upNext'), value: `${audioName}` } + ); + } else { + controlEmbed.addFields( + { name: t('currentlyPlaying'), value: `${audioTitle}` }, + { name: t('upNext'), value: `${audioName}` } + ); + } } interaction.reply({ embeds: [controlEmbed] }); } -- cgit v1.2.3 From 891cf0ecdad9a1a78fdf5d127a60bdcc8e54ae5c Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Thu, 15 Feb 2024 20:19:36 -0500 Subject: Deploy command changes; Filter bots on vote; Fixed status --- Commands/about.js | 4 ++-- Commands/status.js | 8 +++----- README.md | 2 +- Utilities/Voting.js | 2 +- deploy-command.js | 25 +++++++++++++++++++------ 5 files changed, 26 insertions(+), 15 deletions(-) (limited to 'Commands/status.js') diff --git a/Commands/about.js b/Commands/about.js index d8afa52..8e1d31d 100644 --- a/Commands/about.js +++ b/Commands/about.js @@ -36,9 +36,9 @@ 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: '[your name] (username)' }, + { name: t('aboutContributors'), value: 'Victor Moraes (Vicktor#7232) (Improving README)' }, // { name: t('aboutForked'), value: '[your name] (username)' }, - { name: t('aboutFrameworks'), value: `Discord.JS ${version} + Voice` }, + { name: t('aboutFrameworks'), value: `Discord.JS ${version}\nmusic-metadata` }, { name: t('aboutLicense'), value: 'GNU General Public License v3.0' } ) .setFooter({ text: '© Copyright 2020-2024 Andrew Lee' }) diff --git a/Commands/status.js b/Commands/status.js index d762187..fcc6c08 100644 --- a/Commands/status.js +++ b/Commands/status.js @@ -40,10 +40,10 @@ export default { // Get the members of the voice channel who have not voted yet const voiceChannel = interaction.member.voice.channel; - const members = voiceChannel.members.filter(m => !votes.has(m.id)); + const members = voiceChannel.members.filter(m => !votes.has(m.id) && !m.user.bot); // Calculate the number of votes required to skip the audio track - const votesRequired = Math.ceil((members.size - votes.size) / 2); + const votesRequired = Math.ceil(members.size / 2); if (audioID >= files.length) { audioName = t('playlistDone'); @@ -52,12 +52,10 @@ export default { if (!metadataEmpty) { try { const { common } = await parseFile('music/' + audioName); - audioName = common.title; + audioName = common.title ? common.title : audioName.split('.').slice(0, -1).join('.'); } catch (error) { console.error(error.message); } - } else { - audioName = audioName.split('.').slice(0, -1).join('.'); } } diff --git a/README.md b/README.md index 9696433..e9b739e 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ shutdown - Powers off the bot. # Forking When forking the project, you can make your own version of DLAP or help contribute to the project (See the "Contributing" section). -You need to edit `/commands/about.js` to uncomment the `{ name: 'Forked by', value: '[your name] (discord#0000)' }` section. +You need to edit `/commands/about.js` to uncomment the `{ name: 'Forked by', value: '[your name] (username)' }` section. Be sure to replace that with your name. diff --git a/Utilities/Voting.js b/Utilities/Voting.js index 452dc55..fe38ab0 100644 --- a/Utilities/Voting.js +++ b/Utilities/Voting.js @@ -57,7 +57,7 @@ export async function voteSkip(interaction, bot) { if (interaction.options.getSubcommand() === 'vote') { // Get the members of the voice channel who have not voted yet const voiceChannel = interaction.member.voice.channel; - const members = voiceChannel.members.filter(m => !votes.has(m.id)); + const members = voiceChannel.members.filter(m => !votes.has(m.id) && !m.user.bot); // Calculate the number of votes required to skip the audio track const votesRequired = Math.ceil(members.size / 2); diff --git a/deploy-command.js b/deploy-command.js index fd9de7a..0b57507 100644 --- a/deploy-command.js +++ b/deploy-command.js @@ -1,6 +1,5 @@ import fs, { readFileSync } from 'node:fs'; -import { REST } from '@discordjs/rest'; -import { Routes } from 'discord-api-types/v10'; +import { REST, Routes } from 'discord.js'; // import config from './config.json' assert {type: 'json'} const { clientID, token } = JSON.parse(readFileSync('./config.json')); @@ -12,8 +11,22 @@ for (const file of commandFiles) { commands.push(command.data.toJSON()); } -const rest = new REST({ version: '10' }).setToken(token); +const rest = new REST().setToken(token); -rest.put(Routes.applicationCommands(clientID), { body: commands }) - .then(() => console.log('Successfully registered application commands.')) - .catch(console.error); +// and deploy your commands! +(async() => { + try { + console.log(`Started refreshing ${commands.length} application (/) commands.`); + + // The put method is used to fully refresh all commands in the guild with the current set + const data = await rest.put( + Routes.applicationCommands(clientID), + { body: commands } + ); + + console.log(`Successfully reloaded ${data.length} application (/) commands.`); + } catch (error) { + // And of course, make sure you catch and log any errors! + console.error(error); + } +})(); -- cgit v1.2.3 From c848f1d90fef40ffa81915d7dd875a2ee6d6c8d5 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sat, 17 Feb 2024 00:01:56 -0500 Subject: Fixed status command --- Commands/status.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Commands/status.js') diff --git a/Commands/status.js b/Commands/status.js index fcc6c08..ee02126 100644 --- a/Commands/status.js +++ b/Commands/status.js @@ -56,6 +56,8 @@ export default { } catch (error) { console.error(error.message); } + } else { + audioName = audioName.split('.').slice(0, -1).join('.'); } } -- cgit v1.2.3