From 806614b5bf00581c9a564fcda4ecb760b6d27c6a Mon Sep 17 00:00:00 2001 From: Jokler Date: Sat, 17 Feb 2018 23:25:38 +0100 Subject: Improve factoid error handling --- src/plugins/factoids/mod.rs | 6 ++++-- src/plugins/factoids/sandbox.lua | 10 ++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/factoids/mod.rs b/src/plugins/factoids/mod.rs index f857f85..252ba83 100644 --- a/src/plugins/factoids/mod.rs +++ b/src/plugins/factoids/mod.rs @@ -140,8 +140,10 @@ impl Factoids { } }; + let message = factoid.content.replace("\n", "|").replace("\r", ""); + server.send_privmsg(&command.target, - &format!("{}: {}", factoid.name, factoid.content)) + &format!("{}: {}", factoid.name, message)) } fn info(&self, server: &IrcServer, command: &PluginCommand) -> Result<(), IrcError> { @@ -156,7 +158,7 @@ impl Factoids { }; match count { - 0 => server.send_privmsg(&command.target, &format!("{} does not exist", name)), + 0 => server.send_notice(&command.source, &format!("{} does not exist", name)), 1 => { server.send_privmsg(&command.target, &format!("There is 1 version of {}", name)) diff --git a/src/plugins/factoids/sandbox.lua b/src/plugins/factoids/sandbox.lua index 282a903..8ebf518 100644 --- a/src/plugins/factoids/sandbox.lua +++ b/src/plugins/factoids/sandbox.lua @@ -1,5 +1,6 @@ function send(text) - len = #output + local text = tostring(text) + local len = #output if len < 1 then output = { text } else @@ -25,4 +26,9 @@ local env = { print = send, tostring = tostring, math = math } -load(factoid, nil, nil, env)() +local f, e = load(factoid, nil, nil, env) +if f then + f() +else + error(e) +end -- cgit v1.2.3-70-g09d2