add pos in queue and estimated playtime (fix #184)
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 28s
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 28s
This commit is contained in:
parent
30968bcd5b
commit
76b10b1469
4 changed files with 34 additions and 12 deletions
|
@ -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()}.`,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -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);
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue