botserver/src/basic/keywords/first.rs

20 lines
596 B
Rust
Raw Normal View History

2025-10-06 10:30:17 -03:00
use rhai::Dynamic;
use rhai::Engine;
2025-12-21 23:40:43 -03:00
2025-10-06 10:30:17 -03:00
pub fn first_keyword(engine: &mut Engine) {
2025-12-21 23:40:43 -03:00
engine
.register_custom_syntax(["FIRST", "$expr$"], false, {
2025-12-21 23:40:43 -03:00
move |context, inputs| {
let input_string = context.eval_expression_tree(&inputs[0])?;
let input_str = input_string.to_string();
let first_word = input_str
.split_whitespace()
.next()
.unwrap_or("")
.to_string();
Ok(Dynamic::from(first_word))
}
})
.ok();
2025-10-06 10:30:17 -03:00
}