diff options
| author | Jokler <jokler.contact@gmail.com> | 2018-05-06 21:17:54 +0200 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2018-05-06 21:17:54 +0200 |
| commit | 777bfcd9ba4453ad610ca7cf4c23c0de05387045 (patch) | |
| tree | 36e0bbca506d8c7f4d47fb7de2a10faa05129116 | |
| parent | 30fc85d81c54059699bd07d03473b6b87194f1bc (diff) | |
| download | frippy-777bfcd9ba4453ad610ca7cf4c23c0de05387045.tar.gz frippy-777bfcd9ba4453ad610ca7cf4c23c0de05387045.zip | |
Factoids: Add trim function and ioru var to lua
| -rw-r--r-- | src/plugins/factoids/sandbox.lua | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/plugins/factoids/sandbox.lua b/src/plugins/factoids/sandbox.lua index 6fcabef..59e6d9e 100644 --- a/src/plugins/factoids/sandbox.lua +++ b/src/plugins/factoids/sandbox.lua @@ -13,14 +13,29 @@ function sendln(text) table.insert(output, "") end +function trim(s) + local from = s:match"^%s*()" + return from > #s and "" or s:match(".*%S", from) +end + +trimmed_input = trim(input) + +if trimmed_input == "" then + ioru = user +else + ioru = trimmed_input +end + local sandbox_env = { print = send, println = sendln, + trim = trim, eval = nil, sleep = nil, args = args, input = input, user = user, + ioru = ioru, channel = channel, request = download, string = string, @@ -64,11 +79,11 @@ end -- Only sleeps for 1 second at a time -- This ensures that the timeout check can still run function safesleep(dur) - while dur > 1000 do - dur = dur - 1000 - sleep(1000) - end - sleep(dur) + while dur > 1000 do + dur = dur - 1000 + sleep(1000) + end + sleep(dur) end sandbox_env.eval = eval |
