diff options
Diffstat (limited to 'Utilities')
| -rw-r--r-- | Utilities/Voting.js | 32 | ||||
| -rw-r--r-- | Utilities/i18n.js | 10 |
2 files changed, 23 insertions, 19 deletions
diff --git a/Utilities/Voting.js b/Utilities/Voting.js index dc2f153..5bea29c 100644 --- a/Utilities/Voting.js +++ b/Utilities/Voting.js @@ -18,18 +18,20 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * ***************************************************************************/ -import { nextAudio, playerState, previousAudio } from '../AudioBackend/AudioControl.js'; +import { nextAudio, playerStatus, previousAudio } from '../AudioBackend/AudioControl.js'; import { PermissionFlagsBits } from 'discord-api-types/v10'; import { readFileSync } from 'node:fs'; import { player } from '../AudioBackend/VoiceInitialization.js'; -const { djRole, ownerID } = JSON.parse(readFileSync('./config.json', 'utf-8')); +import i18next from '../Utilities/i18n.js'; +const { djRole, ownerID } = JSON.parse(readFileSync('./config.json', 'utf-8')); +const t = i18next.t; export const votes = new Set(); let nextCheck; async function commandCheck(interaction, bot) { if (nextCheck) { - await interaction.reply({ content: 'Playing next music' }); + await interaction.reply({ content: t('musicNext') }); player.stop(); return await nextAudio(bot); } else { @@ -62,37 +64,37 @@ export async function voteSkip(interaction, bot) { // Check if the message author has already voted if (votes.has(interaction.user.id)) { - return interaction.reply({ content: `You have already voted, wait ${votesRequired} more vote(s) to skip the audio track`, ephemeral: true }); + return interaction.reply({ content: t('alreadyVoted', votesRequired), ephemeral: true }); } - if (playerState === 'Playing' || playerState === 'Paused') { + if (playerStatus === 0 || playerStatus === 1) { // Add the message author to the set of members who have voted votes.add(interaction.user.id); if (votes.size >= votesRequired) { - console.log('Enough votes has passed, skipping audio file...'); + console.log(t('enoughVotes')); // Reset the number of votes votes.clear(); // Do something to skip the audio track here (e.g. player.stop()) await commandCheck(interaction, bot); } else { // Send a message with the number of votes needed to skip the audio track - console.log(`${votesRequired - 1} more vote(s) needed to skip the audio track.`); - await interaction.reply({ content: `${votesRequired - 1} more vote(s) needed to skip the audio track.` }); + console.log(t('votesNeeded', { votesRequired: votesRequired - 1 })); + await interaction.reply({ content: t('votesNeeded', { votesRequired: votesRequired - 1 }) }); } - } else if (playerState === 'Stopped') { - return await interaction.reply({ content: 'Cannot play next music. Player is currently stopped...', ephemeral: true }); + } else if (playerStatus === 2) { + return await interaction.reply({ content: t('cannotPlay'), ephemeral: true }); } } if (interaction.options.getSubcommand() === 'force') { - if (!interaction.member.roles.cache.has(djRole) && interaction.user.id !== ownerID && !interaction.memberPermissions.has(PermissionFlagsBits.ManageGuild)) return interaction.reply({ content: 'You need a specific role to execute this command', ephemeral: true }); - console.log('Force skipping this audio track...'); - if (playerState === 'Playing' || playerState === 'Paused') { + if (!interaction.member.roles.cache.has(djRole) && interaction.user.id !== ownerID && !interaction.memberPermissions.has(PermissionFlagsBits.ManageGuild)) return interaction.reply({ content: t('rolePermission'), ephemeral: true }); + console.log(t('forceSkip')); + if (playerStatus === 0 || playerStatus === 1) { votes.clear(); // Do something to skip the audio track here (e.g. player.stop()) await commandCheck(interaction, bot); - } else if (playerState === 'Stopped') { - return await interaction.reply({ content: 'Cannot play next music. Player is currently stopped...', ephemeral: true }); + } else if (playerStatus === 2) { + return await interaction.reply({ content: t('cannotPlay'), ephemeral: true }); } } } diff --git a/Utilities/i18n.js b/Utilities/i18n.js index c667c4c..9b431a1 100644 --- a/Utilities/i18n.js +++ b/Utilities/i18n.js @@ -20,10 +20,12 @@ ***************************************************************************/ import i18next from 'i18next'; import fsBackend from 'i18next-fs-backend'; +import { readFileSync } from 'node:fs'; +const { locale } = JSON.parse(readFileSync('./config.json', 'utf-8')); i18next.use(fsBackend).init({ - lng: 'en', // if you're using a language detector, do not define the lng option - debug: true, + lng: locale, // if you're using a language detector, do not define the lng option + debug: false, fallbackLng: 'en', backend: { loadPath: './Locales/{{lng}}/{{ns}}.json' @@ -32,7 +34,7 @@ i18next.use(fsBackend).init({ export default { i18next, - t(key) { - return i18next.t(key); + t(key, option) { + return i18next.t(key, option); } }; |
