diff --git a/src/commands/faq.rs b/src/commands/faq.rs index 0cc723b..03a3a47 100644 --- a/src/commands/faq.rs +++ b/src/commands/faq.rs @@ -202,3 +202,37 @@ pub async fn edit( Ok(()) } + +/// Delete FAQ +#[poise::command( + prefix_command, + slash_command, + required_permissions = "MANAGE_MESSAGES" +)] +pub async fn delete( + ctx: Context<'_>, + #[description = "FAQ Title"] + #[autocomplete = "autocomplete_faq_titles"] + title: String, +) -> Result<(), Error> { + let data = ctx.data(); + + let result = data + .execute_db({ + let title = title.clone(); + move |conn| conn.execute("DELETE FROM faqs WHERE title = ?1", [title]) + }) + .await?; + + if result == 1 { + let embed = CreateEmbed::new().title(format!("Deleted FAQ: {}", &title)); + ctx.send(CreateReply::default().embed(embed)).await?; + } else { + let embed = CreateEmbed::new() + .title(format!("Error deleting FAQ: {}", &title)) + .description(format!("{} rows were affected", result)); + ctx.send(CreateReply::default().embed(embed)).await?; + } + + Ok(()) +}