Monday, 12 January 2009

Tip of the Day: Make a Perl Script for XChat to Part/Rejoin a Channel Similar with mIRC's /HOP

For those coming from the Windows OS which are probably used to mIRC, here is a short Perl script for XChat which will do the same thing as /HOP in mIRC, and that is, it will part and rejoin a channel immediately.

By default, XChat provides the /HOP command, which is used to give chanhalf-op to the provided nickname. We will not replace this command as it still may be useful on some networks, instead we will use a new command, say /PJ (or any other you like).

The script
Here's how the script looks like:

Xchat::register ("PJ", "0.1.0", "Part/Join");

Xchat::hook_command ("PJ", cmd_pj);

Xchat::command ("ECHO PART/JOIN script loaded. Use it typing /PJ.");

sub cmd_pj
{
$chan = Xchat::get_info ("channel");
Xchat::command ("PART $chan");
Xchat::command ("JOIN $chan");
return Xchat::EAT_ALL;
}
What does it do?
Basically, the first command will tell XChat the information about the script (name, version number, description). The second one will declare the command /PJ and the subroutine to use when it's triggered, cmd_pj. The body under sub cmd_pj contains what the command will actually do, and that's to get the name of the current channel, part it and rejoin.

Save the script under any name, say pj.pl, and put it under your ~/.xchat2/ directory, where ~ is your home directory. The script will be automatically loaded each time XChat starts.

3 comments:

Anonymous said...

A slight delay on this, but for people who search and find this blog post, the command is built into XChat already as /cycle

Anonymous said...

While it is true that Xchat has the /cycle command, learning a new language for scripting it is best to start simple, and this "/hop" command is simple and gives a defiant starting point for building more complex scripts from.

Anonymous said...

very nice. this has me started