Add command bts/bug (mcabber_bts)
authorMikael Berthe <mikael@lilotux.net>
Tue, 13 Apr 2010 22:43:43 +0200
changeset 6 7cf014d0d206
parent 5 a0b9529f17db
child 7 c515e8218c87
Add command bts/bug (mcabber_bts)
mcbot/cmds/mcabber_bts.lua
mcbot/mcbot_engine.lua
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mcbot/cmds/mcabber_bts.lua	Tue Apr 13 22:43:43 2010 +0200
@@ -0,0 +1,37 @@
+
+require "libs.shcmd"
+
+local function get_issue_details (num)
+    num = tonumber(num);
+    if not num then return nil end
+    local issue = {}
+    local btsurl = "http://bitbucket.org/McKael/mcabber-crew/issue/"
+
+    issue.id = tostring(num)
+    issue.url = btsurl..issue.id.."/"
+    local data = shcmd("curl "..issue.url)
+    local title = data:match("#"..issue.id.."%s*-%s*(.*)%s*&mdash;")
+    if not title then return nil end
+    issue.title = title
+    return issue
+end
+
+local function mcabber_bts (num)
+    -- Check that xepnum is a valid number
+    if num then
+        num = num:gsub("[%s%?%.%!]+$", "")
+        num = tonumber(num)
+    end
+    if not num or num < 1 then
+        return nil, "Please provide an issue number"
+    end
+    local issue = get_issue_details(num)
+    if not issue then
+        return nil,"Sorry, couldn't find issue "..tostring(num)
+    end
+    return "Issue #"..issue.id.." -- "..issue.title.."\n"..
+           "URL: <"..tostring(issue.url)..">"
+end
+
+mcbot_register_command("bts", mcabber_bts)
+mcbot_register_command("bug", mcabber_bts)
--- a/mcbot/mcbot_engine.lua	Tue Apr 13 22:04:51 2010 +0200
+++ b/mcbot/mcbot_engine.lua	Tue Apr 13 22:43:43 2010 +0200
@@ -23,6 +23,7 @@
 require "cmds.dict"
 require "cmds.misc"
 require "cmds.xep"
+require "cmds.mcabber_bts"
 
 function process (line, botdata, muc)
     local n