Tuesday 13 January 2009

Tip of the Day: Make a Perl Script for XChat to Display Notices in Current Window

In my last Tip of the Day article I showed you how to create a simple part/join command in Perl. Today I'll continue with a script which will make XChat display notices in the current window.

The script

Xchat::register ("CWN", "0.1.0", "Displays notices in current window");

Xchat::hook_print ("Notice", cw_notice, "");

sub cw_notice
{
Xchat::set_context Xchat::find_context
Xchat::command ("ECHO Received a notice from $_[0][0]: $_[0][1]");
return Xchat::EAT_ALL;
}

As you can see in the Xchat::hook_print command, the subroutine cw_notice will be executed when a notice is sent to you. You can find these events like Notice, Channel Message, Channel Action etc in the Settings -> Advanced -> Text Events... menu in XChat.

The cw_notice subroutine will set the context to your current window and will echo in it the nick and the notice received.

No comments: