diff --git a/bot.ts b/bot.ts index 8438c69..61f992e 100644 --- a/bot.ts +++ b/bot.ts @@ -92,6 +92,13 @@ async function joinRandomChannel(retries = 12) { await entersState(connection, VoiceConnectionStatus.Ready, 30e3); const soundFiles = fileSystem.readdirSync(soundsDir).filter(file => file.endsWith('.mp3')); const soundFile = soundsDir + soundFiles[Math.floor(Math.random() * soundFiles.length)]; + + if(!soundFile) { + console.log(LoggerColors.Red, 'No sound files found'); + scheduleNextJoin(); + return; + } + const resource = createAudioResource(soundFile); const player = createAudioPlayer(); diff --git a/client/web/client.js b/client/web/client.js index dccb80f..a5fb14f 100644 --- a/client/web/client.js +++ b/client/web/client.js @@ -1,3 +1,11 @@ +document.addEventListener('DOMContentLoaded', (event) => { + document.querySelector('#myFile').addEventListener('change', function(e) { + var fileName = e.target.files[0].name; + var nextSibling = e.target.nextElementSibling + nextSibling.innerText = fileName + }) +}); + function loadNextPlaybackTime() { fetch('/nextplaybacktime') .then(response => response.text()) @@ -24,20 +32,35 @@ function loadFiles() { data.forEach(file => { // Create a new list item const li = document.createElement('li'); - li.className = 'grid-x'; + li.className = 'list-group-item list-group-item-action d-flex justify-content-between align-items-center' // Create a div for the file name and add it to the list item const fileNameDiv = document.createElement('div'); - fileNameDiv.className = 'cell auto'; fileNameDiv.textContent = file; li.appendChild(fileNameDiv); - // Create a div for the trash icon and add it to the list item - const trashIconDiv = document.createElement('div'); - trashIconDiv.className = 'cell shrink'; + // Create a div for the icons and add it to the list item + const iconDiv = document.createElement('div'); + li.appendChild(iconDiv); + + // Create a div for the play icon and add it to the icon div + const playIconDiv = document.createElement('span'); + playIconDiv.style.cursor = 'pointer'; + playIconDiv.textContent = '▶️'; + iconDiv.appendChild(playIconDiv); + + // Attach a click event listener to the play icon div + playIconDiv.addEventListener('click', () => { + // Create a new audio object and play the file + let audio = new Audio('/sounds/' + file); + audio.play(); + }); + + // Create a div for the trash icon and add it to the icon div + const trashIconDiv = document.createElement('span'); trashIconDiv.style.cursor = 'pointer'; trashIconDiv.textContent = '🗑️'; - li.appendChild(trashIconDiv); + iconDiv.appendChild(trashIconDiv); // Attach a click event listener to the trash icon div trashIconDiv.addEventListener('click', () => { @@ -60,6 +83,7 @@ function loadFiles() { .catch(error => console.error('Error:', error)); } + // Call loadFiles when the script is loaded loadFiles(); loadNextPlaybackTime(); diff --git a/client/web/index.html b/client/web/index.html index d36c920..ea7065c 100644 --- a/client/web/index.html +++ b/client/web/index.html @@ -1,49 +1,43 @@ - -
- - - -