From cd4f98971091a43078f9906aa9feb7290b1b5b09 Mon Sep 17 00:00:00 2001 From: Sidonie Bouthors Date: Fri, 19 Sep 2025 15:08:03 +0200 Subject: [PATCH] fix: insert in db on authorize and improve authorize messages --- src/cmd_authentication.rs | 49 ++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/src/cmd_authentication.rs b/src/cmd_authentication.rs index 71fe7eb..d1172ec 100644 --- a/src/cmd_authentication.rs +++ b/src/cmd_authentication.rs @@ -103,7 +103,7 @@ pub async fn authorize( .fetch_one(tx.as_mut()) .await?; - if already_authorized.count > 0 { + if already_authorized.count == 0 { sqlx::query!( r#"INSERT INTO authorizations(command, chat_id) VALUES($1, $2)"#, command, @@ -115,11 +115,20 @@ pub async fn authorize( tx.commit().await?; - bot.send_message( - msg.chat.id, - format!("Ce groupe peut désormais utiliser la commande /{}", command), - ) - .await?; + if already_authorized.count > 0 { + bot.send_message( + msg.chat.id, + format!("Ce groupe peut déjà utiliser la commande /{}", command), + ) + .await?; + } else { + bot.send_message( + msg.chat.id, + format!("Ce groupe peut désormais utiliser la commande /{}", command), + ) + .await?; + } + Ok(()) } @@ -152,14 +161,26 @@ pub async fn unauthorize( tx.commit().await?; - bot.send_message( - msg.chat.id, - format!( - "Ce groupe ne peut désormais plus utiliser la commande /{}", - command - ), - ) - .await?; + if already_authorized.count == 0 { + bot.send_message( + msg.chat.id, + format!( + "Ce groupe ne peut déjà pas utiliser la commande /{}", + command + ), + ) + .await?; + } else { + bot.send_message( + msg.chat.id, + format!( + "Ce groupe ne peut désormais plus utiliser la commande /{}", + command + ), + ) + .await?; + } + Ok(()) }