author | Mikael Berthe <mikael@lilotux.net> |
Mon, 12 Oct 2015 12:42:27 +0200 | |
changeset 72 | 01a4b9048880 |
parent 66 | d9c00a9fe9d5 |
permissions | -rw-r--r-- |
66
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
49
diff
changeset
|
1 |
|
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
49
diff
changeset
|
2 |
-- This module is part of the McBot / mcabbot project |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
49
diff
changeset
|
3 |
-- |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
49
diff
changeset
|
4 |
-- Copyright (C) 2010-2012 Mikael Berthe <mikael@lilotux.net> |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
49
diff
changeset
|
5 |
-- |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
49
diff
changeset
|
6 |
-- This program is free software; you can redistribute it and/or modify |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
49
diff
changeset
|
7 |
-- it under the terms of the GNU General Public License as published by |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
49
diff
changeset
|
8 |
-- the Free Software Foundation; either version 2 of the License, or (at |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
49
diff
changeset
|
9 |
-- your option) any later version. |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
49
diff
changeset
|
10 |
-- |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
49
diff
changeset
|
11 |
-- Please check the license in the COPYING file at the root of the tree. |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
49
diff
changeset
|
12 |
-- |
6
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
13 |
|
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
14 |
require "libs.shcmd" |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
15 |
|
20 | 16 |
local mcabber_bts = { ["desc"] = "Query mcabber (crew) BTS", |
46
6f8df1b79ab8
mcabber_bts: use "mcabber_bts" as the command and "bts" as an alias
Mikael Berthe <mikael@lilotux.net>
parents:
45
diff
changeset
|
17 |
["aliases"] = { "bts", "bug", "issue" } |
20 | 18 |
} |
16
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
14
diff
changeset
|
19 |
|
6
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
20 |
local function get_issue_details (num) |
8
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
21 |
local item |
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
22 |
|
6
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
23 |
num = tonumber(num); |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
24 |
if not num then return nil end |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
25 |
local issue = {} |
72 | 26 |
local btsurl = "https://bitbucket.org/McKael/mcabber-crew/issues/" |
6
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
27 |
|
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
28 |
issue.id = tostring(num) |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
29 |
issue.url = btsurl..issue.id.."/" |
49
4f7fc5acf33d
[mcabber_bts] I need -k in the chroot environment :(
Mikael Berthe <mikael@lilotux.net>
parents:
48
diff
changeset
|
30 |
local data = shcmd("curl -k "..issue.url) |
39
237af42156a1
Add checks after shcmd() calls
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
31 |
if not data then return nil end |
6
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
32 |
local title = data:match("#"..issue.id.."%s*-%s*(.*)%s*—") |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
33 |
if not title then return nil end |
72 | 34 |
issue.title = title |
35 |
issue.title = issue.title:gsub(""", "\""):gsub("&", "&") |
|
14
5c3ef7c5ba6c
Handle some more HTML tags in mcabber_bts
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
36 |
issue.title = issue.title:gsub("<", "<"):gsub(">", ">") |
13 | 37 |
issue.title = issue.title:gsub("'", "'") |
72 | 38 |
issue.title = issue.title:gsub("[%s\n]+$", "") -- trailing newlines |
8
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
39 |
|
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
40 |
-- Get Status |
72 | 41 |
item = data:match('<a href="[^"]+/issues%?status=(%w+)"') |
8
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
42 |
if item then issue.status = item end |
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
43 |
-- Get Type |
72 | 44 |
item = data:match('<a href="[^"]+/issues%?kind=(%w+)"') |
8
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
45 |
if item then issue.type = item end |
72 | 46 |
-- Get Priority |
47 |
item = data:match('<a href="[^"]+/issues%?priority=(%w+)"') |
|
48 |
if item then issue.priority = item end |
|
8
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
49 |
|
6
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
50 |
return issue |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
51 |
end |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
52 |
|
16
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
14
diff
changeset
|
53 |
function mcabber_bts.cmd (num) |
6
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
54 |
-- Check that xepnum is a valid number |
45
d333cb35e79a
Allow #number in the mcabber_bts command
Mikael Berthe <mikael@lilotux.net>
parents:
39
diff
changeset
|
55 |
if num then |
d333cb35e79a
Allow #number in the mcabber_bts command
Mikael Berthe <mikael@lilotux.net>
parents:
39
diff
changeset
|
56 |
num = num:gsub("[%s%?%.%!]+$", "") |
d333cb35e79a
Allow #number in the mcabber_bts command
Mikael Berthe <mikael@lilotux.net>
parents:
39
diff
changeset
|
57 |
num = num:gsub("^#", "") |
d333cb35e79a
Allow #number in the mcabber_bts command
Mikael Berthe <mikael@lilotux.net>
parents:
39
diff
changeset
|
58 |
end |
7 | 59 |
num = tonumber(num) |
6
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
60 |
if not num or num < 1 then |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
61 |
return nil, "Please provide an issue number" |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
62 |
end |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
63 |
local issue = get_issue_details(num) |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
64 |
if not issue then |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
65 |
return nil,"Sorry, couldn't find issue "..tostring(num) |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
66 |
end |
8
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
67 |
|
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
68 |
local result = "Issue #"..issue.id.." -- "..issue.title.."\n" |
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
69 |
if issue.status then |
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
70 |
result = result .. "Status: " .. issue.status .. "\n" |
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
71 |
end |
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
72 |
if issue.type then |
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
73 |
result = result .. "Type: " .. issue.type .. "\n" |
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
74 |
end |
72 | 75 |
if issue.type then |
76 |
result = result .. "Priority: " .. issue.priority .. "\n" |
|
77 |
end |
|
8
db84d97cf13d
Improve mcabber_bts (display status and type)
Mikael Berthe <mikael@lilotux.net>
parents:
7
diff
changeset
|
78 |
return result .. "URL: <"..tostring(issue.url)..">" |
6
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
79 |
end |
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
80 |
|
47
4b3b839c8f36
mcabber_bts: actually use "mcabberbts" as the command name
Mikael Berthe <mikael@lilotux.net>
parents:
46
diff
changeset
|
81 |
mcbot_register_command("mcabberbts", mcabber_bts) |