diff --git a/README.md b/README.md index a32abb5..95cf817 100644 --- a/README.md +++ b/README.md @@ -74,3 +74,12 @@ _See old steps of the roadmap at [archives/TODO.md](./archives/TODO.md)_ - [ ] Fix "I'll be back" features and creates a disabling method [Planned before 1.0 realease] - [ ] Add multi-language support (English/French to start) [Planned before 1.0 realease] - [ ] Add Smart Assistant support [No plan] + +#### ENVIRONMENT VARIABLES + +| VARIABLE | REQUIRED | DEFAULT | USED ONLY FOR DOCKER | DESCRIPTION | +| -------------- | -------- | ------------ | -------------------- | ------------------------------------------ | +| BOT_TOKEN | TRUE | | FALSE | Your discord app token | +| TRIGGER_PREFIX | FALSE | & | FALSE | Your bot prefix | +| LOG_DIR | FALSE | /log | TRUE | Your logging directory path use for docker | +| TIMEZONE | FALSE | Europe/Paris | TRUE | Your container timezone | diff --git a/app.js b/app.js index 44f8196..e8e365d 100644 --- a/app.js +++ b/app.js @@ -26,7 +26,7 @@ const clientDiscord = new Client({ ], }); -const PREFIX = process.env.TRIGGER_PREFIX; +const PREFIX = process.env.TRIGGER_PREFIX || "&"; const queue = new Map(); const actions = require("./components/action_function"); diff --git a/components/action_function.js b/components/action_function.js index 4ea8e24..ecd332a 100644 --- a/components/action_function.js +++ b/components/action_function.js @@ -5,11 +5,16 @@ const embed_constructor = require("./embed_constructor"); const play = async (guild, song, queue) => { const serverQueue = queue.get(guild.id); + if (!song) { queue.delete(guild.id); try { if (serverQueue) { serverQueue.connection.destroy(); + serverQueue.player.stop(); + serverQueue.songs = []; + serverQueue.playing = false; + serverQueue.connectedToVoiceChannel = false; } } catch (e) { console.log("Connection already destroyed"); @@ -31,7 +36,10 @@ const play = async (guild, song, queue) => { serverQueue.player.play(stream); - serverQueue.connection.subscribe(serverQueue.player); + if (!serverQueue.connectedToVoiceChannel) { + serverQueue.connectedToVoiceChannel = true; + serverQueue.connection.subscribe(serverQueue.player); + } serverQueue.player.on(AudioPlayerStatus.Idle, () => { serverQueue.songs.shift(); @@ -77,6 +85,10 @@ const stop = (message, serverQueue, queue) => { try { serverQueue.connection.destroy(); + serverQueue.player.stop(); + serverQueue.songs = []; + serverQueue.playing = false; + serverQueue.connectedToVoiceChannel = false; } catch (e) { console.log("Connection already destroyed"); console.log(e); diff --git a/components/bases.js b/components/bases.js index 9428409..de00198 100644 --- a/components/bases.js +++ b/components/bases.js @@ -60,6 +60,17 @@ exports.errors = (errorMsg, message) => { }); }; +exports.formatTimeDisplay = (time) => { + const parts = time.split(":"); + const minutes = parts[0]; + const seconds = parts[1]; + + // Ajoute un zéro initial si les secondes sont inférieures à 10 + const formattedSeconds = seconds < 10 ? `0${seconds}` : seconds; + + return `${minutes}:${formattedSeconds}`; +}; + /* *************** Exemple for logging diff --git a/components/embed_constructor.js b/components/embed_constructor.js index d5234a1..c81f050 100644 --- a/components/embed_constructor.js +++ b/components/embed_constructor.js @@ -33,7 +33,7 @@ exports.new = (song, message, PREFIX) => { }, { name: "Durée :", - value: song.videoLength, + value: require("./bases").formatTimeDisplay(song.videoLength), } ); }; @@ -120,7 +120,7 @@ exports.added = (song, message, PREFIX) => { }, { name: "Durée :", - value: song.videoLength, + value: require("./bases").formatTimeDisplay(song.videoLength), } ); }; @@ -138,7 +138,11 @@ exports.queue = (songsList) => { } else { tabEmbeds.push({ name: index + 1 + ". " + song.title, - value: song.videoAuthor + ", " + song.videoLength + " minutes.", + value: + song.videoAuthor + + ", " + + require("./bases").formatTimeDisplay(song.videoLength) + + " minutes.", }); } }); diff --git a/components/queue_constructor.js b/components/queue_constructor.js index 6d17bb8..cb59d5d 100644 --- a/components/queue_constructor.js +++ b/components/queue_constructor.js @@ -41,6 +41,7 @@ const queue_create = async ( songs: [], volume: 5, playing: true, + connectedToVoiceChannel: false, }; queue.set(message.guild.id, queueContruct); diff --git a/docker-compose.yml b/docker-compose.yml index 27e247f..cfd3ec3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,4 +17,4 @@ services: #VOICE_CHANNEL_ID: ${VOICE_CHANNEL_ID} #USER_ID: ${USER_ID} volumes: - - ${LOG_DIR}:/stroycord_app/logs:rw + - ${LOG_DIR:-logs}:/stroycord_app/logs:rw