chore: merge branch dev to main #200

Merged
Anri merged 19 commits from dev into main 2024-11-02 17:36:38 +01:00
4 changed files with 34 additions and 12 deletions
Showing only changes of commit 76b10b1469 - Show all commits

View file

@ -13,6 +13,7 @@ import {
discord_limit_autocompletion_list_length, discord_limit_autocompletion_list_length,
discord_limit_autocompletion_value_length, discord_limit_autocompletion_value_length,
} from "../../utils/constants"; } from "../../utils/constants";
import { timeToString } from "../../utils/time";
export default { export default {
scope: () => [], scope: () => [],
@ -179,12 +180,19 @@ export default {
queue.node.play(); queue.node.play();
} }
// TODO: When added to an existing queue (size of queue > 0): const positionEstimation = () => {
// - Add position in queue const pos = queue.node.getTrackPosition(result.tracks[0]) + 1;
// - Add estimated time until playing
// https://git.mylloon.fr/ConfrerieDuKassoulait/Botanique/issues/184 if (pos === 0) {
return loc.get("c_play_sub2_name");
}
return `${loc.get("c_play10")} ${pos} (${loc.get("c_play11")}${estimation})`;
};
const estimation = timeToString(queue.estimatedDuration);
return await interaction.followUp({ return await interaction.followUp({
content: `⏱️ | \`${title}\` ${loc.get("c_play5")}.`, content: `⏱️ | \`${title}\` ${loc.get("c_play5")}, ${loc.get("c_play12")} : ${positionEstimation()}.`,
}); });
}, },

View file

@ -96,6 +96,9 @@
"c_play7": "Currently playing", "c_play7": "Currently playing",
"c_play8": "Asked by", "c_play8": "Asked by",
"c_play9": "No results were found", "c_play9": "No results were found",
"c_play10": "position",
"c_play11": "estimation",
"c_play12": "play",
"c_stop_name": "stop", "c_stop_name": "stop",
"c_stop_desc": "Stop the music", "c_stop_desc": "Stop the music",

View file

@ -96,6 +96,9 @@
"c_play7": "Joue actuellement", "c_play7": "Joue actuellement",
"c_play8": "Demandé par", "c_play8": "Demandé par",
"c_play9": "Aucun résultat trouvé", "c_play9": "Aucun résultat trouvé",
"c_play10": "position",
"c_play11": "estimation",
"c_play12": "joue",
"c_stop_name": "stop", "c_stop_name": "stop",
"c_stop_desc": "Stop la musique", "c_stop_desc": "Stop la musique",

View file

@ -94,14 +94,12 @@ export const strToSeconds = (time: string) => {
}; };
/** /**
* Calculating the difference between a date and now * Returns the time in a readable way
* @param lang Locale * @param seconds Time in milliseconds
* @param time Time * @returns Time as string
* @returns Delta between the time and now
*/ */
export const timeDeltaToString = (time: number) => { export const timeToString = (time: number) => {
const now = Date.now(); let secondsDifference = Math.abs(Math.ceil(time / 1000));
let secondsDifference = Math.abs(Math.ceil((time - now) / 1000));
if (secondsDifference === 0) { if (secondsDifference === 0) {
return "0s"; return "0s";
@ -123,3 +121,13 @@ export const timeDeltaToString = (time: number) => {
.filter(Boolean) .filter(Boolean)
.join(" "); .join(" ");
}; };
/**
* Calculating the difference between a date and now
* @param time Time in milliseconds
* @returns Delta between the time and now
*/
export const timeDeltaToString = (time: number) => {
const now = Date.now();
return timeToString(time - now);
};