Compare commits
No commits in common. "92c97abd4a58bc9b0fe75e686a65703b636a1877" and "ab3cf214d1801163e1ab34cc4dd4e48fb1a12e12" have entirely different histories.
92c97abd4a
...
ab3cf214d1
@ -118,13 +118,9 @@ where
|
|||||||
script_handler_gen(bot_runner.controller.clone(), handlers.collect())
|
script_handler_gen(bot_runner.controller.clone(), handlers.collect())
|
||||||
.await;
|
.await;
|
||||||
Some(
|
Some(
|
||||||
spawn_bot_thread(
|
spawn_bot_thread(bot_runner.controller.clone(), db, handler)
|
||||||
bot_runner.controller.bot.clone(),
|
.await
|
||||||
bot_runner.controller.db.clone(),
|
.unwrap(),
|
||||||
handler,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -140,13 +136,12 @@ where
|
|||||||
db: &mut DB,
|
db: &mut DB,
|
||||||
plug_handlers: Vec<BotHandler>,
|
plug_handlers: Vec<BotHandler>,
|
||||||
) -> BotResult<BotInfo> {
|
) -> BotResult<BotInfo> {
|
||||||
let db = db.clone().with_name(bi.name.clone());
|
let mut db = db.clone().with_name(bi.name.clone());
|
||||||
let controller = BotController::with_db(db.clone(), &bi.token, &bi.script).await?;
|
let controller = BotController::with_db(db.clone(), &bi.token, &bi.script).await?;
|
||||||
|
|
||||||
let handler = script_handler_gen(controller.clone(), plug_handlers).await;
|
let handler = script_handler_gen(controller.clone(), plug_handlers).await;
|
||||||
|
|
||||||
let thread =
|
let thread = spawn_bot_thread(controller.clone(), &mut db, handler).await?;
|
||||||
spawn_bot_thread(controller.bot.clone(), controller.db.clone(), handler).await?;
|
|
||||||
|
|
||||||
let info = BotInfo {
|
let info = BotInfo {
|
||||||
name: bi.name.clone(),
|
name: bi.name.clone(),
|
||||||
@ -179,7 +174,7 @@ pub async fn start_bot(
|
|||||||
db: &mut DB,
|
db: &mut DB,
|
||||||
plug_handlers: Vec<BotHandler>,
|
plug_handlers: Vec<BotHandler>,
|
||||||
) -> BotResult<BotInfo> {
|
) -> BotResult<BotInfo> {
|
||||||
let db = db.clone().with_name(bi.name.clone());
|
let mut db = db.clone().with_name(bi.name.clone());
|
||||||
let controller = BotController::with_db(db.clone(), &bi.token, &bi.script).await?;
|
let controller = BotController::with_db(db.clone(), &bi.token, &bi.script).await?;
|
||||||
|
|
||||||
let handler = script_handler(controller.rc.clone());
|
let handler = script_handler(controller.rc.clone());
|
||||||
@ -190,7 +185,7 @@ pub async fn start_bot(
|
|||||||
.chain(std::iter::once(handler))
|
.chain(std::iter::once(handler))
|
||||||
.fold(dptree::entry(), |h, plug| h.branch(plug));
|
.fold(dptree::entry(), |h, plug| h.branch(plug));
|
||||||
|
|
||||||
let thread = spawn_bot_thread(controller.bot.clone(), controller.db.clone(), handler).await?;
|
let thread = spawn_bot_thread(controller.clone(), &mut db, handler).await?;
|
||||||
|
|
||||||
let info = BotInfo {
|
let info = BotInfo {
|
||||||
name: bi.name.clone(),
|
name: bi.name.clone(),
|
||||||
@ -217,11 +212,11 @@ pub async fn start_bot(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn spawn_bot_thread(
|
pub async fn spawn_bot_thread(
|
||||||
bot: Bot,
|
bc: BotController,
|
||||||
mut db: DB,
|
db: &mut DB,
|
||||||
handler: BotHandler,
|
handler: BotHandler,
|
||||||
) -> BotResult<JoinHandle<BotResult<()>>> {
|
) -> BotResult<JoinHandle<BotResult<()>>> {
|
||||||
let state_mgr = MongodbStorage::from_db(&mut db, Json)
|
let state_mgr = MongodbStorage::from_db(db, Json)
|
||||||
.await
|
.await
|
||||||
.map_err(DbError::from)?;
|
.map_err(DbError::from)?;
|
||||||
let thread = std::thread::spawn(move || -> BotResult<()> {
|
let thread = std::thread::spawn(move || -> BotResult<()> {
|
||||||
@ -232,8 +227,8 @@ pub async fn spawn_bot_thread(
|
|||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
rt.block_on(
|
rt.block_on(
|
||||||
Dispatcher::builder(bot, handler)
|
Dispatcher::builder(bc.bot, handler)
|
||||||
.dependencies(dptree::deps![db, state_mgr])
|
.dependencies(dptree::deps![bc.db, state_mgr])
|
||||||
.build()
|
.build()
|
||||||
.dispatch(),
|
.dispatch(),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -108,12 +108,6 @@ pub struct BotController {
|
|||||||
pub runner: Runner,
|
pub runner: Runner,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for BotController {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
info!("called drop for BotController");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl Send for BotController {}
|
unsafe impl Send for 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"));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user