Neu: Yoda-Plugin (Only english)

This commit is contained in:
Akamaru 2015-12-20 20:43:19 +01:00
parent 0e2991b9ea
commit d656ffca98
2 changed files with 46 additions and 1 deletions

3
.gitignore vendored
View File

@ -7,4 +7,5 @@ plugins/dantest.lua
plugins/stats2.lua
plugins/help2.lua
plugins/pegelf_img.lua
plugins/plex.lua
plugins/plex.lua
plugins/chantalle.lua

44
plugins/yoda.lua Normal file
View File

@ -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
}