diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2022-04-03 16:43:47 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2022-04-03 16:43:47 -0400 |
| commit | a555449001cbe87503e5ffe9b311aceb59592c63 (patch) | |
| tree | bf2920c4532ca65b5837d459e46bbe53c893de76 /AudioBackend.js | |
| parent | daf3c1735513bb252614a0047116088e242f7984 (diff) | |
| download | DLAP-a555449001cbe87503e5ffe9b311aceb59592c63.tar.gz DLAP-a555449001cbe87503e5ffe9b311aceb59592c63.tar.bz2 DLAP-a555449001cbe87503e5ffe9b311aceb59592c63.zip | |
Audio states on control; Control can be ran once; Ping update, etc
Diffstat (limited to 'AudioBackend.js')
| -rw-r--r-- | AudioBackend.js | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/AudioBackend.js b/AudioBackend.js index 53acc61..b5d5be6 100644 --- a/AudioBackend.js +++ b/AudioBackend.js @@ -29,12 +29,16 @@ import { import { MessageEmbed } from 'discord.js' import config from './config.json' assert {type: 'json'} import { readdirSync, writeFile } from 'node:fs' +import {controlEmbed} from "./commands/control.js"; export const player = createAudioPlayer(); export let audio; export let files = readdirSync('music'); let fileData; +export let playerState; +let isAudioStatePaused; + export async function voiceInit(bot) { bot.channels.fetch(config.voiceChannel).then(async channel => { const connection = joinVoiceChannel({ @@ -52,7 +56,7 @@ export async function voiceInit(bot) { }); player.on('idle', () => { - console.log("Beat has finished playing, shuffling the beats...") + console.log("Beat has finished playing, shuffling the beats..."); searchAudio(bot); }) @@ -76,14 +80,17 @@ export async function inputAudio(bot, integer) { export async function playAudio(bot) { let resource = createAudioResource('music/' + audio); - await player.play(resource); + player.play(resource); console.log('Now playing: ' + audio); + playerState = "Playing" + isAudioStatePaused = false + audio = audio.split('.').slice(0, -1).join('.'); if (config.txtFile === true) { - fileData = "Now Playing: " + audio; + fileData = "Now Playing: " + audio writeFile("./now-playing.txt", fileData, (err) => { if (err) console.log(err); @@ -100,7 +107,7 @@ export async function playAudio(bot) { } -export function destroyAudio(interaction) { +export async function destroyAudio(interaction) { if (config.txtFile === true) { fileData = "Now Playing: Nothing"; writeFile("now-playing.txt", fileData, (err) => { @@ -109,10 +116,25 @@ export function destroyAudio(interaction) { }); } - audio = "Not Playing"; - player.stop(); + audio = "Not Playing" + playerState = "Stopped" + isAudioStatePaused = true + const connection = getVoiceConnection(interaction.guild.id); - return connection.destroy(); + if (VoiceConnectionStatus.Ready) { + player.stop(); + return connection.destroy(); + } +} + +export function audioState() { + if (isAudioStatePaused === false) { + isAudioStatePaused = true + playerState = "Paused" + } else if (isAudioStatePaused === true) { + isAudioStatePaused = false + playerState = "Playing" + } } export async function stopBot(bot, interaction) { @@ -125,7 +147,7 @@ export async function stopBot(bot, interaction) { await statusChannel.send({embeds: [statusEmbed]}); console.log('Powering off...'); - destroyAudio(interaction); + await destroyAudio(interaction); bot.destroy(); return process.exit(0); }
\ No newline at end of file |
