Xchat Perl Docs
Good Hello!
The purpose of this page is to give people some quick documentation on the
things that they will encounter when they try to code scripts for X-Chat.
It is not meant to be a comprehensive programming tutorial,
by any means. If that's what you're looking for, then you can just keep on
looking.
If you're going to do any scripting with X-Chat at all, you will
need to know perl. It also won't hurt to have had experience writing tcl for
eggdrops or ircII scripts. Otherwise you're going to have to be very careful
to avoid creating conditions which could flood you offline or do other
not-so-optimal things. ;) Thankfully, it shouldn't take most intelligent
people more than a week (month on the outside) enough perl to do some nice
things in it.
Perl is a very flexible language.
You should probably also go read (or at least skim over and then carefully
bookmark this copy of the thing that defines how IRC works: RFC 1459.
Other documents that scripters might find useful would be this
nice list of server
numerics, and this list of changes
for Hybrid 6 which is something everyone on EFNet should read. In fact, I
strongly suggest saving copies of these documents to your local
hard drive, because you will be back to look at them again soon.
One last thing... While you may hear that RFC 1459 isn't being followed very
well, and this is partly true, do your absolute best to stick with RFC-compliant
behaviours anyway because otherwise there's a good chance that your script will
never interoperate properly with others, or at least just piss off a lot of other
people. Pay special attention to section 2.2 of the RFC.
Standard Disclaimer
|
This documentation is provided on an "as-is" basis and comes with no warranty of accuracy or usefulness, either expressed or implied. It is subject to change without any notice, and may contain omissions or errors which could cause your genitalia to shrivel and fall off, or spontaneously combust. If you have any further questions, please feel free to seek professional help.
|
There are [currently] four basic ways to make things call the subroutines you write for X-Chat and they are:
- message handlers - Triggered by messagse sent from the IRC server to your client
- command handlers - triggered by / commands typed in by the user at the keyboard
- timeout handlers - triggered by gtk+
- print handlers - triggered just before xchat calls its built in print handlers for events
These are very important. Every time you set up a handler, it takes precedent over the built-in functions and commands of X-Chat. That is, whatever thing which triggered your subroutine will go to your code before it goes to X-Chat to be dealt with. In this way you can replace almost every built-in function that the client has with your own routines. The thing to remember is that if your code exits by hitting the end of your subroutine, or by a plain 'return' statement, processing of the event will go on to whatever other things have set up hooks for the event, and then (provided nothing else exits with a return value of 1) to X-Chat itself. There is only one problem with this, (which is solved by the brokering handler that I'll explain that later) and that is that you cannot really control what order the custom routines get called. Normally they will execute in order of which ones were installed first, but a single script has no real way of knowing this. Beware.
If you've never heard of @_ before, then you've obviously not coded in perl. When a message handler triggers, the raw line from the IRC server is passed to the subroutine you specify in @_. When a command handler is triggered, only the arguments are passed to the routine through @_ and they are not broken into a list, but left as one long string. You'll have to parse those yourself with split. (I advise using s/\s+/ /g to collapse the blank space to single space first.) When a timer handler is triggered, I *think* absolutely nothing is passed in @_, but it's not like anything terrifically important could be passed along anyway. Be especially careful when setting up message handlers for mode changes, since the modes are not broken up into individual events like they are with eggdrop. The upside of this is that X-Chat has no mode hooks of it's own, so you don't have to worry about it too much. (This is not the case with the brokering handler, however.)
There are some really nice things about coding for X-Chat, and the biggest one is that it's fairly good about determining the proper context for things. If a server sends something that triggers a message handler, then you can be sure that unless you specify otherwise, that your IRC::print or IRC::command function call will go back to that server and that server alone. If you really really need to know what the current context is, use the IRC::get_info function as detailed below.
script initialization commands
|
|
IRC::register(scriptname, version, shutdownroutine, unused);
|
|
This is the first function your script should call, example:
IRC::register ("my script", "1.0", "", "");
The "shutdownroutine" arg is a function that will be called when X-Chat shuts down, so you get a chance to save config files etc. You can omit this arg, it is optional. The "unused" arg is reserved for future use, for now just provide "". This function also returns X-Chat's version number.
Handler initialization commands
|
|
IRC::add_message_handler(message, subroutine_name);
|
|
This function allows you to set up hooks to subroutines so that when a particular message arrives from the IRC server that you are connected to, it can be passed /* X-Chat
* Copyright (C) 1998 Peter Zelezny.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifndef WIN32
#include <unistd.h>
#endif
#include "xchat.h"
#include "cfgfiles.h"
#include "util.h"
#include "modes.h"
#include "outbound.h"
#include "ignore.h"
#include "inbound.h"
#include "dcc.h"
#include "text.h"
#include "ctcp.h"
#include "server.h"
#include "xchatc.h"
static void
ctcp_reply (session *sess, char *nick, char *word[], char *word_eol[],
char *conf)
{
char tbuf[4096]; /* can receive 2048 from IRC, so this is enough */
conf = strdup (conf);
/* process %C %B etc */
check_special_chars (conf, TRUE);
auto_insert (tbuf, sizeof (tbuf), conf, word, word_eol, "", "", word_eol[5],
server_get_network (sess->server, TRUE), "", "", nick);
free (conf);
handle_command (sess, tbuf, FALSE);
}
static int
ctcp_check (session *sess, char *nick, char *word[], char *word_eol[],
char *ctcp)
{
int ret = 0;
char *po;
struct popup *pop;
GSList *list = ctcp_list;
po = strchr (ctcp, '\001');
if (po)
*po = 0;
po = strchr (word_eol[5], '\001');
if (po) |