# HG changeset patch # User Mikael Berthe # Date 1272098700 -7200 # Node ID 237af42156a1a027800c7e62e5aa1e7a04359c6f # Parent a51ddbce247b61f8b44740ccaece45d21995557c Add checks after shcmd() calls diff -r a51ddbce247b -r 237af42156a1 mcbot/cmds/mcabber_bts.lua --- a/mcbot/cmds/mcabber_bts.lua Mon Apr 19 10:20:28 2010 +0200 +++ b/mcbot/cmds/mcabber_bts.lua Sat Apr 24 10:45:00 2010 +0200 @@ -16,6 +16,7 @@ issue.id = tostring(num) issue.url = btsurl..issue.id.."/" local data = shcmd("curl "..issue.url) + if not data then return nil end local title = data:match("#"..issue.id.."%s*-%s*(.*)%s*—") if not title then return nil end issue.title = title:gsub(""", "\""):gsub("&", "&") diff -r a51ddbce247b -r 237af42156a1 mcbot/cmds/tvcal.lua --- a/mcbot/cmds/tvcal.lua Mon Apr 19 10:20:28 2010 +0200 +++ b/mcbot/cmds/tvcal.lua Sat Apr 24 10:45:00 2010 +0200 @@ -28,6 +28,10 @@ local function parse_webpage (url) local contents = shcmd("curl "..url) + if not contents then + return nil, "Could not fetch calendar, please try again later!" + end + local tabregex = '%s*\n%s*'.. '(.-)
' diff -r a51ddbce247b -r 237af42156a1 mcbot/cmds/xep.lua --- a/mcbot/cmds/xep.lua Mon Apr 19 10:20:28 2010 +0200 +++ b/mcbot/cmds/xep.lua Sat Apr 24 10:45:00 2010 +0200 @@ -29,8 +29,10 @@ if os.difftime(now, xeps_updated_at) < 43200 then return end -- Let's get some fresh data local xepdata = shcmd(xeplisturl) - xeps_updated_at = now - parse_xeps(xepdata) + if xepdata then + xeps_updated_at = now + parse_xeps(xepdata) + end end -- Deeply inspired by MattJ's riddim bot diff -r a51ddbce247b -r 237af42156a1 mcbot/libs/shcmd.lua --- a/mcbot/libs/shcmd.lua Mon Apr 19 10:20:28 2010 +0200 +++ b/mcbot/libs/shcmd.lua Sat Apr 24 10:45:00 2010 +0200 @@ -6,6 +6,7 @@ local fh = io.popen(fullcmd) result = fh:read("*a") -- read cmd output fh:close() + if not result then return nil end -- Trim trailing newlines local r = result:gsub("\n+$", "") return r