-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path9gag.lua
35 lines (30 loc) · 880 Bytes
/
9gag.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)
if success then
send_msg(cb_extra[1], cb_extra[2], ok_cb, false)
end
end
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
end
return {
description = "9GAG for telegram",
usage = "!9gag: Send random image from 9gag",
patterns = {"^!9gag$"},
run = run
}