summaryrefslogtreecommitdiffstats
path: root/src/plugins/factoids/sandbox.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/factoids/sandbox.lua')
-rw-r--r--src/plugins/factoids/sandbox.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/plugins/factoids/sandbox.lua b/src/plugins/factoids/sandbox.lua
index 8ebf518..3fde65e 100644
--- a/src/plugins/factoids/sandbox.lua
+++ b/src/plugins/factoids/sandbox.lua
@@ -24,9 +24,26 @@ local env = { print = send,
table = table,
string = string,
tostring = tostring,
+ tonumber = tonumber,
math = math }
local f, e = load(factoid, nil, nil, env)
+
+-- 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
+end
+
+-- Add timeout hook
+time = os.time()
+timeout = 30
+debug.sethook(checktime, "l")
+
if f then
f()
else