From f24da1f5090d71a4963e05c5a76dad2eccac15bd Mon Sep 17 00:00:00 2001 From: Jokler Date: Sat, 24 Feb 2018 19:26:26 +0100 Subject: Add temporary eval function to factoids --- src/plugins/factoids/sandbox.lua | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/plugins/factoids/sandbox.lua') diff --git a/src/plugins/factoids/sandbox.lua b/src/plugins/factoids/sandbox.lua index 31ef5cb..3fc74cd 100644 --- a/src/plugins/factoids/sandbox.lua +++ b/src/plugins/factoids/sandbox.lua @@ -16,6 +16,7 @@ end local sandbox_env = { print = send, println = sendln, + eval = nil, args = args, input = input, user = user, @@ -49,18 +50,30 @@ sandbox_env.string.rep = nil sandbox_env.string.dump = nil sandbox_env.math.randomseed = nil -local f, e = load(factoid, nil, nil, sandbox_env) +-- Temporary evaluation function +function eval(code) + local c, e = load(code, nil, nil, sandbox_env) + if c then + return c() + else + error(e) + end +end + +sandbox_env.eval = eval -- Check if the factoid timed out function checktime(event, line) - if os.time() - time >= timeout then - error("Timed out after " .. timeout .. " seconds", 0) - else - -- Limit the cpu usage of factoids - sleep(1) - end + if os.time() - time >= timeout then + error("Timed out after " .. timeout .. " seconds", 0) + else + -- Limit the cpu usage of factoids + sleep(1) + end end +local f, e = load(factoid, nil, nil, sandbox_env) + -- Add timeout hook time = os.time() timeout = 30 -- cgit v1.2.3-70-g09d2