"""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 " __copyright__ = "Copyright 2010 Lars Wirzenius ." __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"(?\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__))