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 @@ - - - - - - RandomMemer upload sounds - - - - -
- Logo -
-
-
-
-
-

Upload Sound

-
- File: - -
- + + + + + + RandomMemer upload sounds + + + +
+
+
+ Logo + +

Upload a sound

+
+
+
+ +
- +
+
+ + -
-

Info

-
-
-
+
+ Endpoint not loading!?
- -
-
-

Uploaded Files

-
- -
-
+ +
+

Uploaded Files

+
    - - - - +
    + + + + + + \ No newline at end of file diff --git a/client/webserver.ts b/client/webserver.ts index 479c24f..909624c 100644 --- a/client/webserver.ts +++ b/client/webserver.ts @@ -32,6 +32,9 @@ app.post('/upload', upload.single('myFile'), async (req, res) => { res.send('File uploaded successfully.'); }); +// create a enpoint to return a file from the sounds folder (use the file name) with as little code as possible +app.use('/sounds', express.static(path.join(__dirname, '../sounds'))); + app.get('/sounds', (_req, res) => { const fs = require('fs'); const directoryPath = path.join(__dirname, '../sounds'); diff --git a/sounds/1697309103654-Rev Up Those Fryers!.mp3 b/sounds/1697309103654-Rev Up Those Fryers!.mp3 new file mode 100644 index 0000000..25d1415 Binary files /dev/null and b/sounds/1697309103654-Rev Up Those Fryers!.mp3 differ diff --git a/sounds/badsalt.mp3 b/sounds/badsalt.mp3 deleted file mode 100644 index 5b5a717..0000000 Binary files a/sounds/badsalt.mp3 and /dev/null differ