From d656ffca985b76e06e347cfc3591948ce5f75285 Mon Sep 17 00:00:00 2001 From: Akamaru Date: Sun, 20 Dec 2015 20:43:19 +0100 Subject: [PATCH] Neu: Yoda-Plugin (Only english) --- .gitignore | 3 ++- plugins/yoda.lua | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 plugins/yoda.lua diff --git a/.gitignore b/.gitignore index 92603b3..2357e09 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ plugins/dantest.lua plugins/stats2.lua plugins/help2.lua plugins/pegelf_img.lua -plugins/plex.lua \ No newline at end of file +plugins/plex.lua +plugins/chantalle.lua \ No newline at end of file diff --git a/plugins/yoda.lua b/plugins/yoda.lua new file mode 100644 index 0000000..42e8dc3 --- /dev/null +++ b/plugins/yoda.lua @@ -0,0 +1,44 @@ +local ltn12 = require "ltn12" +local https = require "ssl.https" + +local function request(text) + local api = "https://yoda.p.mashape.com/yoda?" + text = string.gsub(text, " ", "+") + local parameters = "sentence="..(text or "") + local url = api..parameters + + local api_key = cred_data.x_mashape_key + if api_key:isempty() then + return 'Configure your Mashape API Key' + end + + local headers = { + ["X-Mashape-Key"] = api_key, + ["Accept"] = "text/plain" + } + + local respbody = {} + local body, code = https.request{ + url = url, + method = "GET", + headers = headers, + sink = ltn12.sink.table(respbody), + protocol = "tlsv1" + } + if code ~= 200 then return code end + local body = table.concat(respbody) + return body +end + +local function run(msg, matches) + return request(matches[1]) +end + +return { + description = "Listen to Yoda and learn from his words!", + usage = "/yoda You will learn how to speak like me someday.", + patterns = { + "^/[Yy][Oo][Dd][Aa] (.*)$" + }, + run = run +} \ No newline at end of file