summaryrefslogtreecommitdiff
path: root/debianbugs.py
diff options
context:
space:
mode:
Diffstat (limited to 'debianbugs.py')
-rw-r--r--debianbugs.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/debianbugs.py b/debianbugs.py
new file mode 100644
index 0000000..fe09d42
--- /dev/null
+++ b/debianbugs.py
@@ -0,0 +1,66 @@
+"""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.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@iki.fi>"
+__copyright__ = "Copyright 2004 Lars Wirzenius <liw@iki.fi>."
+__licence__ = "MIT"
+
+__module_name__ = "debianbugs"
+__module_version__ = "0.5"
+__module_description__ = \
+ "Shows links to Debian bugs, when someone says #[number]"
+
+import re
+import xchat
+
+BUG_MIN = 10000
+BUG_MAX = 600000
+
+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__))