diff --git a/src/main.rs b/src/main.rs index cccbd00..c15f014 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ pub mod db; pub mod mongodb_storage; pub mod utils; -use botscript::{BotMessage, Runner, RunnerConfig}; +use botscript::{BotMessage, Runner, RunnerConfig, ScriptError}; use commands::BotCommand; use db::application::Application; use db::callback_info::CallbackInfo; @@ -133,6 +133,7 @@ pub enum BotError { MsgTooOld(String), BotLogicError(String), AdminMisconfiguration(String), + ScriptError(#[from] ScriptError), } pub type BotResult = Result; @@ -254,8 +255,35 @@ async fn main() -> Result<(), Box> { Ok(()) } -async fn botscript_command_handler(bot: Bot, bm: BotMessage) -> BotResult<()> { +async fn botscript_command_handler( + bot: Bot, + mut db: DB, + bm: BotMessage, + msg: Message, +) -> BotResult<()> { info!("Eval BM: {:?}", bm); + let buttons = bm + .resolve_buttons(&mut db) + .await? + .map(|buttons| InlineKeyboardMarkup { + inline_keyboard: buttons + .iter() + .map(|r| { + r.iter() + .map(|b| match b { + botscript::ButtonLayout::Callback { + name, + literal: _, + callback, + } => InlineKeyboardButton::callback(name, callback), + }) + .collect() + }) + .collect(), + }); + let literal = bm.literal().map_or("", |s| s.as_str()); + + answer_message_varianted(&bot, msg.chat.id.0, &mut db, literal, None, buttons).await?; Ok(()) }