From ba6ce31fc06bb31d6b1a323dea7cf5b541ea9082 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 14 Mar 2010 09:51:16 +1300 Subject: Initial commit. These versions are old, but only now under version control. --- debianbugs.py | 66 +++++++++++++++++++++++++++++++++++ topicdiff.py | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ whiteout.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 260 insertions(+) create mode 100644 debianbugs.py create mode 100644 topicdiff.py create mode 100644 whiteout.py 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 " +__copyright__ = "Copyright 2004 Lars Wirzenius ." +__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"(?\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__)) diff --git a/topicdiff.py b/topicdiff.py new file mode 100644 index 0000000..e58c0ba --- /dev/null +++ b/topicdiff.py @@ -0,0 +1,108 @@ +"""X-Chat 2.0 plugin to show changes made to the topic. + +Place in your .xchat2 directory and either reload X-Chat or +/PY LOAD topicdiff.py + +0.1 14jan04 initial version +0.2 15jan04 removed UTF-8 (C) that Python didn't like + don't return changes list when everything changes +0.3 17jan04 fix bug when no initial topic + fix bug when entire list of words get changed +""" + +__author__ = "Scott James Remnant " +__copyright__ = "Copyright (C) 2004 Scott James Remnant ." +__licence__ = "MIT" + +__module_name__ = "topicdiff" +__module_version__ = "0.3" +__module_description__ = "Shows changes made to the topic" + +import re +import xchat + +def strdiff(old_str, new_str): + changes = [] + unchanged = 0 + last_hanging = 0 + + if old_str is None or new_str is None: + return [] + + old_words = re.sub(r'\s+', ' ', old_str).strip().split(" ") + new_words = re.sub(r'\s+', ' ', new_str).strip().split(" ") + + while len(old_words) and len(new_words): + if new_words[0] == old_words[0]: + # Both words match, carry on to the next + new_words = new_words[1:] + old_words = old_words[1:] + last_hanging = 0 + unchanged += 1 + else: + try: + # Are the first two new words later in old_words? + # If so, we've got deletions + idx = old_words.index(new_words[0]) + if idx > 0 and old_words[idx + 1] == new_words[1]: + changes.append(["-", " ".join(old_words[0:idx])]) + old_words = old_words[idx:] + last_hanging = 0 + continue + except ValueError: + pass + except IndexError: + pass + + try: + # Are the first two old words later in new_words? + # If so, we've got additions + idx = new_words.index(old_words[0]) + if idx > 0 and new_words[idx + 1] == old_words[1]: + changes.append(["+", " ".join(new_words[0:idx])]) + new_words = new_words[idx:] + last_hanging = 0 + continue + except ValueError: + pass + except IndexError: + pass + + # Swapped words, just kill the old one + # If we did this last time, just append to it (for when an entire + # section of the string is swapped with another) + if last_hanging: + changes[-1][1] += " " + old_words[0] + else: + changes.append(["-", old_words[0]]) + old_words = old_words[1:] + last_hanging = 1 + + if len(old_words): + changes.append(["-", " ".join(old_words)]) + if len(new_words): + changes.append(["+", " ".join(new_words)]) + + if unchanged: + return changes + else: + return [] + + +def topic_change_cb(word, word_eol, userdata): + ctx = xchat.get_context() + + channel = ctx.get_info("channel") + old_topic = ctx.get_info("topic") + new_topic = word_eol[3] + if new_topic.startswith(":"): + new_topic = new_topic[1:] + + changes = strdiff(old_topic, new_topic) + for mod, change in changes: + ctx.prnt("[Topic] %s %s" % (mod, change,)) + + return xchat.EAT_NONE + + +xchat.hook_server("TOPIC", topic_change_cb) diff --git a/whiteout.py b/whiteout.py new file mode 100644 index 0000000..99526ca --- /dev/null +++ b/whiteout.py @@ -0,0 +1,86 @@ +"""X-Chat 2.0 plugin to hide what ignored people say on channel. + +Messages from people (nicknames) that are ignored (using /ignore) are +printed with the same foreground and background color. This is better +than normal /ignore, since it reduces your confusion by making it clear +that the ignored people are talking. Also, you can select the text with +a mouse and see what they're saying, in case it is something important. +(If you do that a lot, there's no point in using /ignore, though.) + +Place in your .xchat2 directory and either reload X-Chat or +/PY LOAD whiteout.py + +0.2 15 Aug 2005 Remove ":+" and ":-" prefixes from the message of + a user. I should read about the IRC protocol. +0.1 10 Aug 2005 Initial version, based on Scott James Remnant's + topicdiff.py. +""" + +__author__ = "Lars Wirzenius " +__copyright__ = "Copyright 2005 Lars Wirzenius ." +__licence__ = "MIT" + +__module_name__ = "whiteout" +__module_version__ = "0.2" +__module_description__ = \ + "Show ignored channel messages with same fore/background color" + +import re +import xchat + +# Change this to select the color you want to use. +COLOR = 0 + +nick_pattern = re.compile(r":(?P[^!]+)!") + +def matches_ignore_mask(mask, userspec): + regexp = ":" # userspec always seems to start with a colon + for c in mask: + if c == "*": + regexp += ".*" + elif c == "?": + regexp += "." + elif c in ".\\": + regexp += "\\" + c + else: + regexp += c + + if "!" not in mask: + regexp += "!.*" + + return re.match(regexp, userspec) != None + +def is_ignored(userspec): + for ignored in xchat.get_list("ignore"): + if ignored.flags & 1 and matches_ignore_mask(ignored.mask, userspec): + return True + return False + +def parse_nickname(userspec): + m = nick_pattern.match(userspec) + if m: + return m.group("nick") + else: + return None + +def privmsg_cb(word, word_eol, userdata): + ctx = xchat.get_context() + + channel = ctx.get_info("channel") + nickname = parse_nickname(word[0]) + if is_ignored(word[0]): + start_color = "\003%02d,%02d" % (COLOR, COLOR) + end_color = "\003" + msg = word_eol[3] + if msg[:2] in [":-", ":+"]: + msg = msg[2:] + elif msg[:1] == ":": + msg = msg[1:] + ctx.emit_print("Channel Message", nickname, + start_color + msg + end_color) + return xchat.EAT_ALL + + return xchat.EAT_NONE + +xchat.hook_server("PRIVMSG", privmsg_cb) +xchat.prnt("%s %s loaded" % (__module_name__, __module_version__)) -- cgit v1.2.1