diff --git a/src/commands/music/play.ts b/src/commands/music/play.ts index 8afeaae..439a4ea 100644 --- a/src/commands/music/play.ts +++ b/src/commands/music/play.ts @@ -13,6 +13,7 @@ import { discord_limit_autocompletion_list_length, discord_limit_autocompletion_value_length, } from "../../utils/constants"; +import { timeToString } from "../../utils/time"; export default { scope: () => [], @@ -179,12 +180,19 @@ export default { queue.node.play(); } - // TODO: When added to an existing queue (size of queue > 0): - // - Add position in queue - // - Add estimated time until playing - // https://git.mylloon.fr/ConfrerieDuKassoulait/Botanique/issues/184 + const positionEstimation = () => { + const pos = queue.node.getTrackPosition(result.tracks[0]) + 1; + + 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({ - content: `⏱️ | \`${title}\` ${loc.get("c_play5")}.`, + content: `⏱️ | \`${title}\` ${loc.get("c_play5")}, ${loc.get("c_play12")} : ${positionEstimation()}.`, }); }, diff --git a/src/locales/en-US.json b/src/locales/en-US.json index a45ce2b..ecbf532 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -96,6 +96,9 @@ "c_play7": "Currently playing", "c_play8": "Asked by", "c_play9": "No results were found", + "c_play10": "position", + "c_play11": "estimation", + "c_play12": "play", "c_stop_name": "stop", "c_stop_desc": "Stop the music", diff --git a/src/locales/fr.json b/src/locales/fr.json index 00316b0..65163d5 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -96,6 +96,9 @@ "c_play7": "Joue actuellement", "c_play8": "Demandé par", "c_play9": "Aucun résultat trouvé", + "c_play10": "position", + "c_play11": "estimation", + "c_play12": "joue", "c_stop_name": "stop", "c_stop_desc": "Stop la musique", diff --git a/src/utils/time.ts b/src/utils/time.ts index 0c719da..045e09d 100644 --- a/src/utils/time.ts +++ b/src/utils/time.ts @@ -94,14 +94,12 @@ export const strToSeconds = (time: string) => { }; /** - * Calculating the difference between a date and now - * @param lang Locale - * @param time Time - * @returns Delta between the time and now + * Returns the time in a readable way + * @param seconds Time in milliseconds + * @returns Time as string */ -export const timeDeltaToString = (time: number) => { - const now = Date.now(); - let secondsDifference = Math.abs(Math.ceil((time - now) / 1000)); +export const timeToString = (time: number) => { + let secondsDifference = Math.abs(Math.ceil(time / 1000)); if (secondsDifference === 0) { return "0s"; @@ -123,3 +121,13 @@ export const timeDeltaToString = (time: number) => { .filter(Boolean) .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); +};