From 2c3297f8344619e508e11f03b916a73c8659b05b Mon Sep 17 00:00:00 2001 From: Akamaru Date: Mon, 11 May 2015 20:02:19 +0200 Subject: [PATCH] updated rechner.lua --- .gitignore | 3 ++- plugins/boersedown.lua | 2 +- plugins/rechner.lua | 25 +++++++++++++++++++++---- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 91507e3..c561e12 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,5 @@ plugins/spotify.lua plugins/vimeo.lua plugins/vine.lua plugins/youtube_playlist.lua -plugins/yandere.lua \ No newline at end of file +plugins/yandere.lua +plugins/e621.lua \ No newline at end of file diff --git a/plugins/boersedown.lua b/plugins/boersedown.lua index 0d1e9de..f33be94 100644 --- a/plugins/boersedown.lua +++ b/plugins/boersedown.lua @@ -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 diff --git a/plugins/rechner.lua b/plugins/rechner.lua index 921cc1d..8aac160 100644 --- a/plugins/rechner.lua +++ b/plugins/rechner.lua @@ -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 {