diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-03-14 09:51:16 +1300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-03-14 09:51:16 +1300 |
commit | ba6ce31fc06bb31d6b1a323dea7cf5b541ea9082 (patch) | |
tree | b734efcc85d32d30d012652eeb434ab44f0bbb5a /whiteout.py | |
download | xchat-plugins-liw-ba6ce31fc06bb31d6b1a323dea7cf5b541ea9082.tar.gz |
Initial commit. These versions are old, but only now under version
control.
Diffstat (limited to 'whiteout.py')
-rw-r--r-- | whiteout.py | 86 |
1 files changed, 86 insertions, 0 deletions
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 <liw@iki.fi>" +__copyright__ = "Copyright 2005 Lars Wirzenius <liw@iki.fi>." +__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<nick>[^!]+)!") + +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__)) |