summaryrefslogtreecommitdiff
path: root/debianbugs.py
blob: 8e512e19399c04f718695580678d67331814bae1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""X-Chat 2.0 plugin to show links to Debian bugs.

Place in your .xchat2 directory and either reload X-Chat or
/PY LOAD topicdiff.py

0.6     26 Oct 2010     Allow bug numbers up to one million.
0.5     23 Jun 2008     Add support for Ubuntu/Launchpad.
0.4     21 May 2006     Change channel pattern from *debian* to *deb*.
0.3     12 Jun 2005     Limit bug numbers to be below 4e5 to reduce false
                        positives.
0.2     23 Jan 2005     Dont' require # in front of version number, but allow
                        it and do require white space.
0.1     18 Sep 2004     Initial version, based on Scott James Remnant's
                        topicdiff.py.
"""

__author__ = "Lars Wirzenius <liw@liw.fi>"
__copyright__ = "Copyright 2010 Lars Wirzenius <liw@liw.fi>."
__licence__ = "MIT"

__module_name__ = "debianbugs"
__module_version__ = "0.6"
__module_description__ = \
    "Shows links to Debian/Ubuntu bugs, when someone says #[number]"

import re
import xchat

BUG_MIN = 10000
BUG_MAX = 1000000

patterns = {
    r"#.*deb.*": "http://bugs.debian.org/%s",
    r"#ubuntu.*": "https://bugs.launchpad.net/bugs/%s",
    r"#canonical": "https://bugs.launchpad.net/bugs/%s",
    r"#distro": "https://bugs.launchpad.net/bugs/%s",
}

bug_pattern = re.compile(r"(?<![=/?.])\b#?(?P<number>\d+)")

def privmsg_cb(word, word_eol, userdata):
    ctx = xchat.get_context()
    
    channel = ctx.get_info("channel")
    for chanpat in patterns.keys():
        if re.match(chanpat, channel):
            bugs = []
            for w in word[3:]:
                m = bug_pattern.search(w)
                if m:
                    n = m.group("number")
                    try:
                        n = int(n)
                    except ValueError:
                        pass
                    else:
                        if n >= BUG_MIN and n <= BUG_MAX and n not in bugs:
                            bugs.append(n)
            if bugs:
                bts_url = patterns[chanpat]
                ctx.emit_print("Channel Message", "###########", 
                               " ".join(bts_url % bug for bug in bugs))

    return xchat.EAT_NONE

xchat.hook_server("PRIVMSG", privmsg_cb)
xchat.prnt("%s %s loaded" % (__module_name__, __module_version__))