From 8955e1a7f6a125cbfc34353818670213dd5a0782 Mon Sep 17 00:00:00 2001 From: liyunze <50455574+liyunze-coding@users.noreply.github.com> Date: Thu, 24 Sep 2026 20:28:06 +0800 Subject: [PATCH] removed unused comments, formatted better --- src/commands/faq.rs | 41 +++++++++++++++++++++---------------- src/commands/forum.rs | 6 ------ src/commands/info.rs | 1 - src/database/database.rs | 1 - src/events/thread_create.rs | 6 +++--- 5 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/commands/faq.rs b/src/commands/faq.rs index 649642f..566202d 100644 --- a/src/commands/faq.rs +++ b/src/commands/faq.rs @@ -6,8 +6,6 @@ use serenity::all::CreateEmbed; // Define your FAQ struct struct Faq { - // id: i64, - // guild_id: String, title: String, description: String, } @@ -40,7 +38,7 @@ async fn autocomplete_faq_titles<'a>( let guild_id = server_guild_id.to_string(); move |conn| { let mut stmt = conn.prepare( - "SELECT id, guild_id, title, description FROM faqs WHERE guild_id = ?1" + "SELECT id, guild_id, title, description FROM faqs WHERE guild_id = ?1", )?; let faqs: Vec = stmt @@ -64,11 +62,17 @@ async fn autocomplete_faq_titles<'a>( let partial_lowercase = partial.to_lowercase(); futures::stream::iter(faqs) - .filter(move |faq| futures::future::ready(faq.title.to_lowercase().contains(&partial_lowercase))) + .filter(move |faq| { + futures::future::ready(faq.title.to_lowercase().contains(&partial_lowercase)) + }) .map(|faq| faq.title) } -#[poise::command(slash_command, subcommands("view", "preview", "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(()) } @@ -87,7 +91,7 @@ pub async fn view( .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" @@ -122,8 +126,8 @@ pub async fn view( /// Preview FAQ #[poise::command( - prefix_command, - slash_command, + prefix_command, + slash_command, required_permissions = "MANAGE_MESSAGES" // mod only )] pub async fn preview( @@ -138,7 +142,7 @@ pub async fn preview( .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" @@ -162,15 +166,12 @@ pub async fn preview( 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!("``` + let embed = CreateEmbed::new().title(&faq.title).description(format!( + "``` {} ```", - &faq.description - ) - ); + &faq.description + )); ctx.send(CreateReply::default().embed(embed)).await?; @@ -296,7 +297,12 @@ pub async fn delete( let result = data .execute_db({ let title = title.clone(); - move |conn| conn.execute("DELETE FROM faqs WHERE title = ?1 AND guild_id = ?2", [title, guild_id]) + move |conn| { + conn.execute( + "DELETE FROM faqs WHERE title = ?1 AND guild_id = ?2", + [title, guild_id], + ) + } }) .await?; @@ -312,4 +318,3 @@ pub async fn delete( Ok(()) } - diff --git a/src/commands/forum.rs b/src/commands/forum.rs index 0f009c8..a8dedb2 100644 --- a/src/commands/forum.rs +++ b/src/commands/forum.rs @@ -3,12 +3,6 @@ use poise::CreateReply; use rusqlite::Connection; use serenity::all::{CreateEmbed, GuildChannel}; -// struct Forum { -// id: i64, -// guild_id: String, -// forum_id: String, -// } - #[poise::command(slash_command, subcommands("add", "delete"), guild_only)] pub async fn forum(_ctx: Context<'_>) -> Result<(), Error> { Ok(()) diff --git a/src/commands/info.rs b/src/commands/info.rs index 22af781..969b1ac 100644 --- a/src/commands/info.rs +++ b/src/commands/info.rs @@ -12,7 +12,6 @@ pub async fn help( ctx, command.as_deref(), poise::builtins::HelpConfiguration { - // extra_text_at_bottom: "made with ❤️", ..Default::default() }, ) diff --git a/src/database/database.rs b/src/database/database.rs index 9516faa..b9e530c 100644 --- a/src/database/database.rs +++ b/src/database/database.rs @@ -63,6 +63,5 @@ pub fn init_tables(conn: &Connection) -> Result<()> { } // if we need to create more tables we'll use this function - Ok(()) } diff --git a/src/events/thread_create.rs b/src/events/thread_create.rs index ebdbf2b..efe34f1 100644 --- a/src/events/thread_create.rs +++ b/src/events/thread_create.rs @@ -85,9 +85,9 @@ pub async fn on_thread_create( .to_string(); let message_builder = CreateMessage::new().content(format!( - "<@{}> Please select only ONE (1) tag (personal-only or career-oriented)\n\nYou can edit your post's tags under Post Settings -> Edit Tags", - thread_owner - )); + "<@{}> Please select only ONE (1) tag (personal-only or career-oriented)\n\nYou can edit your post's tags under Post Settings -> Edit Tags", + thread_owner + )); tokio::time::sleep(std::time::Duration::from_secs(1)).await;