From 4103c5dfbe00e55f987e77f01ea7cba0163eefa0 Mon Sep 17 00:00:00 2001 From: Akulij Date: Thu, 5 Jun 2025 22:36:30 +0500 Subject: [PATCH] create BotMessage.update_defaults method for some logic for default values --- src/botscript.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/botscript.rs b/src/botscript.rs index b0ec98a..04d3ac5 100644 --- a/src/botscript.rs +++ b/src/botscript.rs @@ -513,6 +513,24 @@ impl BotMessage { } } + /// chain of modifications on BotMessage + pub fn update_defaults(self) -> Self { + let bm = self; + // if message is `start`, defaulting meta to true, if not set + let bm = match bm.meta { + Some(_) => bm, + None => match &bm.literal { + Some(l) if l == "start" => Self { + meta: Some(true), + ..bm + }, + _ => bm, + }, + }; + + bm + } + pub fn is_replace(&self) -> bool { self.replace } @@ -868,7 +886,7 @@ impl RunnerConfig { pub fn get_command_message(&self, command: &str) -> Option { let bm = self.dialog.commands.get(command).cloned(); - bm.map(|bm| bm.fill_literal(command.to_string())) + bm.map(|bm| bm.fill_literal(command.to_string()).update_defaults()) } pub fn get_callback_message(&self, callback: &str) -> Option {