Skip to content

Commit

Permalink
Added yoda plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
DevPGSV committed Jun 4, 2015
1 parent f13013d commit 1185d11
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions plugins/yoda.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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 https = require("ssl.https")
local respbody = {}
local ltn12 = require "ltn12"
local headers = {
["X-Mashape-Key"] = "5j2cydo37tmshgTnssARJN6VuGqkp1ggaTojsnP2fharkD2Uir",
["Accept"] = "text/plain"
}
print(url)
local body, code, headers, status = 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)
print(body)
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 = {
"^![y|Y]oda (.*)$"
},
run = run
}

0 comments on commit 1185d11

Please sign in to comment.