Xchat::register( $name, $version, [$description,[$callback]] )
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::unhook( $hook )
Xchat::print( $text, [$channel,[$server]] )
Xchat::printf( $format, LIST )
Xchat::command( $command, [$channel,[$server]] )
Xchat::commandf( $format, LIST )
Xchat::find_context( [$channel, [$server]] )
Xchat::get_context()
Xchat::set_context( $context )
Xchat::get_info( $id )
Xchat::get_prefs( $name )
Xchat::emit_print( $event, LIST )
Xchat::nickcmp( $nick1, $nick2 )
Xchat::get_list( $name )
Xchat::user_info( [$nick] )
This is the new Perl interface for X-Chat 2. However, due to changes in xchat's plugin code you will need xchat 2.0.8 or above to load this. Scripts written using the old interface will continue to work. If there are any problems, questions, comments or suggestions please email them to the address on the bottom of this page.
Xchat::EAT_NONE
pass the event alongXchat::EAT_XCHAT
don't let xchat see this eventXchat::EAT_PLUGIN
don't let other plugins see this eventXchat::EAT_ALL
don't let anything see this event
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 script
unloaded. This can be either a string, a reference to a
function or an anonymous sub reference.This should be the first thing each script calls.
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] )
$message
- server message to hook$command
- command to execute without the leading /$event
- one of the events listed in Settings->Lists->Text Events$timeout
- timeout in milliseconds$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 string, a reference to a
function or an anonymous sub reference.Valid keys for \%options:
data | Additional data that is to be associated with the hook. For timer hooks this value can be provided either as Xchat::hook_timer( $timeout, $cb,{data=>$data}) or Xchat::hook_timer( $timeout, $cb, $data ) .However, this means that hook_timer cannot be provided with a hash reference containing data as a key. example: my $options = { data => [@arrayOfStuff] }; Xchat::hook_timer( $timeout, $cb, $options ); In this example, the timer's data will be [@arrayOfStuff] and not { data => [@arrayOfStuff] } This key is valid for all of the hook functions. Default is undef. |
priority | Sets the priority for the hook. It can be set to one of the Xchat::PRI_* constants.This key only applies to server, command and print hooks. Default is Xchat::PRI_NORM .
|
help_text | Text displayed for /help $command. This key only applies to command hooks. Default is "". |
Each of the hooks will be triggered at different times depending on the type of hook.
Hook Type | When the callback will be invoked |
server hooks | a $message message is
received from the server
|
command hooks | the $command command is
executed, either by the user or from a script
|
print hooks | X-Chat is about to print the message for the
$event event
|
timer hooks | called every $timeout milliseconds
(1000 millisecond is 1 second)
|
The value return from these hook functions can be passed to Xchat::unhook
to remove the hook.
All callback functions will receive their arguments in @_
like every
other Perl subroutine.
$_[0]
- array reference containing the IRC message or command and
arguments broken into words$_[0][0]
- command$_[0][1]
- arg1$_[0][2]
- arg2$_[0][3]
- arg3$_[1]
- array reference containing the Nth word to the last word$_[1][0]
- command arg1 arg2 arg3$_[1][1]
- arg1 arg2 arg3$_[1][2]
- arg2 arg3$_[2]
- the data that was passed to the hook function$_[0]
- array reference containing the values for the
text event see Settings->Lists->Text Events$_[1]
- the data that was passed to the hook function$_[0]
- the data that was passed to the hook function
All server, command and print callbacks should return one of
the Xchat::EAT_*
constants.
Timer callbacks can return 0 to remove
the timer or 1 to keep it going
For server hooks, if $message
is ``RAW LINE'' then $cb
will be called for
every IRC message that X-Chat receives.
For command hooks if $command
is ``'' then $cb will be called for
messages entered by the user.
For print hooks besides those events listed in Settings-> Lists->Text Events, these additional events can be used.
Event | Description |
"Open Context" | a new context is created |
"Close Context" | a context has been close |
"Focus Tab" | when a tab is brought to the front |
"Focus Window" | when a top level window is focused or the main tab window is focused by the window manager |
"DCC Chat Text" | when text from a DCC Chat arrives.
$_[0] will have these values$_[0][0] - Address$_[0][1] - Port$_[0][2] - Nick$_[0][3] - Message |
Xchat::unhook( $hook )
This function is used to removed a hooks previously added with one of
the Xchat::hook_*
functions
It returns the data that was passed to the Xchat::hook_*
function when
the hook was added
Xchat::print( $text, [$channel,[$server]] )
$text
- the text to print, this can be an array reference in which
case all the elements will be joined together before printing$channel
- channel or tab with the given name where $text
will be printed$server
- specifies that the text will be printed in a channel or tab
that is associated with $server
Either or both of $channel
and $server
can be undef.
If called as Xchat::print( $text )
, it will always return true.
If called with either the channel or the channel and the server
specified then it will return true if a context is found and
false otherwise. The text will not be printed if the context
is not found. The meaning of setting $channel
or $server
to
undef is the same as
find_context.
Xchat::printf( $format, LIST )
$format
- a format string, see ``perldoc -f sprintf'' for further detail
Xchat::command( $command, [$channel,[$server]] )
$command
- the command to execute without the leading /$channel
- channel or tab with the given name where $text will be printed$server
- specifies that the command will be executed in a channel or tab
that is associated with $serverEither or both of $channel
and $server can be undef.
If called as Xchat::command( $command )
, it will always return true.
If called with either the channel or the channel and the server
specified then it will return true if a context is found and false
otherwise. The command will not be executed if the context is not found.
The meaning of setting $channel
or $server to undef is the same
as find_context.
Xchat::commandf( $format, LIST )
$format
- a format string, see ``perldoc -f sprintf'' for further detail
Xchat::find_context( [$channel, [$server]] )
Either or both of $channel
and $server can be undef. Calling
Xchat::find_context()
is the same as calling
Xchat::find_context( undef, undef)
and
Xchat::find_context( $channel )
is
the same as Xchat::find_context( $channel, undef )
.
If $server
is undef, find any channel named $channel.
If $channel
is undef, find the front most window
or tab named $server
.If both $channel and
$server
are undef, find the currently focused tab or window.
Return the context found for one of the above situations or undef if such a context cannot be found.
Xchat::get_context()
Xchat::set_context( $context )
Xchat::get_info( $id )
ID | Return value |
away | away reason or undef |
channel | current channel name |
host | real hostname of the current server |
network | current network name or undef |
nick | current nick |
server | current server name (what the server claims to be) undef if not connected |
topic | current channel topic |
version | xchat version number |
xchatdir | xchat config directory examples: /home/user/.xchat2 C:\Documents and Settings\user\Application Data\X-Chat 2 |
This function is used to retrieve certain information about the current context.
Xchat::get_prefs( $name )
This function provides a way to retrieve X-Chat's setting information.
Returns undef
if there is no setting called called $name
.
Xchat::emit_print( $event, LIST )
$event
- name from the Event column in Settings->Lists->Text EventsThis functions is used to generate one of the events listed under Settings-> Lists->Text Events
Returns 1 on success, 0 on failure
Xchat::nickcmp( $nick1, $nick2 )
The comparsion is based on the current server. Either a RFC1459 compliant string compare or plain ascii will be using depending on the server. The comparison is case insensitive.
Returns a number less than, equal to or greater than zero if
$nick1
is
found respectively, to be less than, to match, or be greater than
$nick2
.
Xchat::get_list( $name )
This function will return a list of hash references. The hash references will have different keys depend on the list. An empty list is returned if there is not such list.
"channels" - list of channels, querys and their serverKey | Description |
channel | channel or query |
context | can be used with set_context |
flags | Server Bits: 0 - Connected 1 - Connecting 2 - Away 3 - EndOfMotd(Login complete) 4 - Has WHOX |
id | Unique server ID |
network | network name to which this channel belongs |
server | server name to which this channel belongs |
type | the type of this context 1 - server 2 - channel 3 - dialog |
Key | Value |
address32 | address of the remote user(ipv4 address) |
cps | bytes per second(speed) |
destfile | destination full pathname |
file | file name |
nick | nick of the person this DCC connection is connected to |
port | TCP port number |
pos | bytes sent/received |
resume | point at which this file was resumed (zero if it was not resumed) |
size | file size in bytes |
status | DCC Status: 0 - queued 1 - active 2 - failed 3 - done 4 - connecting 5 - aborted |
type | DCC Type: 0 - send 1 - receive 2 - chatrecv 3 - chatsend |
Key | Value |
mask | ignore mask. e.g: *!*@*.aol.com |
flags | Bit field of flags. 0 - private 1 - notice 2 - channel 3 - ctcp 4 - invite 5 - unignore 6 - nosave 7 - dcc |
Key | Value |
nick | nickname |
flags | 0 = is online |
on | time when user came online |
off | time when user went offline |
seen | time when user was last verified still online |
the values indexed by on, off and seen can be passed to localtime and gmtime, see perldoc -f localtime and perldoc -f gmtime for more detail
Key | Value |
away | away status(boolean) |
nick | nick name |
host | host name in the form: user@host or undef if not known |
prefix | prefix character, .e.g: @ or + |
Xchat::user_info( [$nick] )
This function is mainly intended to be used as a shortcut for when you need
to retrieve some information about only one user in a channel. Otherwise it
is probably a better idea to use get_list.
If $nick
is found a hash reference containing the same keys as those in the
``users'' list of get_list.
Contact Lian Situ at <atmcmnky@yahoo.com> for questions, comments and corrections about this page or the Perl plugin itself.