Archive for May, 2009

XChat notification and highlighting on phrases instead of single words

I wrote the following xchat plugin after they decided to “fix” the Extra words to highlight feature in XChat 2.8.6

The python plugin can be downloaded here

__module_name__ = 'hilight-phrase'
__module_description__ = 'XChat notification and hilighting on phrases instead of single words'
__module_version__ = '2.0'

import xchat, os, re

CONFFILE = os.environ['HOME'] + '/.xchat2/hilight-phrase.conf'

xchat.prnt('%(name)s, version %(version)s' % {'name': __module_name__,  'version': __module_version__})  

def read_list():
        conf = open(CONFFILE,'r')
        xchat.prnt(CONFFILE + " currently doesn't exist, creating")
        return None
    lines = conf.readlines()
    for each in lines:

def save_list():
    conf = open(CONFFILE,'w')
    for phrase in list:
        conf.write(phrase + '\n')

def check_msg(word, word_eol, userdata):
    for phrase in list:
        if phrase in word_eol[1].lower():
            xchat.command("gui color 3")
            xchat.emit_print( "Channel Msg Hilight", word[0], word[1] )
            return xchat.EAT_ALL

    return xchat.EAT_NONE

def add_hilight_phrase(word, word_eol, userdata):
    if len(word) == 1:
        return list_hilight_phrase(word, word_eol, userdata)
    phrase = word_eol[1]
    if phrase not in list:
        xchat.prnt('\x032* "%s" will be hilighted' % phrase)
        xchat.prnt('\x032* "%s" is already being hilighted' % phrase)
    return xchat.EAT_XCHAT

def list_hilight_phrase(word, word_eol, userdata):
    xchat.prnt('\x032Current hilight-phrase list: %d hilighted.' % len(list))
    for phrase in list:
        xchat.prnt('\x032  -- %s' % phrase)
    xchat.prnt('\x032* End of hilight-phrase list')
    return xchat.EAT_XCHAT

def remove_hilight_phrase(word, word_eol, userdata):
    phrase = word_eol[1]
    if phrase in list:
        xchat.prnt('\x032 "%s" has been removed from the hilight list' % phrase)
        xchat.prnt('\x032 "%s" is not in the hilight list' % phrase)
    return xchat.EAT_XCHAT

xchat.hook_command("hilight-add", add_hilight_phrase)
xchat.hook_command("hilight-list", list_hilight_phrase)
xchat.hook_command("hilight-remove", remove_hilight_phrase)
xchat.hook_print("Channel Message", check_msg)

You can use the plugin by either:
1. manually loading the file through the menu (Windows -> Plugins and Scripts) every time you restart xchat
2. copy the to your $HOME/.xchat2/ direcory where it will get loaded automatically when xchat is run.

Once loaded, a /hilight-list will list all of the currently active phrases to highlight. A /hilight-add <phrase> where <phrase> is a string will add the specified phrase to the list. As you can probably guess, a /hilight-remove <phrase> where <phrase> is a currently active phrase will remove it from the list.

Feel free to comment and leave suggestions.

Tuesday, May 26th, 2009 Technology 10 Comments