summaryrefslogtreecommitdiffstats
path: root/src/plugins/factoids/sandbox.lua
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2019-06-22 15:51:21 +0200
committerJokler <jokler.contact@gmail.com>2019-06-22 15:51:21 +0200
commit3592c7b6fb2522ff57c7f312b8927eb680d6dc5c (patch)
treed484a367c205afe43ba7327a888b06844fd24c0c /src/plugins/factoids/sandbox.lua
parent237f6ebe59c90d4ceddd9af6a8a19e562d304aaa (diff)
parenta92e622a0d42911e8e46239c3bde17169ed60c92 (diff)
downloadfrippy-3592c7b6fb2522ff57c7f312b8927eb680d6dc5c.tar.gz
frippy-3592c7b6fb2522ff57c7f312b8927eb680d6dc5c.zip
Merge branch 'dev'HEADv0.5.0master
Diffstat (limited to 'src/plugins/factoids/sandbox.lua')
-rw-r--r--src/plugins/factoids/sandbox.lua86
1 files changed, 0 insertions, 86 deletions
diff --git a/src/plugins/factoids/sandbox.lua b/src/plugins/factoids/sandbox.lua
deleted file mode 100644
index 3fc74cd..0000000
--- a/src/plugins/factoids/sandbox.lua
+++ /dev/null
@@ -1,86 +0,0 @@
-function send(text)
- local text = tostring(text)
- local len = #output
- if len < 1 then
- output = { text }
- else
- output[len] = output[len] .. text
- end
-end
-
-function sendln(text)
- send(text)
- table.insert(output, "")
-end
-
-local sandbox_env = {
- print = send,
- println = sendln,
- eval = nil,
- args = args,
- input = input,
- user = user,
- channel = channel,
- request = download,
- string = string,
- math = math,
- table = table,
- pairs = pairs,
- ipairs = ipairs,
- next = next,
- select = select,
- unpack = unpack,
- tostring = tostring,
- tonumber = tonumber,
- type = type,
- assert = assert,
- error = error,
- pcall = pcall,
- xpcall = xpcall,
- _VERSION = _VERSION
-}
-
-sandbox_env.os = {
- clock = os.clock,
- time = os.time,
- difftime = os.difftime
-}
-
-sandbox_env.string.rep = nil
-sandbox_env.string.dump = nil
-sandbox_env.math.randomseed = nil
-
--- 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
-end
-
-local f, e = load(factoid, nil, nil, sandbox_env)
-
--- Add timeout hook
-time = os.time()
-timeout = 30
-debug.sethook(checktime, "l")
-
-if f then
- f()
-else
- error(e)
-end