Compare commits

..

No commits in common. "208dbf0813baf4cc74e5dff49a8f13dfbccc315d" and "f9cc154b040d46d7943f66d78a676d871c85464c" have entirely different histories.

4 changed files with 25 additions and 33 deletions

View file

@ -60,14 +60,14 @@
"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.",
"c_reminder5": "Reminders of",
"c_reminder6": "Page",
"c_reminder7": "No message",
"c_reminder8": "Expires",
"c_reminder8": "Expires in",
"c_reminder9": "Do on",
"c_reminder10": "The user has no pending reminders or page no.",
"c_reminder11": "empty",
@ -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",

View file

@ -60,14 +60,14 @@
"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.",
"c_reminder5": "Rappels de",
"c_reminder6": "Page",
"c_reminder7": "Pas de message",
"c_reminder8": "Expire",
"c_reminder8": "Expire dans",
"c_reminder9": "Fais le",
"c_reminder10": "L'utilisateur n'a aucun rappel en attente ou page n°",
"c_reminder11": "vide",
@ -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",

View file

@ -88,8 +88,6 @@ export const newReminder = async (client: Client, time: string, info: infoRemind
const timeoutId = setTimeoutReminder(client, info, data.option, timeout);
const expiration_date = info.createdAt + timeout * 1000;
// Add the remind to the db
client.db.run(
"INSERT INTO reminder ( \
@ -97,7 +95,7 @@ export const newReminder = async (client: Client, time: string, info: infoRemind
) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? );",
[
info.message,
`${expiration_date}`,
`${info.createdAt + timeout * 1000}`,
data.option.valueOf(),
info.channelId,
`${info.createdAt}`,
@ -112,7 +110,7 @@ export const newReminder = async (client: Client, time: string, info: infoRemind
}
// Send confirmation to user
ok(`${loc.get("c_reminder1")} ${timeDeltaToString(info.locale, expiration_date)}.`);
ok(`${loc.get("c_reminder1")} ${data.time}.`);
},
);
});
@ -193,7 +191,7 @@ export const sendReminder = (client: Client, info: infoReminder, option: OptionR
if (channel?.isSendable()) {
let content = `<@${info.userId}>`;
embed.setFooter({
text: timeDeltaToString(info.locale, info.createdAt).capitalize(),
text: `${loc.get("c_reminder17")} ${timeDeltaToString(info.createdAt)}`,
});
// Mention everybody if needed
@ -426,7 +424,7 @@ export const embedListReminders = async (
if (text.length > 1024) {
text = `${text.substring(0, 1021)}...`;
}
const expiration = `${loc.get("c_reminder8")} ${timeDeltaToString(local, remind.expiration_date)}`;
const expiration = `${loc.get("c_reminder8")} ${timeDeltaToString(remind.expiration_date)}`;
embed.addFields({
name: `#${remind.id}${loc.get("c_reminder9")} ${showDate(
local,

View file

@ -3,15 +3,15 @@ import { RegexC, RegExpFlags } from "./regex";
/**
* Parsed string adapted with TZ (locales) and format for the specified lang
* @param lang Locale
* @param translation Translation for "at"
* @param tz Lang
* @param locale Locales
* @param date Date
* @returns String
*/
export const showDate = (lang: string, translation: Map<string, unknown>, date: Date) => {
const localeInfo = new Intl.Locale(lang);
export const showDate = (tz: string, locale: Map<string, unknown>, date: Date) => {
const localeInfo = new Intl.Locale(tz);
const intlTimezone = moment.tz.zonesForCountry(localeInfo.region ?? localeInfo.baseName);
const formattedDate = new Intl.DateTimeFormat(lang, {
const formattedDate = new Intl.DateTimeFormat(tz, {
timeZone: intlTimezone ? intlTimezone[0] : "Factory",
dateStyle: "short",
timeStyle: "medium",
@ -19,14 +19,14 @@ export const showDate = (lang: string, translation: Map<string, unknown>, date:
.format(date)
.split(" ");
return `${formattedDate[0]} ${translation.get("u_time_at")} ${formattedDate[1]}`;
return `${formattedDate[0]} ${locale.get("u_time_at")} ${formattedDate[1]}`;
};
export enum TimeSecond {
Year = 60 * 60 * 24 * 365,
Week = 60 * 60 * 24 * 7,
Day = 60 * 60 * 24,
Hour = 60 * 60,
Year = 31536000,
Week = 604800,
Day = 86400,
Hour = 3600,
Minute = 60,
Second = 1,
}
@ -95,21 +95,13 @@ 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
*/
export const timeDeltaToString = (lang: string, time: number) => {
export const timeDeltaToString = (time: number) => {
const now = Date.now();
const secondsDifference = Math.round((time - now) / 1000) - 2;
const rtf = new Intl.RelativeTimeFormat(lang, { numeric: "auto" });
for (const [unit, value] of Object.entries(TimeSecond)) {
const delta = secondsDifference / (value as number);
if (delta >= 1) {
return rtf.format(Math.round(delta), unit.toLowerCase() as Intl.RelativeTimeFormatUnit);
}
}
return rtf.format(secondsDifference, "second");
// TODO: adapt the output and not always parse the time as seconds
// https://git.mylloon.fr/ConfrerieDuKassoulait/Botanique/issues/189
// Use Intl.RelativeTimeFormat ?
return `${strToSeconds(`${(now - time) / 1000}`)} secs`;
};