@javierhonduco Dulcinea
This commit is contained in:
parent
57ad52893f
commit
86c8096631
46
bot/bot.lua
46
bot/bot.lua
@ -59,7 +59,6 @@ function send_image_from_url (msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function is_image_url(text)
|
function is_image_url(text)
|
||||||
print ('IS image ' .. text ..'?')
|
|
||||||
last = string.get_last_word(text)
|
last = string.get_last_word(text)
|
||||||
extension = string.get_extension_from_filename(last)
|
extension = string.get_extension_from_filename(last)
|
||||||
if extension == 'jpg' or extension == 'png' then
|
if extension == 'jpg' or extension == 'png' then
|
||||||
@ -102,6 +101,12 @@ function do_action(msg)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if string.starts(msg.text, '!rae') then
|
||||||
|
text = msg.text:sub(6,-1)
|
||||||
|
meaning = getDulcinea(text)
|
||||||
|
send_msg(receiver, meaning, ok_cb, false)
|
||||||
|
end
|
||||||
|
|
||||||
if string.starts(msg.text, '!9gag') then
|
if string.starts(msg.text, '!9gag') then
|
||||||
url, title = get_9GAG()
|
url, title = get_9GAG()
|
||||||
file_path = download_to_file(url)
|
file_path = download_to_file(url)
|
||||||
@ -271,14 +276,39 @@ function get_fortunes_uc3m()
|
|||||||
return b
|
return b
|
||||||
end
|
end
|
||||||
|
|
||||||
function getGoogleImage(text)
|
function getDulcinea( text )
|
||||||
local api = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q="
|
local api = "http://dulcinea.herokuapp.com/api/?query="
|
||||||
text = URL.escape(text)
|
|
||||||
b = http.request(api..text)
|
b = http.request(api..text)
|
||||||
local google = json:decode(b)
|
dulcinea = json:decode(b)
|
||||||
math.randomseed(os.time())
|
while dulcinea.type == "multiple" do
|
||||||
i = math.random(#google.responseData.results)
|
text = dulcinea.response[1].id
|
||||||
return google.responseData.results[i].url
|
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"
|
||||||
|
end
|
||||||
|
return text
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function getGoogleImage(text)
|
||||||
|
text = URL.escape(text)
|
||||||
|
for i = 1, 5, 1 do -- Try 5 times
|
||||||
|
local api = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q="
|
||||||
|
b = http.request(api..text)
|
||||||
|
local google = json:decode(b)
|
||||||
|
|
||||||
|
if (google.responseStatus == 200) then -- OK
|
||||||
|
math.randomseed(os.time())
|
||||||
|
i = math.random(#google.responseData.results) -- Random image from results
|
||||||
|
return google.responseData.results[i].url
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_9GAG()
|
function get_9GAG()
|
||||||
|
Reference in New Issue
Block a user