This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/9gag.lua

38 lines
830 B
Lua
Raw Normal View History

do
2014-11-04 16:09:08 +01:00
2015-04-05 16:26:30 +02:00
local function get_9GAG()
local url = "http://api-9gag.herokuapp.com/"
local b,c = http.request(url)
if c ~= 200 then return nil end
local gag = json:decode(b)
2015-04-05 16:26:30 +02:00
-- random max json table size
local i = math.random(#gag)
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
return link_image, title
2014-11-04 16:09:08 +01:00
end
2015-04-05 16:26:30 +02:00
local function send_title(cb_extra, success, result)
2014-11-22 14:25:53 +01:00
if success then
send_msg(cb_extra[1], cb_extra[2], ok_cb, false)
2014-11-22 14:25:53 +01:00
end
end
2015-04-05 16:26:30 +02:00
local function run(msg, matches)
2014-11-04 16:09:08 +01:00
local receiver = get_receiver(msg)
2015-04-05 16:26:30 +02:00
local url, title = get_9GAG()
2015-04-16 20:14:36 +02:00
send_photo_from_url(receiver, url, send_title, {receiver, title})
return false
2014-11-04 16:09:08 +01:00
end
return {
2015-04-14 20:21:23 +02:00
description = "9GAG",
2015-04-28 17:49:11 +02:00
usage = {"/9gag"},
2015-04-14 20:21:23 +02:00
patterns = {"^/9gag$"},
run = run
2014-11-04 16:09:08 +01:00
}
end