mcbot/cmds/mcabber_bts.lua
changeset 72 01a4b9048880
parent 66 d9c00a9fe9d5
equal deleted inserted replaced
71:63ee968309d4 72:01a4b9048880
    21     local item
    21     local item
    22 
    22 
    23     num = tonumber(num);
    23     num = tonumber(num);
    24     if not num then return nil end
    24     if not num then return nil end
    25     local issue = {}
    25     local issue = {}
    26     local btsurl = "https://bitbucket.org/McKael/mcabber-crew/issue/"
    26     local btsurl = "https://bitbucket.org/McKael/mcabber-crew/issues/"
    27 
    27 
    28     issue.id = tostring(num)
    28     issue.id = tostring(num)
    29     issue.url = btsurl..issue.id.."/"
    29     issue.url = btsurl..issue.id.."/"
    30     local data = shcmd("curl -k "..issue.url)
    30     local data = shcmd("curl -k "..issue.url)
    31     if not data then return nil end
    31     if not data then return nil end
    32     local title = data:match("#"..issue.id.."%s*-%s*(.*)%s*—")
    32     local title = data:match("#"..issue.id.."%s*-%s*(.*)%s*—")
    33     if not title then return nil end
    33     if not title then return nil end
    34     issue.title = title:gsub(""", "\""):gsub("&", "&")
    34     issue.title = title
       
    35     issue.title = issue.title:gsub(""", "\""):gsub("&", "&")
    35     issue.title = issue.title:gsub("&lt;", "<"):gsub("&gt;", ">")
    36     issue.title = issue.title:gsub("&lt;", "<"):gsub("&gt;", ">")
    36     issue.title = issue.title:gsub("&#39;", "'")
    37     issue.title = issue.title:gsub("&#39;", "'")
       
    38     issue.title = issue.title:gsub("[%s\n]+$", "") -- trailing newlines
    37 
    39 
    38     -- Get Status
    40     -- Get Status
    39     item = data:match("Status:%s*</td>%s*<td [^>]*>(.-)</td>")
    41     item = data:match('<a href="[^"]+/issues%?status=(%w+)"')
    40     if item then issue.status = item end
    42     if item then issue.status = item end
    41     -- Get Type
    43     -- Get Type
    42     item = data:match("Type:%s*</td>%s*<td [^>]*>(.-)</td>")
    44     item = data:match('<a href="[^"]+/issues%?kind=(%w+)"')
    43     if item then issue.type = item end
    45     if item then issue.type = item end
       
    46     -- Get Priority
       
    47     item = data:match('<a href="[^"]+/issues%?priority=(%w+)"')
       
    48     if item then issue.priority = item end
    44 
    49 
    45     return issue
    50     return issue
    46 end
    51 end
    47 
    52 
    48 function mcabber_bts.cmd (num)
    53 function mcabber_bts.cmd (num)
    65         result = result .. "Status: " .. issue.status .. "\n"
    70         result = result .. "Status: " .. issue.status .. "\n"
    66     end
    71     end
    67     if issue.type then
    72     if issue.type then
    68         result = result .. "Type: " .. issue.type .. "\n"
    73         result = result .. "Type: " .. issue.type .. "\n"
    69     end
    74     end
       
    75     if issue.type then
       
    76         result = result .. "Priority: " .. issue.priority .. "\n"
       
    77     end
    70     return result .. "URL: <"..tostring(issue.url)..">"
    78     return result .. "URL: <"..tostring(issue.url)..">"
    71 end
    79 end
    72 
    80 
    73 mcbot_register_command("mcabberbts", mcabber_bts)
    81 mcbot_register_command("mcabberbts", mcabber_bts)