migration to JS engine #1
28
src/main.rs
28
src/main.rs
@ -8,7 +8,7 @@ pub mod message_answerer;
|
|||||||
pub mod mongodb_storage;
|
pub mod mongodb_storage;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
use botscript::{BotMessage, Runner, RunnerConfig, ScriptError};
|
use botscript::{BotMessage, Runner, RunnerConfig, ScriptError, ScriptResult};
|
||||||
use commands::BotCommand;
|
use commands::BotCommand;
|
||||||
use db::application::Application;
|
use db::application::Application;
|
||||||
use db::callback_info::CallbackInfo;
|
use db::callback_info::CallbackInfo;
|
||||||
@ -117,12 +117,28 @@ pub struct BotController {
|
|||||||
const MAIN_BOT_SCRIPT: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/mainbot.js"));
|
const MAIN_BOT_SCRIPT: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/mainbot.js"));
|
||||||
|
|
||||||
impl BotController {
|
impl BotController {
|
||||||
pub async fn new(config: &Config) -> Result<Self, Box<dyn std::error::Error>> {
|
pub async fn new(config: &Config) -> ScriptResult<Self> {
|
||||||
let bot = Bot::new(&config.bot_token);
|
Self::create(
|
||||||
let db = DB::init(&config.db_url).await?;
|
&config.bot_token,
|
||||||
|
&config.db_url,
|
||||||
|
&config.bot_name,
|
||||||
|
MAIN_BOT_SCRIPT,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
let runner = Runner::init()?;
|
pub async fn create(token: &str, db_url: &str, name: &str, script: &str) -> ScriptResult<Self> {
|
||||||
let rc = runner.init_config(include_str!("../mainbot.js"))?;
|
let db = DB::init(db_url, name.to_owned()).await?;
|
||||||
|
|
||||||
|
Self::with_db(db, token, script).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn with_db(mut db: DB, token: &str, script: &str) -> ScriptResult<Self> {
|
||||||
|
let bot = Bot::new(token);
|
||||||
|
|
||||||
|
let runner = Runner::init_with_db(&mut db)?;
|
||||||
|
let rc = runner.init_config(script)?;
|
||||||
|
let rc = Arc::new(RwLock::new(rc));
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
bot,
|
bot,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user