From e0fe64b06c0eb8b92578ae1bf5a166f8d633c9b3 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Fri, 2 Dec 2022 00:31:17 -0500 Subject: [PATCH] Fixed duration date; More stop functions; Required in voice channel --- backend/AudioControl.js | 2 ++ backend/PlayAudio.js | 13 +++---------- bot.js | 1 - commands/join.js | 1 + commands/leave.js | 1 + commands/next.js | 1 + commands/pause.js | 1 + commands/play.js | 1 + commands/previous.js | 1 + commands/reshuffle.js | 5 +++-- commands/status.js | 1 + 11 files changed, 15 insertions(+), 13 deletions(-) diff --git a/backend/AudioControl.js b/backend/AudioControl.js index f26d9d1..216d610 100644 --- a/backend/AudioControl.js +++ b/backend/AudioControl.js @@ -76,7 +76,9 @@ export function audioState(state) { break; case 2: playerState = 'Stopped'; + totalTrack = files.length; isAudioStatePaused = true; + player.stop(); break; } } diff --git a/backend/PlayAudio.js b/backend/PlayAudio.js index 77a33bc..9b4a83b 100644 --- a/backend/PlayAudio.js +++ b/backend/PlayAudio.js @@ -59,14 +59,7 @@ export async function playAudio(bot) { } else { metadataEmpty = true; } - const toHHMMSS = (numSecs) => { - const secNum = parseInt(numSecs, 10); - const hours = Math.floor(secNum / 3600).toString().padStart(2, '0'); - const minutes = Math.floor((secNum - (hours * 3600)) / 60).toString().padStart(2, '0'); - const seconds = secNum - (hours * 3600) - (minutes * 60).toString().padStart(2, '0'); - return `${hours}:${minutes}:${seconds}`; - }; - duration = toHHMMSS(format.duration); + duration = new Date(format.duration * 1000).toISOString().substr(11, 8); } catch (e) { console.error(e); } @@ -104,8 +97,8 @@ export async function playAudio(bot) { return await channel.send({ embeds: [statusEmbed] }); } -export function updatePlaylist(i) { - switch (i) { +export function updatePlaylist(option) { + switch (option) { case 'next': currentTrack++; audio = files[currentTrack]; diff --git a/bot.js b/bot.js index 4aa909b..988ebb3 100644 --- a/bot.js +++ b/bot.js @@ -30,7 +30,6 @@ bot.login(token); /** * TODO: - Custom string support (Basically change what the bot is saying) * - Non repeat support - * - Modularizing AudioBackend * - Easier to use interface */ diff --git a/commands/join.js b/commands/join.js index c5f686d..aa3eb66 100644 --- a/commands/join.js +++ b/commands/join.js @@ -29,6 +29,7 @@ export default { .setDescription('Joins voice chat') .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), async execute(interaction, bot) { + if (!interaction.member.voice.channel) return await interaction.reply({ content: 'You need to be in a voice channel to use this command.', ephemeral: true }); await interaction.reply({ content: 'Joining voice channel', ephemeral: true }); return await voiceInit(bot); } diff --git a/commands/leave.js b/commands/leave.js index 781bc0a..1577baa 100644 --- a/commands/leave.js +++ b/commands/leave.js @@ -29,6 +29,7 @@ export default { .setDescription('Leaves the voice chat') .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), async execute(interaction) { + if (!interaction.member.voice.channel) return await interaction.reply({ content: 'You need to be in a voice channel to use this command.', ephemeral: true }); console.log('Leaving voice channel...'); await destroyAudio(interaction); return await interaction.reply({ content: 'Leaving voice channel', ephemeral: true }); diff --git a/commands/next.js b/commands/next.js index b507cd1..88dac40 100644 --- a/commands/next.js +++ b/commands/next.js @@ -30,6 +30,7 @@ export default { .setDescription('Goes to next music') .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), async execute(interaction, bot) { + if (!interaction.member.voice.channel) return await interaction.reply({ content: 'You need to be in a voice channel to use this command.', ephemeral: true }); await interaction.reply({ content: 'Playing next music', ephemeral: true }); player.stop(); return await nextAudio(bot); diff --git a/commands/pause.js b/commands/pause.js index d5d8edc..c467675 100644 --- a/commands/pause.js +++ b/commands/pause.js @@ -29,6 +29,7 @@ export default { .setDescription('Pauses music') .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), async execute(interaction) { + if (!interaction.member.voice.channel) return await interaction.reply({ content: 'You need to be in a voice channel to use this command.', ephemeral: true }); if (isAudioStatePaused === false) { toggleAudioState(); return await interaction.reply({ content: 'Pausing music', ephemeral: true }); diff --git a/commands/play.js b/commands/play.js index fd8132c..3b226ec 100644 --- a/commands/play.js +++ b/commands/play.js @@ -38,6 +38,7 @@ export default { .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), async execute(interaction, bot) { + if (!interaction.member.voice.channel) return await interaction.reply({ content: 'You need to be in a voice channel to use this command.', ephemeral: true }); integer = interaction.options.getInteger('int'); if (integer) { if (integer < files.length) { diff --git a/commands/previous.js b/commands/previous.js index 6d5eff3..66c1930 100644 --- a/commands/previous.js +++ b/commands/previous.js @@ -29,6 +29,7 @@ export default { .setDescription('Goes to previous music') .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), async execute(interaction, bot) { + if (!interaction.member.voice.channel) return await interaction.reply({ content: 'You need to be in a voice channel to use this command.', ephemeral: true }); return await previousAudio(bot, interaction); } }; diff --git a/commands/reshuffle.js b/commands/reshuffle.js index 517c272..f60bb1c 100644 --- a/commands/reshuffle.js +++ b/commands/reshuffle.js @@ -20,10 +20,10 @@ ***************************************************************************/ import { SlashCommandBuilder } from 'discord.js'; -import { player } from '../backend/VoiceInitialization.js'; import { shufflePlaylist } from '../backend/QueueSystem.js'; import { PermissionFlagsBits } from 'discord-api-types/v10'; import { readFileSync } from 'node:fs'; +import { audioState } from '../backend/AudioControl.js'; // import config from './config.json' assert {type: 'json'} const { shuffle } = JSON.parse(readFileSync('./config.json', 'utf-8')); @@ -33,9 +33,10 @@ export default { .setDescription('Reshuffles the playlist') .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), async execute(interaction, bot) { + if (!interaction.member.voice.channel) return await interaction.reply({ content: 'You need to be in a voice channel to use this command.', ephemeral: true }); async function shuffleDetected(bot) { await interaction.reply({ content: 'Reshuffling the playlist...', ephemeral: true }); - player.stop(); + await audioState(2); await shufflePlaylist(bot); } return (shuffle === true) ? await shuffleDetected(bot) : await interaction.reply({ content: 'Shuffle mode is disabled, enable it in the configuration file to access this command.', ephemeral: true }); diff --git a/commands/status.js b/commands/status.js index 3143e16..cf49509 100644 --- a/commands/status.js +++ b/commands/status.js @@ -29,6 +29,7 @@ export default { .setName('status') .setDescription('Checks what audio file is playing currently'), async execute(interaction, bot) { + if (!interaction.member.voice.channel) return await interaction.reply({ content: 'You need to be in a voice channel to use this command.', ephemeral: true }); let audioID = currentTrack; audioID++;