From 30117624c44363b123f3a76b4eb13fdfc1fc7aaa Mon Sep 17 00:00:00 2001 From: Akulij Date: Thu, 3 Apr 2025 04:56:08 +0900 Subject: [PATCH] move out secret command to admin file --- src/admin.rs | 34 ++++++++++++++++++++++++++++++++++ src/main.rs | 35 +---------------------------------- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/admin.rs b/src/admin.rs index 070af5c..ed94d33 100644 --- a/src/admin.rs +++ b/src/admin.rs @@ -3,6 +3,16 @@ use teloxide::{dispatching::dialogue::GetChatId, payloads::SendMessageSetters, p use crate::db::DB; use crate::LogMsg; +// These are should not appear in /help +#[derive(BotCommands, Clone)] +#[command(rename_rule = "lowercase")] +pub enum SecretCommands { + /// Activate admin mode + Secret { + pass: String + }, +} + #[derive(BotCommands, Clone)] #[command(rename_rule = "lowercase")] pub enum AdminCommands { @@ -42,3 +52,27 @@ pub async fn admin_command_handler( } } } + +pub async fn secret_command_handler( + mut db: DB, + //config: Config, + bot: Bot, + msg: Message, + cmd: SecretCommands, + admin_password: String +) -> Result<(), teloxide::RequestError> { + println!("Admin Pass: {}", admin_password); + let user = db.get_or_init_user(msg.from.clone().unwrap().id.0 as i64).await; + println!("MSG: {}", msg.html_text().unwrap()); + match cmd { + SecretCommands::Secret { pass } => { + if user.is_admin == true { + bot.send_message(msg.from.unwrap().id, "You are an admin already").await?; + } else if pass == admin_password { + db.set_admin(user.id, true).await; + bot.send_message(msg.from.unwrap().id, "You are admin now!").await?; + } + Ok(()) + }, + } +} diff --git a/src/main.rs b/src/main.rs index 4454f96..3f6b6b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ pub mod admin; use crate::db::DB; use crate::admin::{AdminCommands, admin_command_handler}; +use crate::admin::{secret_command_handler, SecretCommands}; use teloxide::{dispatching::dialogue::GetChatId, payloads::SendMessageSetters, prelude::*, types::InputFile, utils::{command::BotCommands, render::RenderMessageTextHelper}}; use envconfig::Envconfig; @@ -26,16 +27,6 @@ enum UserCommands { Help, } -// These are should not appear in /help -#[derive(BotCommands, Clone)] -#[command(rename_rule = "lowercase")] -enum SecretCommands { - /// Activate admin mode - Secret { - pass: String - }, -} - trait LogMsg { fn log(self) -> Self; } @@ -115,30 +106,6 @@ async fn user_command_handler( } } -async fn secret_command_handler( - mut db: DB, - //config: Config, - bot: Bot, - msg: Message, - cmd: SecretCommands, - admin_password: String -) -> Result<(), teloxide::RequestError> { - println!("Admin Pass: {}", admin_password); - let user = db.get_or_init_user(msg.from.clone().unwrap().id.0 as i64).await; - println!("MSG: {}", msg.html_text().unwrap()); - match cmd { - SecretCommands::Secret { pass } => { - if user.is_admin == true { - bot.send_message(msg.from.unwrap().id, "You are an admin already").await?; - } else if pass == admin_password { - db.set_admin(user.id, true).await; - bot.send_message(msg.from.unwrap().id, "You are admin now!").await?; - } - Ok(()) - }, - } -} - async fn echo( bot: Bot, msg: Message,