2 local xkcd_list_updated_at = 0; |
2 local xkcd_list_updated_at = 0; |
3 local xkcd_list = { }; |
3 local xkcd_list = { }; |
4 local handle_xkcd_command; |
4 local handle_xkcd_command; |
5 |
5 |
6 function riddim.plugins.xkcd(bot) |
6 function riddim.plugins.xkcd(bot) |
7 require "net.httpclient_listener"; |
|
8 local http = require("net.http"); |
7 local http = require("net.http"); |
9 bot:hook("commands/xkcd", function(command) |
8 bot:hook("commands/xkcd", function(command) |
10 if os.difftime(os.time(), xkcd_list_updated_at) > (3 * 60 * 60) then -- Not refreshed within 3 hours |
9 if os.difftime(os.time(), xkcd_list_updated_at) > (3 * 60 * 60) then -- Not refreshed within 3 hours |
11 http.request('http://xkcd.com/archive/', { headers = { ["If-Modified-Since"] = os.date("!%a, %d %b %Y %H:%M:%S %Z", xkcd_list_updated_at) } }, function (data, code) |
10 http.request('http://xkcd.com/archive/', { headers = { ["If-Modified-Since"] = os.date("!%a, %d %b %Y %H:%M:%S %Z", xkcd_list_updated_at) } }, function (data, code) |
12 if code == 200 then |
11 if code == 200 then |