diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2022-12-04 01:55:58 -0500 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2022-12-04 01:55:58 -0500 |
| commit | f91f277a30a081cde95805bf39adeb835be98c3f (patch) | |
| tree | 86c3c8c1299dcf33a180c87c16e7d37bade0291f /backend/AudioControl.js | |
| parent | c576ed4e454fe6b4974e7ad873670e3adc9d0a96 (diff) | |
| download | DLAP-f91f277a30a081cde95805bf39adeb835be98c3f.tar.gz DLAP-f91f277a30a081cde95805bf39adeb835be98c3f.tar.bz2 DLAP-f91f277a30a081cde95805bf39adeb835be98c3f.zip | |
Added repeat toggle; Did some optiminizations to the code
Diffstat (limited to 'backend/AudioControl.js')
| -rw-r--r-- | backend/AudioControl.js | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/backend/AudioControl.js b/backend/AudioControl.js index 71952c1..2b314d2 100644 --- a/backend/AudioControl.js +++ b/backend/AudioControl.js @@ -22,20 +22,31 @@ import { readdirSync, readFileSync } from 'node:fs'; import { shufflePlaylist, orderPlaylist } from './QueueSystem.js'; import { playAudio, currentTrack, updatePlaylist } from './PlayAudio.js'; import { player } from './VoiceInitialization.js'; +import { destroyAudio } from './Shutdown.js'; -const { shuffle } = JSON.parse(readFileSync('./config.json', 'utf-8')); +const { shuffle, repeat } = JSON.parse(readFileSync('./config.json', 'utf-8')); export const files = readdirSync('music'); export let playerState; export let isAudioStatePaused; let totalTrack = files.length; +async function repeatCheck(bot) { + if (repeat) { + console.log('All beats in the playlist has finished, repeating beats...'); + totalTrack = files.length; + return (shuffle) ? await shufflePlaylist(bot) : await orderPlaylist(bot); + } else { + console.log('All beats in the playlist has finished.'); + updatePlaylist('stop'); + audioState(2); + } +} + export async function nextAudio(bot) { totalTrack--; if (currentTrack >= totalTrack) { - console.log('All beats in the playlist has finished, repeating beats...'); - totalTrack = files.length; - return (shuffle === true) ? await shufflePlaylist(bot) : await orderPlaylist(bot); + await repeatCheck(bot); } else { updatePlaylist('next'); return await playAudio(bot); |
