plugins/xkcd.lua

changeset 115
6498ca5ed831
parent 109
1c94ed0bfdec
equal deleted inserted replaced
114:d11cf84975c5 115:6498ca5ed831
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

mercurial