plugins/xkcd.lua

changeset 108
70db447e3669
parent 107
441ec8dcdfde
child 109
1c94ed0bfdec
equal deleted inserted replaced
107:441ec8dcdfde 108:70db447e3669
6 function riddim.plugins.xkcd(bot) 6 function riddim.plugins.xkcd(bot)
7 require "net.httpclient_listener"; 7 require "net.httpclient_listener";
8 local http = require("net.http"); 8 local http = require("net.http");
9 bot:hook("commands/xkcd", function(command) 9 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 10 if os.difftime(os.time(), xkcd_list_updated_at) > (3 * 60 * 60) then -- Not refreshed within 3 hours
11 --COMPAT We could have saved 6 bytes here, but Microsoft apparently hates %T, so you got this gigantic comment instead. 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)
12 -- http.request('http://xkcd.com/archive/', { headers = { ["If-Modified-Since"] = os.date("!%a, %d %b %Y %T %Z", xkcd_list_updated_at or 0) } }, function (data, code)
13 http.request('http://xkcd.com/archive/', { headers = { ["If-Modified-Since"] = os.date("!%a, %d %b %Y %H:%M:%S %Z", xkcd_list_updated_at or 0) } }, function (data, code)
14 if code == 200 then 12 if code == 200 then
15 xkcd_list_updated_at = os.time(); 13 xkcd_list_updated_at = os.time();
16 print("debug", "got "..(#data or 0).." bytes of data"); 14 print("debug", "got "..(#data or 0).." bytes of data");
17 parse_xkcd_list(data); 15 parse_xkcd_list(data);
18 elseif code == 304 then 16 elseif code == 304 then

mercurial