2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <title>X-Chat
2 Perl Interface
</title>
6 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
7 <link rev=
"made" href=
"mailto:khisanth@miyu.hopto.org" />
8 <style type=
"text/css">
21 font-family: monospace;
24 .example .line_number {
29 border-right:
1px solid white;
36 .example .content pre {
42 border-collapse: collapse;
46 border:
1px solid black;
50 color: rgb(
135,
206,
235);
53 color: rgb(
205,
92,
92);
61 color: rgb(
255,
222,
173);
64 color: rgb(
102,
102,
102);
67 color: rgb(
255,
255,
255);
68 background-color: rgb(
51,
51,
51);
71 color: rgb(
189,
183,
107);
74 color: rgb(
152,
251,
152);
78 background-color: rgb(
238,
238,
0);
81 color: rgb(
240,
230,
140);
87 <body style=
"background-color: white">
88 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
89 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
90 <big><strong><span class=
"block"> X-Chat
2 Perl Interface
</span></strong></big>
97 <p><a name=
"__index__"></a></p>
100 <li><a href=
"#x_chat_2_perl_interface">X-Chat
2 Perl Interface
</a></li>
103 <li><a href=
"#introduction">Introduction
</a></li>
104 <li><a href=
"#constants">Constants
</a></li>
107 <li><a href=
"#priorities">Priorities
</a></li>
108 <li><a href=
"#return_values">Return values
</a></li>
111 <li><a href=
"#timer_and_fd_hooks">Timer and fd hooks
</a></li>
115 <li><a href=
"#hook_fd_flags">hook_fd flags
</a></li>
119 <li><a href=
"#functions">Functions
</a></li>
122 <li><a href=
"#xchat_register"><code>Xchat::register( $name, $version, [$description,[$callback]] )
</code></a></li>
123 <li><a href=
"#xchat_hook_server"><code>Xchat::hook_server( $message, $callback, [\%options] )
</code></a></li>
124 <li><a href=
"#xchat_hook_command"><code>Xchat::hook_command( $command, $callback, [\%options] )
</code></a></li>
125 <li><a href=
"#xchat_hook_print"><code>Xchat::hook_print( $event,$callback, [\%options] )
</code></a></li>
126 <li><a href=
"#xchat_hook_timer"><code>Xchat::hook_timer( $timeout,$callback, [\%options | $data] )
</code></a></li>
127 <li><a href=
"#xchat_hook_fd"><code>Xchat::hook_fd( $handle, $callback, [ \%options ] )
</code></a></li>
130 <li><a href=
"#when_callbacks_are_invoked">When callbacks are invoked
</a></li>
131 <li><a href=
"#callback_arguments">Callback Arguments
</a></li>
132 <li><a href=
"#callback_return_values">Callback return values
</a></li>
133 <li><a href=
"#miscellaneous_hook_related_information">Miscellaneous Hook Related Information
</a></li>
137 <li><a href=
"#xchat_unhook"><code>Xchat::unhook( $hook )
</code></a></li>
138 <li><a href=
"#xchat_print"><code>Xchat::print( $text | \@lines, [$channel,[$server]] )
</code></a></li>
139 <li><a href=
"#xchat_printf"><code>Xchat::printf( $format, LIST )
</code></a></li>
140 <li><a href=
"#xchat_command"><code>Xchat::command( $command | \@commands, [$channel,[$server]] )
</code></a></li>
141 <li><a href=
"#xchat_commandf"><code>Xchat::commandf( $format, LIST )
</code></a></li>
142 <li><a href=
"#xchat_find_context"><code>Xchat::find_context( [$channel, [$server]] )
</code></a></li>
143 <li><a href=
"#xchat_get_context"><code>Xchat::get_context()
</code></a></li>
144 <li><a href=
"#xchat_set_context"><code>Xchat::set_context( $context | $channel,[$server] )
</code></a></li>
145 <li><a href=
"#xchat_get_info"><code>Xchat::get_info( $id )
</code></a></li>
146 <li><a href=
"#xchat_get_prefs"><code>Xchat::get_prefs( $name )
</code></a></li>
147 <li><a href=
"#xchat_emit_print"><code>Xchat::emit_print( $event, LIST )
</code></a></li>
148 <li><a href=
"#xchat_send_modes"><code>Xchat::send_modes( $target | \@targets, $sign, $mode, [ $modes_per_line ] )
</code></a></li>
149 <li><a href=
"#xchat_nickcmp"><code>Xchat::nickcmp( $nick1, $nick2 )
</code></a></li>
150 <li><a href=
"#xchat_get_list"><code>Xchat::get_list( $name )
</code></a></li>
151 <li><a href=
"#xchat_user_info"><code>Xchat::user_info( [$nick] )
</code></a></li>
152 <li><a href=
"#xchat_context_info"><code>Xchat::context_info( [$context] )
</code></a></li>
153 <li><a href=
"#xchat_strip_code"><code>Xchat::strip_code( $string )
</code></a></li>
157 <li><a href=
"#examples">Examples
</a></li>
160 <li><a href=
"#asynchronous_dns_resolution_with_hook_fd">Asynchronous DNS resolution with hook_fd
</a></li>
164 <li><a href=
"#contact_information">Contact Information
</a></li>
175 <h1><a name=
"x_chat_2_perl_interface" />X-Chat
2 Perl Interface
</h1>
178 <h2><a name=
"introduction" />Introduction
</h2>
179 <p>This is the new Perl interface for X-Chat
2. However, due to changes in
180 xchat's plugin code you will need xchat
2.0.8 or above to load this. Scripts
181 written using the old interface will continue to work. If there are any
182 problems, questions, comments or suggestions please email them to the address
183 on the bottom of this page.
</p>
186 <h2><a name=
"constants" />Constants
</h2>
189 <h3><a name=
"priorities" />Priorities
</h3>
191 <li><strong><code>Xchat::PRI_HIGHEST
</code></strong>
193 <li><strong><code>Xchat::PRI_HIGH
</code></strong>
195 <li><strong><code>Xchat::PRI_NORM
</code></strong>
197 <li><strong><code>Xchat::PRI_LOW
</code></strong>
199 <li><strong><code>Xchat::PRI_LOWEST
</code></strong>
204 <h3><a name=
"return_values" />Return values
</h3>
206 <li><strong><code>Xchat::EAT_NONE
</code> - pass the event along
</strong>
208 <li><strong><code>Xchat::EAT_XCHAT
</code> - don't let xchat see this event
</strong>
210 <li><strong><code>Xchat::EAT_PLUGIN
</code> - don't let other scripts and plugins see this event but xchat will still see it
</strong>
212 <li><strong><code>Xchat::EAT_ALL
</code> - don't let anything else see this event
</strong>
217 <h4><a name=
"timer_and_fd_hooks" />Timer and fd hooks
</h4>
219 <li><strong><code>Xchat::KEEP
</code> - keep the timer going or hook watching the handle
</strong>
221 <li><strong><code>Xchat::REMOVE
</code> - remove the timer or hook watching the handle
</strong>
226 <h3><a name=
"hook_fd_flags" />hook_fd flags
</h3>
228 <li><strong><code>Xchat::FD_READ
</code> - invoke the callback when the handle is ready for reading
</strong>
230 <li><strong><code>Xchat::FD_WRITE
</code> - invoke the callback when the handle is ready for writing
</strong>
232 <li><strong><code>Xchat::FD_EXCEPTION
</code> - invoke the callback if an exception occurs
</strong>
234 <li><strong><code>Xchat::FD_NOTSOCKET
</code> - indicate that the handle being hooked is not a socket
</strong>
239 <h2><a name=
"functions" />Functions
</h2>
242 <h3><a name=
"xchat_register" /><code>Xchat::register( $name, $version, [$description,[$callback]] )
</code></h3>
244 <li><strong><code>$name
</code> - The name of this script
</strong>
246 <li><strong><code>$version
</code> - This script's version
</strong>
248 <li><strong><code>$description
</code> - A description for this script
</strong>
250 <li><strong><code>$callback
</code> - This is a function that will be called when the is script
251 unloaded. This can be either a reference to a
252 function or an anonymous sub reference.
</strong>
255 <p>This is the first thing to call in every script.
</p>
258 <h3><a name=
"xchat_hook_server" /><code>Xchat::hook_server( $message, $callback, [\%options] )
</code></h3>
261 <h3><a name=
"xchat_hook_command" /><code>Xchat::hook_command( $command, $callback, [\%options] )
</code></h3>
264 <h3><a name=
"xchat_hook_print" /><code>Xchat::hook_print( $event,$callback, [\%options] )
</code></h3>
267 <h3><a name=
"xchat_hook_timer" /><code>Xchat::hook_timer( $timeout,$callback, [\%options | $data] )
</code></h3>
270 <h3><a name=
"xchat_hook_fd" /><code>Xchat::hook_fd( $handle, $callback, [ \%options ] )
</code></h3>
271 <p>These functions can be to intercept various events.
272 hook_server can be used to intercept any incoming message from the IRC server.
273 hook_command can be used to intercept any command, if the command doesn't currently exist then a new one is created.
274 hook_print can be used to intercept any of the events listed in Setttings-
>Advanced-
>Text Events
275 hook_timer can be used to create a new timer
</p>
277 <li><strong><code>$message
</code> - server message to hook such as PRIVMSG
</strong>
279 <li><strong><code>$command
</code> - command to intercept, without the leading /
</strong>
281 <li><strong><code>$event
</code> - one of the events listed in Settings-
>Advanced-
>Text Events
</strong>
283 <li><strong><code>$timeout
</code> - timeout in milliseconds
</strong>
285 <li><strong><code>$handle
</code> - the I/O handle you want to monitor with hook_fd. This must be something that has a fileno. See perldoc -f fileno or
<a href=
"http://perldoc.perl.org/functions/fileno.html">fileno
</a></strong>
287 <li><strong><code>$callback
</code> - callback function, this is called whenever
288 the hooked event is trigged, the following are
289 the conditions that will trigger the different hooks.
290 This can be either a reference to a
291 function or an anonymous sub reference.
</strong>
293 <li><strong>\%options - a hash reference containing addional options for the hooks
</strong>
296 <p>Valid keys for \%options:
</p>
297 <table border=
"1"> <tr>
298 <td>data
</td> <td>Additional data that is to be associated with the
<br />
299 hook. For timer hooks this value can be provided either as
<br />
300 <code>Xchat::hook_timer( $timeout, $cb,{data=
>$data})
</code><br />
301 or
<code>Xchat::hook_timer( $timeout, $cb, $data )
</code>.
<br />
302 However, this means that hook_timer cannot be provided
<br />
303 with a hash reference containing data as a key.
<br /> example:
<br />
304 my $options = { data =
> [@arrayOfStuff] };
<br />
305 Xchat::hook_timer( $timeout, $cb, $options );
<br />
307 In this example, the timer's data will be
<br />
308 [@arrayOfStuff] and not { data =
> [@arrayOfStuff] }
<br />
310 This key is valid for all of the hook functions.
<br />
312 Default is undef.
<br />
315 <td>priority
</td> <td>Sets the priority for the hook.
<br />
316 It can be set to one of the
317 <code>Xchat::PRI_*
</code> constants.
<br />
319 This key only applies to server, command
320 and print hooks.
<br />
322 Default is
<code>Xchat::PRI_NORM
</code>.
324 <td>help_text
</td> <td>Text displayed for /help $command.
<br />
326 This key only applies to command hooks.
<br />
331 <td>flags
</td> <td>Specify the flags for a fd hook.
<br />
333 See
<a href=
"#hook_fd_flags">hook fd flags
</a> section for valid values.
<br />
335 On Windows if the handle is a pipe you specify
<br />
336 Xchat::FD_NOTSOCKET in addition to any other flags you might be using.
<br />
338 This key only applies to fd hooks.
<br />
339 Default is Xchat::FD_READ
343 <h4><a name=
"when_callbacks_are_invoked" />When callbacks are invoked
</h4>
344 <p>Each of the hooks will be triggered at different times depending on the type
346 <table border=
"1"> <tr style=
"background-color: #dddddd">
347 <td>Hook Type
</td> <td>When the callback will be invoked
</td>
349 <td>server hooks
</td> <td>a
<code>$message
</code> message is
350 received from the server
353 <td>command hooks
</td> <td>the
<code>$command
</code> command is
354 executed, either by the user or from a script
357 <td>print hooks
</td> <td>X-Chat is about to print the message for the
358 <code>$event
</code> event
361 <td>timer hooks
</td> <td>called every
<code>$timeout
</code> milliseconds
362 (
1000 millisecond is
1 second)
<br />
363 the callback will be executed in the same context where
364 the hook_timer was called, if the context no longer exists
365 then it will execute in a random context
368 <td>fd hooks
</td> <td>depends on the flags that were passed to hook_fd
<br />
369 See
<a href=
"#hook_fd_flags">hook_fd flags
</a> section.
372 </table><p>The value return from these hook functions can be passed to
<code>Xchat::unhook
</code>
373 to remove the hook.
</p>
376 <h4><a name=
"callback_arguments" />Callback Arguments
</h4>
377 <p>All callback functions will receive their arguments in
<code>@_
</code> like every
378 other Perl subroutine.
</p>
380 Server and command callbacks
<br />
382 <code>$_[
0]
</code> - array reference containing the IRC message or command and
383 arguments broken into words
<br />
385 /command arg1 arg2 arg3
<br />
386 <code>$_[
0][
0]
</code> - command
<br />
387 <code>$_[
0][
1]
</code> - arg1
<br />
388 <code>$_[
0][
2]
</code> - arg2
<br />
389 <code>$_[
0][
3]
</code> - arg3
<br />
391 <code>$_[
1]
</code> - array reference containing the Nth word to the last word
<br />
393 /command arg1 arg2 arg3
<br />
394 <code>$_[
1][
0]
</code> - command arg1 arg2 arg3
<br />
395 <code>$_[
1][
1]
</code> - arg1 arg2 arg3
<br />
396 <code>$_[
1][
2]
</code> - arg2 arg3
<br />
397 <code>$_[
1][
3]
</code> - arg3
<br />
399 <code>$_[
2]
</code> - the data that was passed to the hook function
<br />
401 Print callbacks
<br />
403 <code>$_[
0]
</code> - array reference containing the values for the
404 text event see Settings-
>Advanced-
>Text Events
<br />
405 <code>$_[
1]
</code> - the data that was passed to the hook function
<br />
407 Timer callbacks
<br />
409 <code>$_[
0]
</code> - the data that was passed to the hook function
<br />
410 <br />fd callbacks
<br />
412 <code>$_[
0]
</code> - the handle that was passed to hook_fd
<br />
413 <code>$_[
1]
</code> - flags indicating why the callback was called
<br />
414 <code>$_[
2]
</code> - the data that was passed to the hook function
<br />
417 <h4><a name=
"callback_return_values" />Callback return values
</h4>
418 <p>All server, command and print callbacks should return one of
419 the
<code>Xchat::EAT_*
</code> constants.
420 Timer callbacks can return Xchat::REMOVE to remove
421 the timer or Xchat::KEEP to keep it going
</p>
424 <h4><a name=
"miscellaneous_hook_related_information" />Miscellaneous Hook Related Information
</h4>
425 <p>For server hooks, if
<code>$message
</code> is
"RAW LINE
" then
<code>$cb
</code> will be called for
426 every IRC message than X-Chat receives.
</p>
427 <p>For command hooks if
<code>$command
</code> is
"" then
<code>$cb
</code> will be called for
428 messages entered by the user that is not a command.
</p>
429 <p>For print hooks besides those events listed in
430 Settings-
>Advanced-
>Text Events, these additional events can be used.
</p>
431 <table border=
"1"> <tr style=
"background-color: #dddddd">
432 <td>Event
</td> <td>Description
</td>
434 <td>"Open Context"</td> <td>a new context is created
</td>
436 <td>"Close Context"</td> <td>a context has been close
</td>
438 <td>"Focus Tab"</td> <td>when a tab is brought to the front
</td>
440 <td>"Focus Window"</td> <td>when a top level window is focused or the
441 main tab window is focused by the window manager
444 <td>"DCC Chat Text"</td> <td>when text from a DCC Chat arrives.
445 <code>$_[
0]
</code> will have these values
<br />
447 <code>$_[
0][
0]
</code> - Address
<br />
448 <code>$_[
0][
1]
</code> - Port
<br />
449 <code>$_[
0][
2]
</code> - Nick
<br />
450 <code>$_[
0][
3]
</code> - Message
<br />
453 <td>"Key Press"</td> <td>used for intercepting key presses
<br />
454 $_[
0][
0] - key value
<br />
455 $_[
0][
1] - state bitfield,
1 - shift,
4 - control,
8 - alt
<br />
456 $_[
0][
2] - string version of the key which might be empty for unprintable keys
<br />
457 $_[
0][
3] - length of the string in $_[
0][
2]
<br />
462 <h3><a name=
"xchat_unhook" /><code>Xchat::unhook( $hook )
</code></h3>
464 <li><strong><code>$hook
</code> - the hook that was previously returned by one of the
<code>Xchat::hook_*
</code> functions
</strong>
467 <p>This function is used to removed a hook previously added with one of
468 the
<code>Xchat::hook_*
</code> functions
</p>
469 <p>It returns the data that was passed to the
<code>Xchat::hook_*
</code> function when
470 the hook was added
</p>
473 <h3><a name=
"xchat_print" /><code>Xchat::print( $text | \@lines, [$channel,[$server]] )
</code></h3>
475 <li><strong><code>$text
</code> - the text to print
</strong>
477 <li><strong><code>\@lines
</code> - array reference containing lines of text to be printed
478 all the elements will be joined together before printing
</strong>
480 <li><strong><code>$channel
</code> - channel or tab with the given name where
<code>$text
</code>
481 will be printed
</strong>
483 <li><strong><code>$server
</code> - specifies that the text will be printed in a channel or tab
484 that is associated with
<code>$server
</code></strong>
487 <p>The first argument can either be a string or an array reference of strings.
488 Either or both of
<code>$channel
</code> and
<code>$server
</code> can be undef.
</p>
489 <p>If called as
<code>Xchat::print( $text )
</code>, it will always return true.
490 If called with either the channel or the channel and the server
491 specified then it will return true if a context is found and
492 false otherwise. The text will not be printed if the context
493 is not found. The meaning of setting
<code>$channel
</code> or
<code>$server
</code> to
495 <a href=
"#xchat_find_context">find_context
</a>.
</p>
498 <h3><a name=
"xchat_printf" /><code>Xchat::printf( $format, LIST )
</code></h3>
500 <li><strong><code>$format
</code> - a format string, see
"perldoc -f
<a href=
"http://perldoc.perl.org/functions/sprintf.html">sprintf
</a>" for further detail
</strong>
502 <li><strong>LIST - list of values for the format fields
</strong>
507 <h3><a name=
"xchat_command" /><code>Xchat::command( $command | \@commands, [$channel,[$server]] )
</code></h3>
509 <li><strong><code>$command
</code> - the command to execute, without the leading /
</strong>
511 <li><strong><code>\@commands
</code> - array reference containing a list of commands to execute
</strong>
513 <li><strong><code>$channel
</code> - channel or tab with the given name where
<code>$command
</code> will be executed
</strong>
515 <li><strong><code>$server
</code> - specifies that the command will be executed in a channel or tab that is associated with
<code>$server
</code></strong>
518 <p>The first argument can either be a string or an array reference of strings.
519 Either or both of
<code>$channel
</code> and
<code>$server
</code> can be undef.
</p>
520 <p>If called as
<code>Xchat::command( $command )
</code>, it will always return true.
521 If called with either the channel or the channel and the server
522 specified then it will return true if a context is found and false
523 otherwise. The command will not be executed if the context is not found.
524 The meaning of setting
<code>$channel
</code> or
<code>$server
</code> to undef is the same
528 <h3><a name=
"xchat_commandf" /><code>Xchat::commandf( $format, LIST )
</code></h3>
530 <li><strong><code>$format
</code> - a format string, see
"perldoc -f
<a href=
"http://perldoc.perl.org/functions/sprintf.html">sprintf
</a>" for further detail
</strong>
532 <li><strong>LIST - list of values for the format fields
</strong>
537 <h3><a name=
"xchat_find_context" /><code>Xchat::find_context( [$channel, [$server]] )
</code></h3>
539 <li><strong><code>$channel
</code> - name of a channel
</strong>
541 <li><strong><code>$server
</code> - name of a server
</strong>
544 <p>Either or both of
<code>$channel
</code> and $server can be undef. Calling
545 <code>Xchat::find_context()
</code> is the same as calling
546 <code>Xchat::find_context( undef, undef)
</code> and
547 <code>Xchat::find_context( $channel )
</code> is
548 the same as
<code>Xchat::find_context( $channel, undef )
</code>.
</p>
549 <p>If
<code>$server
</code> is undef, find any channel named $channel.
550 If
<code>$channel
</code> is undef, find the front most window
551 or tab named
<code>$server
</code>.If both $channel and
552 <code>$server
</code> are undef, find the currently focused tab or window.
</p>
553 <p>Return the context found for one of the above situations or undef if such
554 a context cannot be found.
</p>
557 <h3><a name=
"xchat_get_context" /><code>Xchat::get_context()
</code></h3>
558 <p>Returns the current context.
</p>
561 <h3><a name=
"xchat_set_context" /><code>Xchat::set_context( $context | $channel,[$server] )
</code></h3>
563 <li><strong><code>$context
</code> - context value as returned from
<a href=
"#xchat_get_context">get_context
</a>,
<a href=
"#xchat_find_context">find_context
</a> or one
564 of the fields in the list of hashrefs returned by list_get
</strong>
566 <li><strong><code>$channel
</code> - name of a channel you want to switch context to
</strong>
568 <li><strong><code>$server
</code> - name of a server you want to switch context to
</strong>
571 <p>See
<a href=
"#xchat_find_context">find_context
</a> for more details on
<code>$channel
</code> and
<code>$server
</code>.
</p>
572 <p>Returns true on success, false on failure
</p>
575 <h3><a name=
"xchat_get_info" /><code>Xchat::get_info( $id )
</code></h3>
577 <li><strong><code>$id
</code> - one of the following case sensitive values
</strong>
580 <table border=
"1"> <tr style=
"background-color: #dddddd">
582 <td>Return value
</td>
583 <td>Associated Command(s)
</td>
586 <td>away reason or undef if you are not away
</td>
590 <td>current channel name
</td>
594 <td>character-set used in the current context
</td>
597 <td>event_text
<Event Name
></td> <td>text event format string for
<Event name
><br />
599 <div class=
"example synNormal"><div class='line_number'
>
602 <div class='content'
><pre><span class=
"synStatement">my
</span> <span class=
"synIdentifier">$channel_msg_format
</span> = Xchat::get_info(
<span class=
"synStatement">"</span><span class=
"synConstant">event_text Channel Message
</span><span class=
"synStatement">"</span> );
610 <td>real hostname of the current server
</td>
614 <td>connection id
</td>
618 <td>contents of the inputbox
</td>
622 <td>the system wide directory where xchat will look for plugins.
623 this string is in the same encoding as the local file system
</td>
627 <td>the current channels modes or undef if not known
</td>
631 <td>current network name or undef, this value is taken from the Network List
</td>
635 <td>current nick
</td>
639 <td>nickserv password for this network or undef, this value is taken from the Network List
</td>
642 <td>server
</td> <td>current server name
<br />
643 (what the server claims to be) undef if not connected
647 <td>state_cursor
</td>
648 <td>current inputbox cursor position in characters
</td>
652 <td>current channel topic
</td>
656 <td>xchat version number
</td>
660 <td>status of the xchat window, possible values are
"active",
"hidden"
664 <td>win_ptr
</td> <td>native window pointer, GtkWindow * on Unix, HWND on Win32.
<br />
665 On Unix if you have the Glib module installed you can use my $window = Glib::Object-
>new_from_pointer( Xchat::get_info(
"win_ptr" ) ); to get a Gtk2::Window object.
<br />
666 Additionally when you have detached tabs, each of the windows will return a different win_ptr for the different Gtk2::Window objects.
<br />
667 See
<a href=
"http://xchat.cvs.sourceforge.net/viewvc/xchat/xchat2/plugins/perl/char_count.pl?view=markup">char_count.pl
</a> for a longer example of a script that uses this to show how many characters you currently have in your input box.
673 <td>similar to win_ptr except it will always be a GtkWindow *
</td>
677 <td>xchatdir
</td> <td>xchat config directory encoded in UTF-
8<br />
679 /home/user/.xchat2
<br />
680 C:\Documents and Settings\user\Application Data\X-Chat
2
684 <td>xchatdirfs
</td> <td>same as xchatdir except encoded in the locale file system encoding
</td>
687 </table><p>This function is used to retrieve certain information about the current
688 context. If there is an associated command then that command can be used to change the value for a particular ID.
</p><p>
690 <h3><a name=
"xchat_get_prefs" /><code>Xchat::get_prefs( $name )
</code></h3>
692 <li><strong><code>$name
</code> - name of a X-Chat setting (available through the /set command)
</strong>
695 <p>This function provides a way to retrieve X-Chat's setting information.
</p>
696 <p>Returns
<code>undef
</code> if there is no setting called called
<code>$name
</code>.
</p>
699 <h3><a name=
"xchat_emit_print" /><code>Xchat::emit_print( $event, LIST )
</code></h3>
701 <li><strong><code>$event
</code> - name from the Event column in Settings-
>Advanced-
>Text Events
</strong>
703 <li><strong>LIST - this depends on the Description column on the bottom of Settings-
>Advanced-
>Text Events
</strong>
706 <p>This functions is used to generate one of the events listed under
707 Settings-
>Advanced-
>Text Events
</p>
708 <p>Note: when using this function you MUST return Xchat::EAT_ALL otherwise you will end up with duplicate events.
709 One is the original and the second is the one you emit.
</p>
710 <p>Returns true on success, false on failure
</p>
713 <h3><a name=
"xchat_send_modes" /><code>Xchat::send_modes( $target | \@targets, $sign, $mode, [ $modes_per_line ] )
</code></h3>
715 <li><strong><code>$target
</code> - a single nick to set the mode on
</strong>
717 <li><strong><code>\@targets
</code> - an array reference of the nicks to set the mode on
</strong>
719 <li><strong><code>$sign
</code> - the mode sign, either '+' or '-'
</strong>
721 <li><strong><code>$mode
</code> - the mode character such as 'o' and 'v', this can only be one character long
</strong>
723 <li><strong><code>$modes_per_line
</code> - an optional argument maximum number of modes to send per at once, pass
0 use the current server's maximum (default)
</strong>
726 <p>Send multiple mode changes for the current channel. It may send multiple MODE lines if the request doesn't fit on one.
</p>
728 <div class=
"example synNormal"><div class='line_number'
>
744 <div class='content'
><pre><span class=
"synStatement">use strict
</span>;
745 <span class=
"synStatement">use
</span>warning;
746 <span class=
"synStatement">use
</span>Xchat
<span class=
"synStatement">qw(
</span><span class=
"synConstant">:all
</span><span class=
"synStatement">)
</span>;
748 hook_command(
<span class=
"synStatement">"</span><span class=
"synConstant">MODES
</span><span class=
"synStatement">"</span>,
<span class=
"synStatement">sub
</span>{
749 <span class=
"synStatement">my
</span> (
<span class=
"synStatement">undef
</span>,
<span class=
"synIdentifier">$who
</span>,
<span class=
"synIdentifier">$sign
</span>,
<span class=
"synIdentifier">$mode
</span>) =
<span class=
"synIdentifier">@{$_[
</span><span class=
"synConstant">0</span><span class=
"synIdentifier">]}
</span>;
750 <span class=
"synStatement">my
</span> <span class=
"synIdentifier">@targets
</span> =
<span class=
"synStatement">split
</span> <span class=
"synStatement">/
</span><span class=
"synConstant">,
</span><span class=
"synStatement">/
</span>,
<span class=
"synIdentifier">$who
</span>;
751 <span class=
"synStatement">if
</span>(
<span class=
"synIdentifier">@targets
</span> > <span class=
"synConstant">1</span> ) {
752 send_modes( \
<span class=
"synIdentifier">@targets
</span>,
<span class=
"synIdentifier">$sign
</span>,
<span class=
"synIdentifier">$mode
</span>,
<span class=
"synConstant">1</span> );
753 }
<span class=
"synStatement">else
</span> {
754 send_modes(
<span class=
"synIdentifier">$who
</span>,
<span class=
"synIdentifier">$sign
</span>,
<span class=
"synIdentifier">$mode
</span> );
756 <span class=
"synStatement">return
</span> EAT_XCHAT;
761 <h3><a name=
"xchat_nickcmp" /><code>Xchat::nickcmp( $nick1, $nick2 )
</code></h3>
763 <li><strong><code>$nick1, $nick2
</code> - the two nicks or channel names that are to be compared
</strong>
766 <p>The comparsion is based on the current server. Either a
<a href=
"http://www.ietf.org/rfc/rfc1459.txt" class=
"rfc">RFC1459
</a> compliant
767 string compare or plain ascii will be using depending on the server. The
768 comparison is case insensitive.
</p>
769 <p>Returns a number less than, equal to or greater than zero if
770 <code>$nick1
</code> is
771 found respectively, to be less than, to match, or be greater than
772 <code>$nick2
</code>.
</p>
775 <h3><a name=
"xchat_get_list" /><code>Xchat::get_list( $name )
</code></h3>
777 <li><strong><code>$name
</code> - name of the list, one of the following:
778 "channels
",
"dcc
",
"ignore
",
"notify
",
"users
"</strong>
781 <p>This function will return a list of hash references. The hash references
782 will have different keys depend on the list. An empty list is returned
783 if there is no such list.
</p>
784 <p>"channels" - list of channels, querys and their server
</p><table border=
"1"> <tr style=
"background-color: #dddddd">
785 <td>Key
</td> <td>Description
</td>
787 <td>channel
</td> <td>tab name
</td>
790 <td>channel types supported by the server, typically
"#&"</td>
792 <td>context
</td> <td>can be used with set_context
</td>
794 <td>flags
</td> <td>Server Bits:
<br />
798 3 - EndOfMotd(Login complete)
<br />
800 5 - Has IDMSG (FreeNode)
<br />
802 <p>The following correspond to the /chanopt command
</p>
803 6 - Hide Join/Part Message (text_hidejoinpart)
<br />
804 7 - unused (was for color paste)
<br />
805 8 - Beep on message (alert_beep)
<br />
806 9 - Blink Tray (alert_tray)
<br />
807 10 - Blink Task Bar (alert_taskbar)
<br />
808 <p>Example of checking if the current context has Hide Join/Part messages set:
</p>
809 <div class=
"example synNormal"><div class='line_number'
>
814 <div class='content'
><pre><span class=
"synStatement">if
</span>( Xchat::context_info-
>{flags}
& (
<span class=
"synConstant">1</span> << <span class=
"synConstant">6</span>) ) {
815 Xchat::
<span class=
"synStatement">print
</span>(
<span class=
"synStatement">"</span><span class=
"synConstant">Hide Join/Part messages is enabled
</span><span class=
"synStatement">"</span> );
820 <td>id
</td> <td>Unique server ID
</td>
825 <td>lag in milliseconds
</td>
827 <td>maxmodes
</td> <td>Maximum modes per line
</td>
829 <td>network
</td> <td>network name to which this channel belongs
</td>
831 <td>nickprefixes
</td> <td>Nickname prefixes e.g.
"+@"</td>
835 <td>nickmodes
</td> <td>Nickname mode chars e.g.
"vo"</td>
838 <td>number of bytes in the send queue
</td>
842 <td>server
</td> <td>server name to which this channel belongs
</td>
844 <td>type
</td> <td>the type of this context
<br />
849 5 - server notices
<br />
852 <td>users
</td> <td>Number of users in this channel
</td>
854 </table><p>"dcc" - list of DCC file transfers
</p>
855 <table border=
"1"> <tr style=
"background-color: #dddddd">
856 <td>Key
</td> <td>Value
</td>
858 <td>address32
</td> <td>address of the remote user(ipv4 address)
</td>
860 <td>cps
</td> <td>bytes per second(speed)
</td>
862 <td>destfile
</td> <td>destination full pathname
</td>
864 <td>file
</td> <td>file name
</td>
867 <td>nick of the person this DCC connection is connected to
</td>
869 <td>port
</td> <td>TCP port number
</td>
871 <td>pos
</td> <td>bytes sent/received
</td>
873 <td>poshigh
</td> <td>bytes sent/received, high order
32 bits
</td>
875 <td>resume
</td> <td>point at which this file was resumed
<br />
876 (zero if it was not resumed)
879 <td>resumehigh
</td> <td>point at which this file was resumed, high order
32 bits
<br />
882 <td>size
</td> <td>file size in bytes low order
32 bits
</td>
884 <td>sizehigh
</td> <td>file size in bytes, high order
32 bits (when the files is
> 4GB)
</td>
887 <td>status
</td> <td>DCC Status:
<br />
896 <td>type
</td> <td>DCC Type:
<br />
902 </tr></table><p>"ignore" - current ignore list
</p>
903 <table border=
"1"> <tr style=
"background-color: #dddddd">
904 <td>Key
</td> <td>Value
</td>
906 <td>mask
</td> <td>ignore mask. e.g: *!*@*.aol.com
</td>
908 <td>flags
</td> <td>Bit field of flags.
<br />
918 </tr></table><p>"notify" - list of people on notify
</p>
920 <tr style=
"background-color: #dddddd">
921 <td>Key
</td> <td>Value
</td>
924 <td>comma separated list of networks where you will be notfified about this user's online/offline status or undef if you will be notificed on every network you are connected to
</td>
926 <td>nick
</td> <td>nickname
</td>
928 <td>flags
</td> <td>0 = is online
</td>
930 <td>on
</td> <td>time when user came online
</td>
932 <td>off
</td> <td>time when user went offline
</td>
934 <td>seen
</td> <td>time when user was last verified still online
</td>
936 </table><p>the values indexed by on, off and seen can be passed to localtime
937 and gmtime, see perldoc -f
<a href=
"http://perldoc.perl.org/functions/localtime.html">localtime
</a> and perldoc -f
<a href=
"http://perldoc.perl.org/functions/gmtime.html">gmtime
</a> for more
938 detail
</p><p>"users" - list of users in the current channel
</p>
939 <table border=
"1"> <tr style=
"background-color: #dddddd">
940 <td>Key
</td> <td>Value
</td>
942 <td>away
</td> <td>away status(boolean)
</td>
945 <td>last time a user was seen talking, this is the an epoch time(number of seconds since a certain date, that date depends on the OS)
</td>
947 <td>nick
</td> <td>nick name
</td>
950 <td>host name in the form: user@host or undef if not known
</td>
952 <td>prefix
</td> <td>prefix character, .e.g: @ or +
</td>
955 <td>Real name or undef
</td>
958 <td>selected status in the user list, only works when retrieving the user list of the focused tab. You can use the /USELECT command to select the nicks
</td>
960 </table><p>"networks" - list of networks and the associated settings from network list
</p>
961 <table border=
"1"> <tr style=
"background-color: #dddddd">
962 <td>Key
</td> <td>Value
</td>
966 <td>autojoins
</td> <td>An object with the following methods:
<br />
973 <td>returns a list of this networks' autojoin channels in list context, a count of the number autojoin channels in scalar context
</td>
976 <td>returns a list of the keys to go with the channels, the order is the same as the channels, if a channel doesn't have a key, '' will be returned in it's place
</td>
979 <td>a combination of channels() and keys(), returns a list of (channels, keys) pairs. This can be assigned to a hash for a mapping from channel to key.
</td>
982 <td>return the pairs as a hash reference
</td>
985 <td>the original string that was used to construct this autojoin object, this can be used with the JOIN command to join all the channels in the autojoin list
</td>
988 <td>return an array reference of hash references consisting of the keys
"channel" and
"key"</td>
991 <td>returns true if the network has autojoins and false otherwise
</td>
998 <td>connect_commands
</td> <td>An array reference containing the connect commands for a network. An empty array if there aren't any
</td>
1000 <td>encoding
</td> <td>the encoding for the network
</td>
1004 a hash reference corresponding to the checkboxes in the network edit window
1007 <td>allow_invalid
</td>
1008 <td>true if
"Accept invalid SSL certificate" is checked
</td>
1010 <td>autoconnect
</td>
1011 <td>true if
"Auto connect to this network at startup" is checked
</td>
1014 <td>true if
"Connect to selected server only" is
<strong>NOT
</strong> checked
</td>
1017 <td>true if
"Use global user information" is checked
</td>
1020 <td>true if
"Bypass proxy server" is
<strong>NOT
</strong> checked
</td>
1023 <td>true if
"Use SSL for all the servers on this network" is checked
</td>
1029 <td>Corresponds with the
"Nick name" field in the network edit window
</td>
1032 <td>Corresponds with the
"Second choice" field in the network edit window
</td>
1034 <td>irc_real_name
</td>
1035 <td>Corresponds with the
"Real name" field in the network edit window
</td>
1037 <td>irc_user_name
</td>
1038 <td>Corresponds with the
"User name" field in the network edit window
</td>
1041 <td>Name of the network
</td>
1043 <td>nickserv_password
</td>
1044 <td>Corresponds with the
"Nickserv password" field in the network edit window
</td>
1047 <td>Index into the list of servers in the
"servers" key, this is used if the
"cycle" flag is false
</td>
1049 <td>server_password
</td>
1050 <td>Corresponds with the
"Server password" field in the network edit window
</td>
1053 <td>An array reference of hash references with a
"host" and
"port" key. If a port is not specified then
6667 will be used.
</td>
1057 <h3><a name=
"xchat_user_info" /><code>Xchat::user_info( [$nick] )
</code></h3>
1059 <li><strong><code>$nick
</code> - the nick to look for, if this is not given your own nick will be
1060 used as default
</strong>
1063 <p>This function is mainly intended to be used as a shortcut for when you need
1064 to retrieve some information about only one user in a channel. Otherwise it
1065 is better to use
<a href=
"#xchat_get_list">get_list
</a>.
1066 If
<code>$nick
</code> is found a hash reference containing the same keys as those in the
1067 "users
" list of
<a href=
"#xchat_get_list">get_list
</a> is returned otherwise undef is returned.
1068 Since it relies on
<a href=
"#xchat_get_list">get_list
</a> this function can only be used in a
1069 channel context.
</p>
1072 <h3><a name=
"xchat_context_info" /><code>Xchat::context_info( [$context] )
</code></h3>
1074 <li><strong><code>$context
</code> - context returned from
<a href=
"#xchat_get_context">get_context
</a>,
<a href=
"#xchat_find_context">find_context
</a> and
<a href=
"#xchat_get_list">get_list
</a>, this is the context that you want infomation about. If this is omitted, it will default to current context.
</strong>
1077 <p>This function will return the information normally retrieved with
<a href=
"#xchat_get_info">get_info
</a>, except this is for the context that is passed in. The information will be returned in the form of a hash. The keys of the hash are the
<code>$id
</code> you would normally supply to
<a href=
"#xchat_get_info">get_info
</a> as well as all the keys that are valid for the items in the
"channels
" list from
<a href=
"#xchat_get_list">get_list
</a>. Use of this function is more efficient than calling get_list(
"channels
" ) and searching through the result.
</p>
1079 <div class=
"example synNormal"><div class='line_number'
>
1092 <div class='content'
><pre><span class=
"synStatement">use strict
</span>;
1093 <span class=
"synStatement">use warnings
</span>;
1094 <span class=
"synStatement">use
</span>Xchat
<span class=
"synStatement">qw(
</span><span class=
"synConstant">:all
</span><span class=
"synStatement">)
</span>;
<span class=
"synComment"># imports all the functions documented on this page
</span>
1096 register(
<span class=
"synStatement">"</span><span class=
"synConstant">User Count
</span><span class=
"synStatement">"</span>,
<span class=
"synStatement">"</span><span class=
"synConstant">0.1</span><span class=
"synStatement">"</span>,
1097 <span class=
"synStatement">"</span><span class=
"synConstant">Print out the number of users on the current channel
</span><span class=
"synStatement">"</span> );
1098 hook_command(
<span class=
"synStatement">"</span><span class=
"synConstant">UCOUNT
</span><span class=
"synStatement">"</span>, \
<span class=
"synIdentifier">&display_count
</span> );
1099 <span class=
"synStatement">sub
</span><span class=
"synIdentifier">display_count
</span>{
1100 prnt
<span class=
"synStatement">"</span><span class=
"synConstant">There are
</span><span class=
"synStatement">"</span> . context_info()-
>{users} .
<span class=
"synStatement">"</span><span class=
"synConstant"> users in this channel.
</span><span class=
"synStatement">"</span>;
1101 <span class=
"synStatement">return
</span> EAT_XCHAT;
1106 <h3><a name=
"xchat_strip_code" /><code>Xchat::strip_code( $string )
</code></h3>
1108 <li><strong><code>$string
</code> - string to remove codes from
</strong>
1111 <p>This function will remove bold, color, beep, reset, reverse and underline codes from
<code>$string
</code>. It will also remove ANSI escape codes which might get used by certain terminal based clients. If it is called in void context
<code>$string
</code> will be modified otherwise a modified copy of
<code>$string
</code> is returned.
</p>
1114 <h2><a name=
"examples" />Examples
</h2>
1117 <h3><a name=
"asynchronous_dns_resolution_with_hook_fd" />Asynchronous DNS resolution with hook_fd
</h3>
1118 <div class=
"example synNormal"><div class='line_number'
>
1155 <div class='content'
><pre><span class=
"synStatement">use strict
</span>;
1156 <span class=
"synStatement">use warnings
</span>;
1157 <span class=
"synStatement">use
</span>Xchat
<span class=
"synStatement">qw(
</span><span class=
"synConstant">:all
</span><span class=
"synStatement">)
</span>;
1158 <span class=
"synStatement">use
</span>Net::DNS;
1160 hook_command(
<span class=
"synStatement">"</span><span class=
"synConstant">BGDNS
</span><span class=
"synStatement">"</span>,
<span class=
"synStatement">sub
</span>{
1161 <span class=
"synStatement">my
</span> <span class=
"synIdentifier">$host
</span> =
<span class=
"synIdentifier">$_[
</span><span class=
"synConstant">0</span><span class=
"synIdentifier">][
</span><span class=
"synConstant">1</span><span class=
"synIdentifier">]
</span>;
1162 <span class=
"synStatement">my
</span> <span class=
"synIdentifier">$resolver
</span> = Net::DNS::Resolver-
>new;
1163 <span class=
"synStatement">my
</span> <span class=
"synIdentifier">$sock
</span> =
<span class=
"synIdentifier">$resolver-
>bgsend
</span>(
<span class=
"synIdentifier">$host
</span> );
1165 hook_fd(
<span class=
"synIdentifier">$sock
</span>,
<span class=
"synStatement">sub
</span>{
1166 <span class=
"synStatement">my
</span> <span class=
"synIdentifier">$ready_sock
</span> =
<span class=
"synIdentifier">$_[
</span><span class=
"synConstant">0</span><span class=
"synIdentifier">]
</span>;
1167 <span class=
"synStatement">my
</span> <span class=
"synIdentifier">$packet
</span> =
<span class=
"synIdentifier">$resolver-
>bgread
</span>(
<span class=
"synIdentifier">$ready_sock
</span> );
1169 <span class=
"synStatement">if
</span>(
<span class=
"synIdentifier">$packet-
>authority
</span> && (
<span class=
"synStatement">my
</span> <span class=
"synIdentifier">@answers
</span> =
<span class=
"synIdentifier">$packet-
>answer
</span> ) ) {
1171 <span class=
"synStatement">if
</span>(
<span class=
"synIdentifier">@answers
</span> ) {
1172 prnt
<span class=
"synStatement">"</span><span class=
"synIdentifier">$host
</span><span class=
"synConstant">:
</span><span class=
"synStatement">"</span>;
1173 <span class=
"synStatement">my
</span> <span class=
"synIdentifier">$padding
</span> =
<span class=
"synStatement">"</span><span class=
"synConstant"> </span><span class=
"synStatement">"</span> x (
<span class=
"synStatement">length
</span>(
<span class=
"synIdentifier">$host
</span> ) +
<span class=
"synConstant">2</span>);
1174 <span class=
"synStatement">for
</span> <span class=
"synStatement">my
</span> <span class=
"synIdentifier">$answer
</span> (
<span class=
"synIdentifier">@answers
</span> ) {
1175 prnt
<span class=
"synIdentifier">$padding
</span> .
<span class=
"synIdentifier">$answer-
>rdatastr
</span> .
<span class=
"synStatement">'
</span><span class=
"synConstant"> </span><span class=
"synStatement">'
</span> .
<span class=
"synIdentifier">$answer-
>type
</span>;
1178 }
<span class=
"synStatement">else
</span> {
1179 prnt
<span class=
"synStatement">"</span><span class=
"synConstant">Unable to resolve
</span><span class=
"synIdentifier">$host
</span><span class=
"synStatement">"</span>;
1182 <span class=
"synStatement">return
</span> REMOVE;
1185 <span class=
"synConstant">flags
</span> =
> FD_READ,
1188 <span class=
"synStatement">return
</span> EAT_XCHAT;
1195 <h2><a name=
"contact_information" />Contact Information
</h2>
1196 <p>Contact Lian Wan Situ at
<atmcmnky [at] yahoo.com
> for questions, comments and
1197 corrections about this page or the Perl plugin itself. You can also find me
1198 in #xchat on FreeNode under the nick Khisanth.
</p>
1199 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
1200 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
1201 <big><strong><span class=
"block"> X-Chat
2 Perl Interface
</span></strong></big>