feat: Add simple form of ADD SWITCHER keyword without AS clause
All checks were successful
Botlib CI / build (push) Successful in 13s
Bottest CI / build (push) Successful in 31s
BotUI CI / build (push) Successful in 15s

- ADD_SWITCHER "tables" now works (label defaults to switcher ID)
- ADD_SWITCHER "tables" AS "Tabelas" still works (custom label)
- Follows same pattern as ADD_SUGGESTION simple/AS forms
- Fixes #495
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-24 18:22:17 +00:00
parent 8a97c0517f
commit 3048832a2d

View file

@ -89,6 +89,8 @@ pub fn add_switcher_keyword(
engine: &mut Engine,
) {
let cache = state.cache.clone();
let cache2 = state.cache.clone();
let user_session2 = user_session.clone();
engine
.register_custom_syntax(
@ -109,6 +111,25 @@ pub fn add_switcher_keyword(
},
)
.expect("valid syntax registration");
engine
.register_custom_syntax(
["ADD_SWITCHER", "$expr$"],
true,
move |context, inputs| {
let switcher_id = context.eval_expression_tree(&inputs[0])?.to_string();
add_switcher(
cache2.as_ref(),
&user_session2,
&switcher_id,
&switcher_id,
)?;
Ok(Dynamic::UNIT)
},
)
.expect("valid syntax registration");
}
fn add_switcher(