I wrote this Python snippet for XChat:
import os import xchat __module_name__ = "xchatmsgmon" __module_version__ = "0.0.0.1" __module_description__ = "Python module for monitoring messages" def on_message(word, word_eol, userdata): if '' in word[2] and \ xchat.get_info('channel').startswith('#friends') and \ 'y' in word[1]: os.system('/usr/bin/mplayer /usr/share/sounds/warning.wav') xchat.hook_print('Channel Message', on_message) print "%s loaded." % __module_name__
To load it, run /py load /path/to/script.py or just /py load script.py if you save it at default configuration directory like ~/.xchat2. Run /py unload xchatmsgmon to unload it.
You can check senders username in word[0], users mode in word[2], and the message is word[1]. After callback function is hooked by xchat.hook_print, all channel messages will be sent to the callback function. But only the messages meet the rules below:
- Sent by OP, i.e. mode with .
- Sent to channel name starts with #friends.
- With letter y in the message.
If the message meet the rules above, then a command is executed. This is just snippet, so the command may not work on your system. You can use any notification system or play media file with your favorite library. Creating GTK window with red background for ultimate attention. Whatever you want as long as you can code it.
You may also want to hook up the highlight message print event as the issue mentioned here1. You can read this xchat-python page, its a good place to get started writing about XChat Python binding.
[1] | http://forum.xchat.org/viewtopic.php?t=4585 is gone. |
0 comments:
Post a Comment