From c5a04a85df7b61d32770defe169a512472461ab5 Mon Sep 17 00:00:00 2001 From: liyunze <50455574+liyunze-coding@users.noreply.github.com> Date: Tue, 6 Jan 2026 13:27:51 +0800 Subject: [PATCH] added delete faq command --- src/commands/faq.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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(()) +}