# HG changeset patch # User Kim Alvefur # Date 1314232226 -7200 # Node ID 5a573f1d75928d4a06dd727ba9f7273434e2b049 # Parent b7f628541981908afdc7d6d5a3339b94727f8de1# Parent 00ad6fe8975e8d273c744d2d7ea820cdf0426b0a Merge diff -r b7f628541981 -r 5a573f1d7592 plugins/version.lua --- a/plugins/version.lua Wed Aug 24 12:58:39 2011 +0200 +++ b/plugins/version.lua Thu Aug 25 02:30:26 2011 +0200 @@ -5,8 +5,9 @@ function riddim.plugins.version(bot) bot.stream:add_plugin("version"); bot.stream.version:set{ - name = "Riddim"; - version = "alpha"; + name = bot.config.bot_name or "Riddim"; + version = bot.config.bot_version or "alpha"; + platform = bot.config.bot_platform or _VERSION; }; bot:hook("commands/version", function (command) diff -r b7f628541981 -r 5a573f1d7592 plugins/xkcd.lua --- a/plugins/xkcd.lua Wed Aug 24 12:58:39 2011 +0200 +++ b/plugins/xkcd.lua Thu Aug 25 02:30:26 2011 +0200 @@ -7,9 +7,9 @@ local http = require("net.http"); bot:hook("commands/xkcd", function(command) if os.difftime(os.time(), xkcd_list_updated_at) > (3 * 60 * 60) then -- Not refreshed within 3 hours - 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) + --COMPAT We could have saved 6 bytes here, but Microsoft apparently hates %T, so you got this gigantic comment instead. + -- 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) + 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) if code == 200 then xkcd_list_updated_at = os.time(); print("debug", "got "..(#data or 0).." bytes of data"); @@ -33,46 +33,46 @@ end function handle_xkcd_command(command) - local xkcdnum = command.param; - if not xkcdnum then return "Please supply an XKCD number or a search string :)"; end - if not tonumber(xkcdnum) then -- Search for an xkcd - xkcdnum = xkcdnum:lower() - local xkcdpat = xkcdnum:gsub("[()]", function(s) return "%" .. s end) - :gsub("[%[]",function(s) return "%" .. s end) - :gsub("%%(%b[])",function(s) return (#s > 2 and "" or "%") .. s end); - local results = {}; - for x, xkcd in pairs(xkcd_list) do - name = xkcd:lower() - if name == xkcdnum then -- exact match - return xkcd..", http://xkcd.org/"..x.."/"; - elseif name:match(xkcdpat) then - table.insert(results, x); - --return commands.xkcd(msg, x); - end - end - if #results == 0 then - return "Sorry, I couldn't find a match"; - elseif #results == 1 then - command.param = results[1]; - return handle_xkcd_command(command); - else - -- We have more than one match - local ret = "Multiple matches:"; - for _, x in ipairs(results) do - local xkcdnum = tostring(tonumber(x)); - local xkcd = xkcd_list[tostring(x)]; - ret = string.format("%s %s%s", ret, xkcd, ((_ < #results) and ",") or ""); - if _ > 5 then ret = ret .. " " .. (#results - 5) .. " more"; break; end - end - return ret; - end - end - -- Check that xkcdnum is a valid number - xkcdnum = tostring(tonumber(xkcdnum)); - if not xkcdnum then return "What XKCD strip number? Or enter a search string."; end - xkcd = xkcd_list[xkcdnum]; - if not xkcd then return "Sorry, I don't think there is a XKCD #"..xkcdnum; end - return xkcd..", http://xkcd.org/"..xkcdnum.."/"; + local xkcdnum = command.param; + if not xkcdnum then return "Please supply an XKCD number or a search string :)"; end + if not tonumber(xkcdnum) then -- Search for an xkcd + xkcdnum = xkcdnum:lower() + local xkcdpat = xkcdnum:gsub("[()]", function(s) return "%" .. s end) + :gsub("[%[]",function(s) return "%" .. s end) + :gsub("%%(%b[])",function(s) return (#s > 2 and "" or "%") .. s end); + local results = {}; + for x, xkcd in pairs(xkcd_list) do + name = xkcd:lower() + if name == xkcdnum then -- exact match + return xkcd..", http://xkcd.org/"..x.."/"; + elseif name:match(xkcdpat) then + table.insert(results, x); + --return commands.xkcd(msg, x); + end + end + if #results == 0 then + return "Sorry, I couldn't find a match"; + elseif #results == 1 then + command.param = results[1]; + return handle_xkcd_command(command); + else + -- We have more than one match + local ret = "Multiple matches:"; + for _, x in ipairs(results) do + local xkcdnum = tostring(tonumber(x)); + local xkcd = xkcd_list[tostring(x)]; + ret = string.format("%s %s%s", ret, xkcd, ((_ < #results) and ",") or ""); + if _ > 5 then ret = ret .. " " .. (#results - 5) .. " more"; break; end + end + return ret; + end + end + -- Check that xkcdnum is a valid number + xkcdnum = tostring(tonumber(xkcdnum)); + if not xkcdnum then return "What XKCD strip number? Or enter a search string."; end + xkcd = xkcd_list[xkcdnum]; + if not xkcd then return "Sorry, I don't think there is a XKCD #"..xkcdnum; end + return xkcd..", http://xkcd.org/"..xkcdnum.."/"; end function parse_xkcd_list(t)