Changed bot logic.

Signed-off-by: Pavel Kirilin <win10@list.ru>
This commit is contained in:
2023-02-23 00:48:30 +04:00
parent 791e27dced
commit cac238df97

View File

@ -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;
}
}