add pos in queue and estimated playtime (fix #184)
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 28s

This commit is contained in:
Mylloon 2024-11-01 18:51:52 +01:00
parent 30968bcd5b
commit 76b10b1469
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 34 additions and 12 deletions

View file

@ -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()}.`,
});
},

View file

@ -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",

View file

@ -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",

View file

@ -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);
};