Fixed duration date; More stop functions; Required in voice channel

This commit is contained in:
Andrew Lee 2022-12-02 00:31:17 -05:00
parent ebdf6e92b1
commit e0fe64b06c
Signed by: andrew
GPG key ID: 4DCE67C47836D125
11 changed files with 15 additions and 13 deletions

View file

@ -76,7 +76,9 @@ export function audioState(state) {
break;
case 2:
playerState = 'Stopped';
totalTrack = files.length;
isAudioStatePaused = true;
player.stop();
break;
}
}

View file

@ -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];

1
bot.js
View file

@ -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
*/

View file

@ -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);
}

View file

@ -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 });

View file

@ -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);

View file

@ -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 });

View file

@ -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) {

View file

@ -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);
}
};

View file

@ -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 });

View file

@ -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++;