some fixes + gliner first implementation
This commit is contained in:
parent
b9d5f41bbd
commit
a8ff3442ff
36 changed files with 1079 additions and 73 deletions
|
|
@ -3,6 +3,8 @@
|
|||
use mlua::{Lua, Table};
|
||||
use crate::lua::{CommandContext};
|
||||
|
||||
use crate::commands::SlotValue;
|
||||
|
||||
pub fn register(lua: &Lua, jarvis: &Table, ctx: &CommandContext) -> mlua::Result<()> {
|
||||
let context = lua.create_table()?;
|
||||
|
||||
|
|
@ -25,6 +27,18 @@ pub fn register(lua: &Lua, jarvis: &Table, ctx: &CommandContext) -> mlua::Result
|
|||
time.set("timestamp", now.timestamp())?;
|
||||
context.set("time", time)?;
|
||||
|
||||
// slots
|
||||
let slots_table = lua.create_table()?;
|
||||
if let Some(ref slots) = ctx.slots {
|
||||
for (name, value) in slots {
|
||||
match value {
|
||||
SlotValue::Text(t) => slots_table.set(name.as_str(), t.as_str())?,
|
||||
SlotValue::Number(n) => slots_table.set(name.as_str(), *n)?,
|
||||
}
|
||||
}
|
||||
}
|
||||
context.set("slots", slots_table)?;
|
||||
|
||||
jarvis.set("context", context)?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
use std::path::PathBuf;
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
|
||||
use crate::commands::SlotValue;
|
||||
|
||||
// Context passed to Lua scripts
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -14,6 +16,9 @@ pub struct CommandContext {
|
|||
|
||||
// Current language
|
||||
pub language: String,
|
||||
|
||||
// Slots
|
||||
pub slots: Option<HashMap<String, SlotValue>>
|
||||
}
|
||||
|
||||
// Result returned from Lua script execution
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ mod tests {
|
|||
command_id: "test_cmd".to_string(),
|
||||
command_path: cmd_path,
|
||||
language: "en".to_string(),
|
||||
slots: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue