2015-05-11 20:02:19 +02:00
|
|
|
-- Function reference: http://mathjs.org/docs/reference/functions/categorical.html
|
|
|
|
|
|
|
|
local function mathjs(exp)
|
2015-11-13 14:02:09 +01:00
|
|
|
local exp = string.gsub(exp, ",", ".")
|
2015-05-11 20:02:19 +02:00
|
|
|
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
|
2015-12-01 20:52:20 +01:00
|
|
|
text = 'Ergebnis: '..b
|
2015-05-11 20:02:19 +02:00
|
|
|
|
|
|
|
elseif c == 400 then
|
|
|
|
text = b
|
|
|
|
else
|
2015-12-01 20:52:20 +01:00
|
|
|
text = 'Unerwarteter Fehler\nIst api.mathjs.org erreichbar?'
|
2015-05-11 20:02:19 +02:00
|
|
|
end
|
|
|
|
return text
|
|
|
|
end
|
|
|
|
|
|
|
|
local function run(msg, matches)
|
|
|
|
return mathjs(matches[1])
|
2015-04-14 22:20:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2015-11-12 17:42:03 +01:00
|
|
|
description = "Rechnen mit der mathjs-API",
|
|
|
|
usage = {
|
2016-06-22 13:59:06 +02:00
|
|
|
"#calc [Ausdruck]: Rechnet",
|
2015-11-12 17:42:03 +01:00
|
|
|
"Weitere Hilfe: + = Plus, - = Minus, * = Mal, / = geteilt"
|
|
|
|
},
|
|
|
|
patterns = {
|
2016-06-22 13:59:06 +02:00
|
|
|
"^#calc (.*)$"
|
2015-11-12 17:42:03 +01:00
|
|
|
},
|
2015-04-14 22:20:26 +02:00
|
|
|
run = run
|
|
|
|
}
|