fix: handle Runner in BotController

reason: earlier, Runner and js runtime in it were freed after init of
BotController, which potentially was able to lead into hanging function
in config without runtime, BUT, there is check in in JS_FreeRuntime to
have zero objects, so bug found without hesitation ;)
This commit is contained in:
Akulij 2025-05-21 14:07:02 +05:00
parent ca2e661a0e
commit d174ee7bc7

View File

@ -105,6 +105,7 @@ pub struct BotController {
pub bot: Bot, pub bot: Bot,
pub db: DB, pub db: DB,
pub rc: RunnerConfig, pub rc: RunnerConfig,
pub runner: Runner,
} }
impl BotController { impl BotController {
@ -112,9 +113,15 @@ impl BotController {
let bot = Bot::new(&config.bot_token); let bot = Bot::new(&config.bot_token);
let db = DB::init(&config.db_url).await?; let db = DB::init(&config.db_url).await?;
let rc = Runner::init()?.init_config(include_str!("../mainbot.js"))?; let runner = Runner::init()?;
let rc = runner.init_config(include_str!("../mainbot.js"))?;
Ok(Self { bot, db, rc }) Ok(Self {
bot,
db,
rc,
runner,
})
} }
} }