diff --git a/src/bot/main.rs b/src/bot/main.rs index fd91a2b3dbf0a85d63528da3c69fd4c440f5c280..1288014fc6acbb285a0f58602788cf3214a80ad2 100644 --- a/src/bot/main.rs +++ b/src/bot/main.rs @@ -155,11 +155,10 @@ async fn run(args: BotConfig, client: Client) -> anyhow::Result<()> { Ok(()) } -/// The main entrypoint for bot. -/// -/// This function starts bot, performs login and -/// starts endless loop. -pub async fn start(args: BotConfig, web_code: Arc<RwLock<Option<String>>>) -> anyhow::Result<()> { +pub async fn bot_life( + args: BotConfig, + web_code: Arc<RwLock<Option<String>>>, +) -> anyhow::Result<()> { log::info!("Connecting to Telegram..."); let client = Client::connect(Config { session: Session::load_file_or_create(args.session_file.as_str())?, @@ -189,3 +188,21 @@ pub async fn start(args: BotConfig, web_code: Arc<RwLock<Option<String>>>) -> an Ok(()) } + +/// The main entrypoint for bot. +/// +/// This function starts bot, performs login and +/// starts endless loop. +pub async fn start(args: BotConfig, web_code: Arc<RwLock<Option<String>>>) -> anyhow::Result<()> { + loop { + match bot_life(args.clone(), web_code.clone()).await { + Err(err) => { + log::error!("{err}"); + } + Ok(_) => { + log::info!("Lol, messages are ended."); + } + } + tokio::time::sleep(Duration::from_secs(1)).await; + } +}