diff options
| author | Jokler <jokler.contact@gmail.com> | 2017-10-29 17:00:58 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2017-12-24 00:12:07 +0100 |
| commit | aa2e6dc0103c303aac0dd688d90c8547b22f8a47 (patch) | |
| tree | 78540914f0c1c52c2457b0ef238b700b313cba58 | |
| parent | fee0ea52e7300042f4baaf2419be344dbc643fb8 (diff) | |
| download | frippy-aa2e6dc0103c303aac0dd688d90c8547b22f8a47.tar.gz frippy-aa2e6dc0103c303aac0dd688d90c8547b22f8a47.zip | |
Add non Lua factoids
Only factoids prefixed with '>' are run as Lua now.
To escape the '>' just add another one.
| -rw-r--r-- | src/plugins/factoids/mod.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/plugins/factoids/mod.rs b/src/plugins/factoids/mod.rs index 68b02e3..c69042f 100644 --- a/src/plugins/factoids/mod.rs +++ b/src/plugins/factoids/mod.rs @@ -9,6 +9,8 @@ use std::sync::Mutex; use plugin::*; +static LUA_SANDBOX: &'static str = include_str!("sandbox.lua"); + #[derive(PluginName, Debug)] pub struct Factoids { factoids: Mutex<HashMap<String, String>>, @@ -23,8 +25,6 @@ macro_rules! try_lock { } } -static LUA_SANDBOX: &'static str = include_str!("sandbox.lua"); - impl Factoids { pub fn new() -> Factoids { Factoids { factoids: Mutex::new(HashMap::new()) } @@ -75,9 +75,19 @@ impl Factoids { None => return self.invalid_command(server, &command), }; - let value = match self.run_lua(&name, factoid, &command) { - Ok(v) => v, - Err(e) => format!("{}", e), + let value = if factoid.starts_with(">") { + let factoid = String::from(&factoid[1..]); + + if factoid.starts_with(">") { + factoid + } else { + match self.run_lua(&name, &factoid, &command) { + Ok(v) => v, + Err(e) => format!("{}", e), + } + } + } else { + String::from(factoid) }; server.send_privmsg(&command.target, &value) |
