diff --git a/src/admin.rs b/src/admin.rs new file mode 100644 index 0000000..070af5c --- /dev/null +++ b/src/admin.rs @@ -0,0 +1,44 @@ +use teloxide::{dispatching::dialogue::GetChatId, payloads::SendMessageSetters, prelude::*, types::InputFile, utils::{command::BotCommands, render::RenderMessageTextHelper}}; + +use crate::db::DB; +use crate::LogMsg; + +#[derive(BotCommands, Clone)] +#[command(rename_rule = "lowercase")] +pub enum AdminCommands { + /// Shows your ID. + MyId, + /// Pin replied message + Pin, + /// Removes your admin privileges + Deop, +} + +pub async fn admin_command_handler( + mut db: DB, + bot: Bot, + msg: Message, + cmd: AdminCommands, +) -> Result<(), teloxide::RequestError> { + let tguser = msg.from.clone().unwrap(); + println!("MSG: {}", msg.html_text().unwrap()); + match cmd { + AdminCommands::MyId => { + bot.send_message(msg.chat.id, format!("Your ID is: {}", tguser.id)).log().await?; + Ok(()) + }, + AdminCommands::Pin => { + if let Some(msg_to_pin) = msg.reply_to_message() { + bot.pin_chat_message(msg.chat.id, msg_to_pin.id).await?; + } else { + bot.send_message(msg.chat.id, "you need to reply to some message with this command").log().await?; + } + Ok(()) + }, + AdminCommands::Deop => { + db.set_admin(tguser.id.0 as i64, false).await; + bot.send_message(msg.chat.id, "You are not an admin anymore").await?; + Ok(()) + } + } +} diff --git a/src/main.rs b/src/main.rs index aeb5877..4454f96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,8 @@ pub mod db; +pub mod admin; + use crate::db::DB; +use crate::admin::{AdminCommands, admin_command_handler}; use teloxide::{dispatching::dialogue::GetChatId, payloads::SendMessageSetters, prelude::*, types::InputFile, utils::{command::BotCommands, render::RenderMessageTextHelper}}; use envconfig::Envconfig; @@ -33,17 +36,6 @@ enum SecretCommands { }, } -#[derive(BotCommands, Clone)] -#[command(rename_rule = "lowercase")] -enum AdminCommands { - /// Shows your ID. - MyId, - /// Pin replied message - Pin, - /// Removes your admin privileges - Deop, -} - trait LogMsg { fn log(self) -> Self; } @@ -147,35 +139,6 @@ async fn secret_command_handler( } } -async fn admin_command_handler( - mut db: DB, - bot: Bot, - msg: Message, - cmd: AdminCommands, -) -> Result<(), teloxide::RequestError> { - let tguser = msg.from.clone().unwrap(); - println!("MSG: {}", msg.html_text().unwrap()); - match cmd { - AdminCommands::MyId => { - bot.send_message(msg.chat.id, format!("Your ID is: {}", tguser.id)).log().await?; - Ok(()) - }, - AdminCommands::Pin => { - if let Some(msg_to_pin) = msg.reply_to_message() { - bot.pin_chat_message(msg.chat.id, msg_to_pin.id).await?; - } else { - bot.send_message(msg.chat.id, "you need to reply to some message with this command").log().await?; - } - Ok(()) - }, - AdminCommands::Deop => { - db.set_admin(tguser.id.0 as i64, false).await; - bot.send_message(msg.chat.id, "You are not an admin anymore").await?; - Ok(()) - } - } -} - async fn echo( bot: Bot, msg: Message,