From 5ce9cf8e73ed46db194d610eb62f4057ba7a36de Mon Sep 17 00:00:00 2001 From: liyunze <50455574+liyunze-coding@users.noreply.github.com> Date: Thu, 8 Jan 2026 08:57:30 +0800 Subject: [PATCH] added FAQ preview --- src/commands/faq.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/commands/faq.rs b/src/commands/faq.rs index 4cc768b..b9772db 100644 --- a/src/commands/faq.rs +++ b/src/commands/faq.rs @@ -67,7 +67,7 @@ async fn autocomplete_faq_titles<'a>( .map(|faq| faq.title) } -#[poise::command(slash_command, subcommands("view", "add", "edit", "delete"), guild_only)] +#[poise::command(slash_command, subcommands("view", "preview", "add", "edit", "delete"), guild_only)] pub async fn faq(_ctx: Context<'_>) -> Result<(), Error> { Ok(()) } @@ -119,6 +119,59 @@ pub async fn view( Ok(()) } +/// Preview FAQ +#[poise::command(prefix_command, slash_command)] +pub async fn preview( + ctx: Context<'_>, + #[description = "FAQ Title"] + #[autocomplete = "autocomplete_faq_titles"] + faq_title: String, +) -> Result<(), Error> { + let data = ctx.data(); + + let faqs = data + .execute_db({ + let server_guild_id = ctx.guild_id().expect("Guild ID not found"); + let guild_id = server_guild_id.to_string(); + + move |conn| { + let mut stmt = conn.prepare( + "SELECT id, guild_id, title, description FROM faqs WHERE title = ?1 AND guild_id = ?2" + )?; + + let faqs: Vec = stmt + .query_map([&faq_title, &guild_id], |row| { + Ok(Faq { + // id: row.get(0)?, + // guild_id: row.get(1)?, + title: row.get(2)?, + description: row.get(3)?, + }) + })? + .collect::, _>>()?; + + Ok(faqs) + }}) + .await?; + + let faq = faqs.first().unwrap(); + + // let embed_description = format_embed_description(&faq.description).expect("Format error"); + let embed = CreateEmbed::new() + .title(&faq.title) + .description( + format!("``` +{} + ```", + &faq.description + ) + ); + + ctx.send(CreateReply::default().embed(embed)).await?; + + Ok(()) +} + /// Add FAQ #[poise::command( prefix_command, @@ -254,3 +307,4 @@ pub async fn delete( Ok(()) } +