migration to JS engine #1
28
src/admin.rs
28
src/admin.rs
@ -1,5 +1,3 @@
|
|||||||
use std::fmt::format;
|
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use teloxide::{
|
use teloxide::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
@ -7,8 +5,8 @@ use teloxide::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bot_manager::create_bot,
|
bot_manager::DEFAULT_SCRIPT,
|
||||||
db::{CallDB, DB},
|
db::{bots::BotInstance, CallDB, DB},
|
||||||
BotResult,
|
BotResult,
|
||||||
};
|
};
|
||||||
use crate::{BotDialogue, LogMsg, State};
|
use crate::{BotDialogue, LogMsg, State};
|
||||||
@ -162,7 +160,27 @@ pub async fn admin_command_handler(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
AdminCommands::Deploy { token } => {
|
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(
|
bot.send_message(
|
||||||
msg.chat.id,
|
msg.chat.id,
|
||||||
|
|||||||
@ -169,17 +169,6 @@ async fn script_handler_gen(c: BotController, plug_handlers: Vec<BotHandler>) ->
|
|||||||
handler
|
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(
|
pub async fn start_bot(
|
||||||
bi: BotInstance,
|
bi: BotInstance,
|
||||||
db: &mut DB,
|
db: &mut DB,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user