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:
parent
d10acc992a
commit
2fdd8a346d
@ -7,7 +7,7 @@ use teloxide::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
bot_manager::deploy_bot,
|
||||
bot_manager::create_bot,
|
||||
db::{CallDB, DB},
|
||||
BotResult,
|
||||
};
|
||||
@ -162,10 +162,11 @@ pub async fn admin_command_handler(
|
||||
Ok(())
|
||||
}
|
||||
AdminCommands::Deploy { token } => {
|
||||
let bot_info = deploy_bot(&mut db, &token).await?;
|
||||
let bot_instance = create_bot(&mut db, &token).await?;
|
||||
|
||||
bot.send_message(
|
||||
msg.chat.id,
|
||||
format!("Deployed bot with name: {}", bot_info.name),
|
||||
format!("Deployed bot with name: {}", bot_instance.name),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
|
||||
@ -36,7 +36,7 @@ lazy_static! {
|
||||
static DEFAULT_SCRIPT: &str =
|
||||
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 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)
|
||||
.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> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user