From 5d984b1dc12c943cc12c0076aeedd45176736f9a Mon Sep 17 00:00:00 2001 From: yago Date: Sat, 4 Oct 2014 17:36:33 +0200 Subject: [PATCH] Loop for meanings and responses --- bot/bot.lua | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index bcd3a36..ba01f78 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -280,17 +280,30 @@ function getDulcinea( text ) local api = "http://dulcinea.herokuapp.com/api/?query=" b = http.request(api..text) 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 = "" vardump(dulcinea) - for i = 1, 5, 1 do - text = text .. dulcinea.response[i].word .."\n" - text = text .. dulcinea.response[i].meanings[1].meaning .."\n" - text = text .. "\n" + local text = "" + local responses = #dulcinea.response + 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 return text