From 6fa1952dd0c1fc402ad8f3daa3a42e2dfb44eb01 Mon Sep 17 00:00:00 2001 From: yago Date: Wed, 6 Aug 2014 01:15:54 +0200 Subject: [PATCH] Usando la super api de yago de 9gag --- bot/bot.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index b68c5e8..4ff106a 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -45,12 +45,13 @@ function do_action(msg) send_msg(receiver, text) end if string.starts(msg.text, '9gag') then - url = get_infiniGAG() + url, title = get_9GAG() file_name = url:match("([^/]+)$") file = "/tmp/"..file_name sh = "curl -o '"..file.."' "..url run_bash(sh) send_photo(receiver, file) + send_msg(receiver, title) end if string.starts(msg.text, 'fortune') then text = run_bash('fortune') @@ -230,14 +231,18 @@ function get_fortunes_uc3m() return b end -function get_infiniGAG() - b, c, h = http.request("http://infinigag-us.aws.af.cm") +function get_9GAG() + b = http.request("http://api-9gag.herokuapp.com/") local gag = json:decode(b) math.randomseed(os.time()) - i = math.random(#gag.data) -- random max json table size (# is an operator o.O) - local link_image = gag.data[i].images.normal + i = math.random(#gag) -- random max json table size (# is an operator o.O) + local link_image = gag[i].src + local title = gag[i].title + if link_image:sub(0,2) == '//' then + link_image = msg.text:sub(3,-1) + end print("9gag image"..link_image) - return link_image + return link_image, title end function get_weather(location)