merge dev to main #169

Merged
Anri merged 6 commits from dev into main 2024-09-17 22:57:55 +02:00
5 changed files with 32 additions and 7 deletions
Showing only changes of commit 0de9aecb89 - Show all commits

View file

@ -158,12 +158,19 @@ export default {
channelId: interaction.channelId, channelId: interaction.channelId,
userId: interaction.user.id, userId: interaction.user.id,
guildId: interaction.guildId, guildId: interaction.guildId,
}).then((msg) => })
.then((msg) =>
interaction.reply({ interaction.reply({
content: msg as string, content: msg as string,
ephemeral: true, ephemeral: true,
}), }),
); )
.catch((err) => {
interaction.reply({
content: err,
ephemeral: true,
});
});
} else { } else {
// Show modal to user to get at least the time // Show modal to user to get at least the time
const modal = new ModalBuilder() const modal = new ModalBuilder()

View file

@ -77,6 +77,7 @@
"c_reminder15": "Message sent in DM because you have left", "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_reminder16": "Message sent in DM because the Discord guild is no longer available.",
"c_reminder17": "Message from", "c_reminder17": "Message from",
"c_reminder18": "Invalid time, try again.",
"c_play_name": "play", "c_play_name": "play",
"c_play_desc": "Plays a song/playlist, no query displays the now playing song", "c_play_desc": "Plays a song/playlist, no query displays the now playing song",

View file

@ -77,6 +77,7 @@
"c_reminder15": "Message envoyé en DM car vous avez quitté", "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_reminder16": "Message envoyé en DM car le serveur Discord n'est plus disponible.",
"c_reminder17": "Message d'il y a", "c_reminder17": "Message d'il y a",
"c_reminder18": "Temps invalide, réessayez.",
"c_play_name": "play", "c_play_name": "play",
"c_play_desc": "Joue une chanson/playlist, pas de requête affiche la chanson en cours actuellement", "c_play_desc": "Joue une chanson/playlist, pas de requête affiche la chanson en cours actuellement",

View file

@ -64,8 +64,15 @@ const splitTime = (time: string) => {
*/ */
export const newReminder = async (client: Client, time: string, info: infoReminder) => export const newReminder = async (client: Client, time: string, info: infoReminder) =>
new Promise((ok, ko) => { new Promise((ok, ko) => {
const loc = getLocale(client, info.locale);
const data = splitTime(time); const data = splitTime(time);
const timeout = strToSeconds(data.time); const timeout = strToSeconds(data.time);
if (timeout < 0) {
ko(loc.get("c_reminder18"));
return;
}
const timeoutId = setTimeoutReminder(client, info, data.option, timeout); const timeoutId = setTimeoutReminder(client, info, data.option, timeout);
// Add the remind to the db // Add the remind to the db
@ -90,7 +97,6 @@ export const newReminder = async (client: Client, time: string, info: infoRemind
} }
// Send confirmation to user // Send confirmation to user
const loc = getLocale(client, info.locale);
ok(`${loc.get("c_reminder1")} ${data.time}.`); ok(`${loc.get("c_reminder1")} ${data.time}.`);
}, },
); );

View file

@ -24,6 +24,11 @@ enum TimeSecond {
* @returns time in seconds * @returns time in seconds
*/ */
export const strToSeconds = (time: string) => { export const strToSeconds = (time: string) => {
if (time.length > 15) {
// 15 is a magic value, weird to be this long
return -1;
}
const regex = new RegExp( const regex = new RegExp(
`(?<${TimeSecond[TimeSecond.Year]}>[0-9]+(?=[y|a]))|(?<${ `(?<${TimeSecond[TimeSecond.Year]}>[0-9]+(?=[y|a]))|(?<${
TimeSecond[TimeSecond.Week] TimeSecond[TimeSecond.Week]
@ -36,6 +41,11 @@ export const strToSeconds = (time: string) => {
const data = Object.assign({}, regex.exec(time.toLowerCase())?.groups); const data = Object.assign({}, regex.exec(time.toLowerCase())?.groups);
if (Object.keys(data).length === 0) {
// Regex returned an invalid time
return -1;
}
let res = 0; let res = 0;
Object.entries(data).forEach(([key, value]) => { Object.entries(data).forEach(([key, value]) => {
if (value) { if (value) {