|
|
# HexChat Perl Interface
## Introduction
This is the Perl interface for HexChat. If there are any problems, questions, comments or
suggestions please email them to the address on the bottom of this page.
## Constants
###Priorities
* **`Xchat::PRI_HIGHEST`**
* **`Xchat::PRI_HIGH`**
* **`Xchat::PRI_NORM`**
* **`Xchat::PRI_LOW`**
* **`Xchat::PRI_LOWEST`**
### Return values
* **`Xchat::EAT_NONE`** - pass the event along
* **`Xchat::EAT_XCHAT`** - don't let HexChat see this event
* **`Xchat::EAT_PLUGIN`** - don't let other scripts and plugins see this event but xchat will still see it
* **`Xchat::EAT_ALL`** - don't let anything else see this event
#### Timer and fd hooks
* **`Xchat::KEEP`** - keep the timer going or hook watching the handle
* **`Xchat::REMOVE`** - remove the timer or hook watching the handle
### hook\_fd flags
* **`Xchat::FD_READ`** - invoke the callback when the handle is ready for reading
* **`Xchat::FD_WRITE`** - invoke the callback when the handle is ready for writing
* **`Xchat::FD_EXCEPTION`** - invoke the callback if an exception occurs
* **`Xchat::FD_NOTSOCKET`** - indicate that the handle being hooked is not a socket
## Functions
### `Xchat::register( $name, $version, [$description,[$callback]] )`
* `$name` - The name of this script
* `$version` - This script's version
* `$description` - A description for this script
* `$callback` - This is a function that will be called when the is script
unloaded. This can be either a reference to a
function or an anonymous sub reference.
This is the first thing to call in every script.
### `Xchat::hook_server( $message, $callback, [\%options] )`
### `Xchat::hook_command( $command, $callback, [\%options] )`
### `Xchat::hook_print( $event,$callback, [\%options] )`
### `Xchat::hook_timer( $timeout,$callback, [\%options | $data] )`
### `Xchat::hook_fd( $handle, $callback, [ \%options ] )`
These functions can be to intercept various events.
hook\_server can be used to intercept any incoming message from the IRC server.
hook\_command can be used to intercept any command, if the command doesn't currently exist then a new one is created.
hook\_print can be used to intercept any of the events listed in _Setttings_ `->` _Text Events_.
hook\_timer can be used to create a new timer
* **`$message`** - server message to hook such as PRIVMSG
* **`$command`** - command to intercept, without the leading /
* **`$event`** - one of the events listed in _Settings_ `->` _Text Events_
* **`$timeout`** - timeout in milliseconds
* **`$handle`** - the I/O handle you want to monitor with hook\_fd. This must be something that has a fileno. See perldoc -f fileno or [fileno](http://perldoc.perl.org/functions/fileno.html)
* **`$callback`** - callback function, this is called whenever
the hooked event is trigged, the following are
the conditions that will trigger the different hooks.
This can be either a reference to a
function or an anonymous sub reference.
* **`\%options`** - a hash reference containing addional options for the hooks
Valid keys for \%options:
<table border="1"> <tr>
<td>data</td> <td>Additional data that is to be associated with the<br />
hook. For timer hooks this value can be provided either as<br />
<code>Xchat::hook_timer( $timeout, $cb,{data=>$data})</code><br />
or <code>Xchat::hook_timer( $timeout, $cb, $data )</code>.<br />
However, this means that hook_timer cannot be provided<br />
with a hash reference containing data as a key.<br /> example:<br />
my $options = { data => [@arrayOfStuff] };<br />
Xchat::hook_timer( $timeout, $cb, $options );<br />
<br />
In this example, the timer's data will be<br />
[@arrayOfStuff] and not { data => [@arrayOfStuff] }<br />
<br />
This key is valid for all of the hook functions.<br />
<br />
Default is undef.<br />
</td>
</tr> <tr>
<td>priority</td> <td>Sets the priority for the hook.<br />
It can be set to one of the
<code>Xchat::PRI_*</code> constants.<br />
<br />
This key only applies to server, command
and print hooks.<br />
<br />
Default is <code>Xchat::PRI_NORM</code>.
</td> </tr> <tr>
<td>help_text</td> <td>Text displayed for /help $command.<br />
<br />
This key only applies to command hooks.<br />
<br />
Default is "".
</td>
</tr> <tr>
<td>flags</td> <td>Specify the flags for a fd hook.<br />
<br />
See <a href="#hook_fd_flags">hook fd flags</a> section for valid values.<br />
<br />
On Windows if the handle is a pipe you specify<br />
Xchat::FD_NOTSOCKET in addition to any other flags you might be using.<br />
<br />
This key only applies to fd hooks.<br />
Default is Xchat::FD_READ
|