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

36 lines
880 B
Lua
Raw Normal View History

2014-11-04 16:09:08 +01:00
function get_9GAG()
b = http.request("http://api-9gag.herokuapp.com/")
local gag = json:decode(b)
math.randomseed(os.time())
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
return link_image, title
end
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
2014-11-04 16:09:08 +01:00
function run(msg, matches)
local receiver = get_receiver(msg)
url, title = get_9GAG()
file_path = download_to_file(url)
_send_photo(receiver, file_path, send_title, {receiver, title})
return false
2014-11-04 16:09:08 +01:00
end
return {
2015-01-23 23:49:51 +01:00
description = "9GAG for telegram",
usage = "!9gag: Send random image from 9gag",
2014-11-04 22:06:59 +01:00
patterns = {"^!9gag$"},
2014-11-04 16:09:08 +01:00
run = run
}