From fd24b6953e04ba5835540cd2c8ba7b8515b9df19 Mon Sep 17 00:00:00 2001 From: Akulij Date: Sat, 7 Jun 2025 03:31:03 +0500 Subject: [PATCH] on downloading new script notify admin about failure --- src/handlers/admin.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/handlers/admin.rs b/src/handlers/admin.rs index d0b419f..0ec65c4 100644 --- a/src/handlers/admin.rs +++ b/src/handlers/admin.rs @@ -17,7 +17,7 @@ use crate::db::bots::BotInstance; use crate::db::message_forward::MessageForward; use crate::db::{CallDB, DB}; use crate::mongodb_storage::MongodbStorage; -use crate::{BotDialogue, BotError, BotResult, CallbackStore, State}; +use crate::{notify_admin, BotDialogue, BotError, BotResult, CallbackStore, State}; pub fn admin_handler() -> BotHandler { dptree::entry() @@ -103,7 +103,17 @@ async fn newscript_handler(bot: Bot, mut db: DB, msg: Message, name: String) -> let mut stream = bot.download_file_stream(&file.path); let mut buf: Vec = Vec::new(); while let Some(bytes) = stream.next().await { - let mut bytes = bytes.unwrap().to_vec(); + let mut bytes = match bytes { + Ok(bytes) => bytes.to_vec(), + Err(err) => { + notify_admin(&format!( + "Failed to download file: {}, err: {err}", + file.path + )) + .await; + return Ok(()); + } + }; buf.append(&mut bytes); }