aboutsummaryrefslogtreecommitdiff
path: root/Utilities
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@protonmail.com>2024-02-17 00:07:31 -0500
committerGitHub <noreply@github.com>2024-02-17 00:07:31 -0500
commit214a83c0f696ac731c54b00bf7503f87e497afa6 (patch)
tree15d57b08e69d19fb4c2f3effb9937aec8d042bdc /Utilities
parentb29ab06623fd24cfc2a611bdd658b4d2ef934335 (diff)
parentc848f1d90fef40ffa81915d7dd875a2ee6d6c8d5 (diff)
downloadDLAP-214a83c0f696ac731c54b00bf7503f87e497afa6.tar.gz
DLAP-214a83c0f696ac731c54b00bf7503f87e497afa6.tar.bz2
DLAP-214a83c0f696ac731c54b00bf7503f87e497afa6.zip
Merge pull request #17 from Alee14/testing
Merging testing branch
Diffstat (limited to 'Utilities')
-rw-r--r--Utilities/Voting.js40
-rw-r--r--Utilities/i18n.js10
2 files changed, 27 insertions, 23 deletions
diff --git a/Utilities/Voting.js b/Utilities/Voting.js
index ad9b656..fe38ab0 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 {
@@ -37,7 +39,7 @@ async function commandCheck(interaction, bot) {
}
}
-export async function voteSkip(interaction, bot) { /*
+export async function voteSkip(interaction, bot) {
if (interaction.commandName === 'next') {
if (nextCheck !== true) {
// Reset the votes if the current value of nextCheck is different from the command being executed
@@ -55,44 +57,44 @@ 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 - votes.size) / 2);
+ const votesRequired = Math.ceil(members.size / 2);
// 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('playerStopped'), ephemeral: true });
}
}
-*/
+
if (interaction.options.getSubcommand() === 'force') {
- if (!interaction.member.roles.cache.has(djRole) && interaction.user.id !== ownerID && !interaction.member.permission.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('playerStopped'), 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);
}
};