simplify code
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 16s
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 16s
This commit is contained in:
parent
56762aaa05
commit
095aa7f68c
4 changed files with 23 additions and 46 deletions
|
@ -60,7 +60,7 @@
|
|||
"c_reminder_sub3_desc": "Delete a reminder",
|
||||
"c_reminder_sub3_opt1_name": "id",
|
||||
"c_reminder_sub3_opt1_desc": "Reminder to be deleted",
|
||||
"c_reminder1": "A reminder has been set up for",
|
||||
"c_reminder1": "A reminder has been set up for in",
|
||||
"c_reminder2": "The ID entered is not valid.",
|
||||
"c_reminder3": "Reminder not found, not in the right guild, or not belonging to you.",
|
||||
"c_reminder4": "Unknown user.",
|
||||
|
@ -76,6 +76,7 @@
|
|||
"c_reminder14": "Message sent in DM as the channel is no longer available.",
|
||||
"c_reminder15": "Message sent in DM because you have left",
|
||||
"c_reminder16": "Message sent in DM because the Discord guild is no longer available.",
|
||||
"c_reminder17": "Message from",
|
||||
"c_reminder18": "Invalid time, try again.",
|
||||
|
||||
"c_play_name": "play",
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
"c_reminder_sub3_desc": "Supprime un rappel",
|
||||
"c_reminder_sub3_opt1_name": "id",
|
||||
"c_reminder_sub3_opt1_desc": "Rappel à supprimé",
|
||||
"c_reminder1": "Un rappel a été configuré pour",
|
||||
"c_reminder1": "Un rappel a été configuré pour dans",
|
||||
"c_reminder2": "L'ID renseigné n'est pas valide.",
|
||||
"c_reminder3": "Rappel non trouvé, pas sur le bon serveur ou qui ne vous appartiens pas.",
|
||||
"c_reminder4": "Utilisateur inconnu.",
|
||||
|
@ -76,6 +76,7 @@
|
|||
"c_reminder14": "Message envoyé en DM car le salon n'est plus disponible.",
|
||||
"c_reminder15": "Message envoyé en DM car vous avez quitté",
|
||||
"c_reminder16": "Message envoyé en DM car le serveur Discord n'est plus disponible.",
|
||||
"c_reminder17": "Message d'il y a",
|
||||
"c_reminder18": "Temps invalide, réessayez.",
|
||||
|
||||
"c_play_name": "play",
|
||||
|
|
|
@ -193,7 +193,7 @@ export const sendReminder = (client: Client, info: infoReminder, option: OptionR
|
|||
if (channel?.isSendable()) {
|
||||
let content = `<@${info.userId}>`;
|
||||
embed.setFooter({
|
||||
text: timeDeltaToString(info.createdAt).capitalize(),
|
||||
text: `${loc.get("c_reminder17")} ${timeDeltaToString(info.createdAt)}`,
|
||||
});
|
||||
|
||||
// Mention everybody if needed
|
||||
|
|
|
@ -101,50 +101,25 @@ export const strToSeconds = (time: string) => {
|
|||
*/
|
||||
export const timeDeltaToString = (time: number) => {
|
||||
const now = Date.now();
|
||||
let secondsDifference = Math.round((time - now) / 1000);
|
||||
let secondsDifference = Math.abs(Math.ceil((time - now) / 1000) - 2);
|
||||
|
||||
// Initialize variables to hold the time components
|
||||
let years = 0,
|
||||
weeks = 0,
|
||||
days = 0,
|
||||
hours = 0,
|
||||
minutes = 0,
|
||||
seconds = 0;
|
||||
|
||||
// Calculate the time components
|
||||
if (secondsDifference >= TimeSecond.Year) {
|
||||
years = Math.floor(secondsDifference / TimeSecond.Year);
|
||||
secondsDifference -= years * TimeSecond.Year;
|
||||
}
|
||||
if (secondsDifference >= TimeSecond.Week) {
|
||||
weeks = Math.floor(secondsDifference / TimeSecond.Week);
|
||||
secondsDifference -= weeks * TimeSecond.Week;
|
||||
}
|
||||
if (secondsDifference >= TimeSecond.Day) {
|
||||
days = Math.floor(secondsDifference / TimeSecond.Day);
|
||||
secondsDifference -= days * TimeSecond.Day;
|
||||
}
|
||||
if (secondsDifference >= TimeSecond.Hour) {
|
||||
hours = Math.floor(secondsDifference / TimeSecond.Hour);
|
||||
secondsDifference -= hours * TimeSecond.Hour;
|
||||
}
|
||||
if (secondsDifference >= TimeSecond.Minute) {
|
||||
minutes = Math.floor(secondsDifference / TimeSecond.Minute);
|
||||
secondsDifference -= minutes * TimeSecond.Minute;
|
||||
if (secondsDifference === 0) {
|
||||
return "0s";
|
||||
}
|
||||
|
||||
// Remaining seconds
|
||||
seconds = secondsDifference;
|
||||
|
||||
// Create the detailed time string
|
||||
const detailedTimeParts = [];
|
||||
if (years > 0) detailedTimeParts.push(`${years}y`);
|
||||
if (weeks > 0) detailedTimeParts.push(`${weeks}w`);
|
||||
if (days > 0) detailedTimeParts.push(`${days}d`);
|
||||
if (hours > 0) detailedTimeParts.push(`${hours}h`);
|
||||
if (minutes > 0) detailedTimeParts.push(`${minutes}m`);
|
||||
if (seconds > 0) detailedTimeParts.push(`${seconds}s`);
|
||||
|
||||
// Return the formatted string
|
||||
return detailedTimeParts.join(" ");
|
||||
return Object.entries(TimeSecond)
|
||||
.map(([key, value]) => ({
|
||||
label: key.charAt(0).toLowerCase(),
|
||||
value: value as TimeSecond,
|
||||
}))
|
||||
.map(({ label, value }) => {
|
||||
if (secondsDifference >= value) {
|
||||
const amount = Math.floor(secondsDifference / value);
|
||||
secondsDifference -= amount * value;
|
||||
return `${amount}${label}`;
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.filter(Boolean)
|
||||
.join(" ");
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue