updated rechner.lua

This commit is contained in:
Akamaru 2015-05-11 20:02:19 +02:00
parent f46036adc4
commit 2c3297f834
3 changed files with 24 additions and 6 deletions

3
.gitignore vendored
View File

@ -37,4 +37,5 @@ plugins/spotify.lua
plugins/vimeo.lua
plugins/vine.lua
plugins/youtube_playlist.lua
plugins/yandere.lua
plugins/yandere.lua
plugins/e621.lua

View File

@ -3,7 +3,7 @@ socket = require("socket")
function cron()
-- Use yours desired web and id
local addr = "www.boerse.to"
local dest = "chat#id12345678"
local dest = "chat#id21091846"
-- Checks a TCP connexion
local connexion = socket.connect(addr, 80)
if not connexion then

View File

@ -1,7 +1,24 @@
function run(msg, matches)
-- Convert expression to a function and execute it
local expression = string.gsub(matches[1], "(%a+)", "math.%1")
return load('return '..expression)()
-- Function reference: http://mathjs.org/docs/reference/functions/categorical.html
local function mathjs(exp)
local url = 'http://api.mathjs.org/v1/'
url = url..'?expr='..URL.escape(exp)
local b,c = http.request(url)
local text = nil
if c == 200 then
text = 'Das Ergebnis ist '..b
elseif c == 400 then
text = b
else
text = 'Unexpected error\n'
..'Is api.mathjs.org up?'
end
return text
end
local function run(msg, matches)
return mathjs(matches[1])
end
return {