2014-11-04 16:09:08 +01:00
|
|
|
function getDulcinea( text )
|
|
|
|
-- Powered by https://github.com/javierhonduco/dulcinea
|
|
|
|
local api = "http://dulcinea.herokuapp.com/api/?query="
|
2014-11-22 21:23:48 +01:00
|
|
|
local query_url = api..text
|
|
|
|
b = http.request(query_url)
|
2014-11-04 16:09:08 +01:00
|
|
|
dulcinea = json:decode(b)
|
|
|
|
if dulcinea.status == "error" then
|
|
|
|
return "Error: " .. dulcinea.message
|
|
|
|
end
|
|
|
|
while dulcinea.type == "multiple" do
|
|
|
|
text = dulcinea.response[1].id
|
|
|
|
b = http.request(api..text)
|
|
|
|
dulcinea = json:decode(b)
|
|
|
|
end
|
|
|
|
local text = ""
|
|
|
|
local responses = #dulcinea.response
|
2014-11-22 21:23:48 +01:00
|
|
|
if responses == 0 then
|
|
|
|
return "Error: 404 word not found"
|
|
|
|
end
|
2014-11-04 16:09:08 +01:00
|
|
|
if (responses > 5) then
|
|
|
|
responses = 5
|
|
|
|
end
|
|
|
|
for i = 1, responses, 1 do
|
|
|
|
text = text .. dulcinea.response[i].word .. "\n"
|
|
|
|
local meanings = #dulcinea.response[i].meanings
|
|
|
|
if (meanings > 5) then
|
|
|
|
meanings = 5
|
|
|
|
end
|
|
|
|
for j = 1, meanings, 1 do
|
|
|
|
local meaning = dulcinea.response[i].meanings[j].meaning
|
|
|
|
text = text .. meaning .. "\n\n"
|
|
|
|
end
|
|
|
|
end
|
2014-11-22 21:23:48 +01:00
|
|
|
print (text)
|
2014-11-04 16:09:08 +01:00
|
|
|
return text
|
|
|
|
end
|
|
|
|
|
|
|
|
function run(msg, matches)
|
|
|
|
return getDulcinea(matches[1])
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2014-11-28 14:50:41 +01:00
|
|
|
description = "Spanish dictionary",
|
2015-02-04 23:03:42 +01:00
|
|
|
usage = "!rae [word]: Search that word in Spanish dictionary. Powered by https://github.com/javierhonduco/dulcinea",
|
2014-11-28 14:50:41 +01:00
|
|
|
patterns = {"^!rae (.*)$"},
|
|
|
|
run = run
|
2014-11-04 16:09:08 +01:00
|
|
|
}
|
|
|
|
|