migration to JS engine #1

Merged
akulij merged 131 commits from dev into main 2025-05-31 08:49:52 +00:00
2 changed files with 23 additions and 16 deletions
Showing only changes of commit 6dfe9b839d - Show all commits

View File

@ -1,5 +1,3 @@
use std::fmt::format;
use itertools::Itertools;
use teloxide::{
prelude::*,
@ -7,8 +5,8 @@ use teloxide::{
};
use crate::{
bot_manager::create_bot,
db::{CallDB, DB},
bot_manager::DEFAULT_SCRIPT,
db::{bots::BotInstance, CallDB, DB},
BotResult,
};
use crate::{BotDialogue, LogMsg, State};
@ -162,7 +160,27 @@ pub async fn admin_command_handler(
Ok(())
}
AdminCommands::Deploy { token } => {
let bot_instance = create_bot(&mut db, &token).await?;
let bot_instance = {
let botnew = Bot::new(&token);
let name = match botnew.get_me().await {
Ok(me) => me.username().to_string(),
Err(teloxide::RequestError::Api(teloxide::ApiError::InvalidToken)) => {
bot.send_message(msg.chat.id, "Error: bot token is invalid")
.await?;
return Ok(());
}
Err(err) => {
return Err(err.into());
}
};
let bi =
BotInstance::new(name.clone(), token.to_string(), DEFAULT_SCRIPT.to_string())
.store(&mut db)
.await?;
bi
};
bot.send_message(
msg.chat.id,

View File

@ -169,17 +169,6 @@ async fn script_handler_gen(c: BotController, plug_handlers: Vec<BotHandler>) ->
handler
}
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();
let bi = BotInstance::new(name.clone(), token.to_string(), DEFAULT_SCRIPT.to_string())
.store(db)
.await?;
Ok(bi)
}
pub async fn start_bot(
bi: BotInstance,
db: &mut DB,