From ac0833a9f6da56475e2862a75b5264b3b438416e Mon Sep 17 00:00:00 2001 From: Akulij Date: Fri, 2 May 2025 17:13:28 +0300 Subject: [PATCH] create notify_admin command --- src/main.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index aa0f332..5035291 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ pub mod mongodb_storage; pub mod utils; use db::callback_info::CallbackInfo; -use log::{info, warn}; +use log::{error, info, warn}; use std::time::Duration; use utils::create_callback_button; @@ -368,6 +368,25 @@ async fn callback_handler(bot: Bot, mut db: DB, q: CallbackQuery) -> BotResult<( Ok(()) } +/// This is an emergent situation function, so it should not return any Result, but handle Results +/// on its own +async fn notify_admin(text: &str) { + let config = match Config::init_from_env() { + Ok(config) => config, + Err(err) => { + error!("notify_admin: Failed to get config from env, err: {err}"); + return; + } + }; + let bot = Bot::new(&config.bot_token); + match bot.send_message(UserId(config.admin_id), text).await { + Ok(_) => {} + Err(err) => { + error!("notify_admin: Failed to send message to admin, WHATS WRONG???, err: {err}"); + } + } +} + async fn edit_msg_cmd_handler( bot: Bot, mut db: DB,