Skip to content

Commit

Permalink
Fix seconds display
Browse files Browse the repository at this point in the history
  • Loading branch information
DestroyCom committed Aug 20, 2023
1 parent b9233a1 commit b4fe706
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 6 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
14 changes: 13 additions & 1 deletion components/action_function.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions components/bases.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions components/embed_constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports.new = (song, message, PREFIX) => {
},
{
name: "Durée :",
value: song.videoLength,
value: require("./bases").formatTimeDisplay(song.videoLength),
}
);
};
Expand Down Expand Up @@ -120,7 +120,7 @@ exports.added = (song, message, PREFIX) => {
},
{
name: "Durée :",
value: song.videoLength,
value: require("./bases").formatTimeDisplay(song.videoLength),
}
);
};
Expand All @@ -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.",
});
}
});
Expand Down
1 change: 1 addition & 0 deletions components/queue_constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const queue_create = async (
songs: [],
volume: 5,
playing: true,
connectedToVoiceChannel: false,
};

queue.set(message.guild.id, queueContruct);
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b4fe706

Please sign in to comment.