fix: instead of actually starting bot on /deploy, just put info in DB

reason: it's not a responsibility of /deploy command to store bot info
AND starting bot thread, isntead it is responsible only for storing info
in DB, as every other command does, and then bot will lazily start by
bot manager
This commit is contained in:
Akulij 2025-05-27 15:08:03 +05:00
parent d10acc992a
commit 2fdd8a346d
2 changed files with 6 additions and 5 deletions

View File

@ -7,7 +7,7 @@ use teloxide::{
}; };
use crate::{ use crate::{
bot_manager::deploy_bot, bot_manager::create_bot,
db::{CallDB, DB}, db::{CallDB, DB},
BotResult, BotResult,
}; };
@ -162,10 +162,11 @@ pub async fn admin_command_handler(
Ok(()) Ok(())
} }
AdminCommands::Deploy { token } => { AdminCommands::Deploy { token } => {
let bot_info = deploy_bot(&mut db, &token).await?; let bot_instance = create_bot(&mut db, &token).await?;
bot.send_message( bot.send_message(
msg.chat.id, msg.chat.id,
format!("Deployed bot with name: {}", bot_info.name), format!("Deployed bot with name: {}", bot_instance.name),
) )
.await?; .await?;
Ok(()) Ok(())

View File

@ -36,7 +36,7 @@ lazy_static! {
static DEFAULT_SCRIPT: &str = static DEFAULT_SCRIPT: &str =
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/default_script.js")); include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/default_script.js"));
pub async fn deploy_bot(db: &mut DB, token: &str) -> BotResult<BotInfo> { pub async fn create_bot(db: &mut DB, token: &str) -> BotResult<BotInstance> {
let bot = Bot::new(token); let bot = Bot::new(token);
let name = bot.get_me().await?.username().to_string(); let name = bot.get_me().await?.username().to_string();
@ -44,7 +44,7 @@ pub async fn deploy_bot(db: &mut DB, token: &str) -> BotResult<BotInfo> {
.store(db) .store(db)
.await?; .await?;
start_bot(bi, &mut db.clone().with_name(name)).await Ok(bi)
} }
pub async fn start_bot(bi: BotInstance, db: &mut DB) -> BotResult<BotInfo> { pub async fn start_bot(bi: BotInstance, db: &mut DB) -> BotResult<BotInfo> {