diff --git a/crates/rustmail/src/commands/remove_reminder/slash_command/remove_reminder.rs b/crates/rustmail/src/commands/remove_reminder/slash_command/remove_reminder.rs index 08f5327e..bf85e5a4 100644 --- a/crates/rustmail/src/commands/remove_reminder/slash_command/remove_reminder.rs +++ b/crates/rustmail/src/commands/remove_reminder/slash_command/remove_reminder.rs @@ -100,7 +100,15 @@ impl RegistrableCommand for RemoveReminderCommand { }; let reminder = match get_reminder_by_id(reminder_id, pool).await { - Ok(Some(r)) => r, + Ok(Some(r)) => { + if r.completed { + return Err(ModmailError::Command( + CommandError::ReminderAlreadyCompleted(reminder_id.to_string()), + )); + } else { + r + } + } Ok(None) => { return Err(ModmailError::Database(DatabaseError::NotFound( "".to_string(), diff --git a/crates/rustmail/src/commands/remove_reminder/text_command/remove_reminder.rs b/crates/rustmail/src/commands/remove_reminder/text_command/remove_reminder.rs index 26a0c0fa..0323120a 100644 --- a/crates/rustmail/src/commands/remove_reminder/text_command/remove_reminder.rs +++ b/crates/rustmail/src/commands/remove_reminder/text_command/remove_reminder.rs @@ -38,7 +38,15 @@ pub async fn remove_reminder( }; let reminder = match get_reminder_by_id(reminder_id as i64, pool).await { - Ok(Some(r)) => r, + Ok(Some(r)) => { + if r.completed { + return Err(ModmailError::Command( + CommandError::ReminderAlreadyCompleted(reminder_id.to_string()), + )); + } else { + r + } + } Ok(None) => { return Err(ModmailError::Database(DatabaseError::NotFound( "".to_string(), diff --git a/crates/rustmail/src/errors/dictionary.rs b/crates/rustmail/src/errors/dictionary.rs index 7b36506c..5855b189 100644 --- a/crates/rustmail/src/errors/dictionary.rs +++ b/crates/rustmail/src/errors/dictionary.rs @@ -286,6 +286,11 @@ impl DictionaryManager { Some(params), ) } + CommandError::ReminderAlreadyCompleted(reminder_id) => { + let mut params = HashMap::new(); + params.insert("reminder_id".to_string(), reminder_id.clone()); + ("reminder.already_complete".to_string(), Some(params)) + } _ => ("command.invalid_format".to_string(), None), }, ModmailError::Thread(thread_err) => match thread_err { diff --git a/crates/rustmail/src/errors/types.rs b/crates/rustmail/src/errors/types.rs index 43ce0095..6bf721ba 100644 --- a/crates/rustmail/src/errors/types.rs +++ b/crates/rustmail/src/errors/types.rs @@ -75,6 +75,7 @@ pub enum CommandError { ReminderAlreadyUnsubscribed(String), ReminderRoleRequired(String), ReminderRoleNotFound(String), + ReminderAlreadyCompleted(String), } #[derive(Debug, Clone)] @@ -206,6 +207,9 @@ impl fmt::Display for CommandError { CommandError::ReminderRoleNotFound(role) => { write!(f, "Role {} not found", role) } + CommandError::ReminderAlreadyCompleted(reminder_id) => { + write!(f, "Reminder {} has already been completed", reminder_id) + } } } } diff --git a/crates/rustmail/src/i18n/language/en.rs b/crates/rustmail/src/i18n/language/en.rs index d6edf64e..82a4a3a7 100644 --- a/crates/rustmail/src/i18n/language/en.rs +++ b/crates/rustmail/src/i18n/language/en.rs @@ -786,6 +786,10 @@ pub fn load_english_messages(dict: &mut ErrorDictionary) { "⏰ Reminder for {roles} scheduled for **{time}** ({remaining_time})\n\n{content}", ), ); + dict.messages.insert( + "reminder.already_complete".to_string(), + DictionaryMessage::new("The reminder '#{reminder_id}' has already been completed."), + ); dict.messages.insert( "reminder.show_with_content".to_string(), DictionaryMessage::new("⏰ Reminder <@{user}>: \n\n{content} !"), diff --git a/crates/rustmail/src/i18n/language/fr.rs b/crates/rustmail/src/i18n/language/fr.rs index ab2b52d5..ccd6d9f0 100644 --- a/crates/rustmail/src/i18n/language/fr.rs +++ b/crates/rustmail/src/i18n/language/fr.rs @@ -822,6 +822,10 @@ pub fn load_french_messages(dict: &mut ErrorDictionary) { "reminder.show_without_content_roles".to_string(), DictionaryMessage::new("⏰ Rappel pour {roles} !"), ); + dict.messages.insert( + "reminder.already_complete".to_string(), + DictionaryMessage::new("Le rappel **#{reminder_id}** a déjà été complété."), + ); dict.messages.insert( "slash_command.add_reminder_command_description".to_string(), DictionaryMessage::new("Ajouter un rappel pour vous-même"),