create notify_admin command

This commit is contained in:
Akulij 2025-05-02 17:13:28 +03:00
parent adac0155b9
commit ac0833a9f6

View File

@ -4,7 +4,7 @@ pub mod mongodb_storage;
pub mod utils; pub mod utils;
use db::callback_info::CallbackInfo; use db::callback_info::CallbackInfo;
use log::{info, warn}; use log::{error, info, warn};
use std::time::Duration; use std::time::Duration;
use utils::create_callback_button; use utils::create_callback_button;
@ -368,6 +368,25 @@ async fn callback_handler(bot: Bot, mut db: DB, q: CallbackQuery) -> BotResult<(
Ok(()) 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( async fn edit_msg_cmd_handler(
bot: Bot, bot: Bot,
mut db: DB, mut db: DB,