added delete faq command
This commit is contained in:
parent
56f28d5891
commit
c5a04a85df
1 changed files with 34 additions and 0 deletions
|
|
@ -202,3 +202,37 @@ pub async fn edit(
|
||||||
|
|
||||||
Ok(())
|
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(())
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue