1 =head1 X-Chat 2 Perl Interface
5 This is the new Perl interface for X-Chat 2. However, due to changes in
6 xchat's plugin code you will need xchat 2.0.8 or above to load this. Scripts
7 written using the old interface will continue to work. If there are any
8 problems, questions, comments or suggestions please email them to the address
9 on the bottom of this page.
39 C<Xchat::EAT_NONE> - pass the event along
42 C<Xchat::EAT_XCHAT> - don't let xchat see this event
45 C<Xchat::EAT_PLUGIN> - don't let other scripts and plugins see this event but xchat will still see it
48 C<Xchat::EAT_ALL> - don't let anything else see this event
52 =head4 Timer and fd hooks
57 C<Xchat::KEEP> - keep the timer going or hook watching the handle
60 C<Xchat::REMOVE> - remove the timer or hook watching the handle
69 C<Xchat::FD_READ> - invoke the callback when the handle is ready for reading
72 C<Xchat::FD_WRITE> - invoke the callback when the handle is ready for writing
75 C<Xchat::FD_EXCEPTION> - invoke the callback if an exception occurs
78 C<Xchat::FD_NOTSOCKET> - indicate that the handle being hooked is not a socket
84 =head3 C<Xchat::register( $name, $version, [$description,[$callback]] )>
89 C<$name> - The name of this script
92 C<$version> - This script's version
95 C<$description> - A description for this script
98 C<$callback> - This is a function that will be called when the is script
99 unloaded. This can be either a reference to a
100 function or an anonymous sub reference.
104 This is the first thing to call in every script.
106 =head3 C<Xchat::hook_server( $message, $callback, [\%options] )>
108 =head3 C<Xchat::hook_command( $command, $callback, [\%options] )>
110 =head3 C<Xchat::hook_print( $event,$callback, [\%options] )>
112 =head3 C<Xchat::hook_timer( $timeout,$callback, [\%options | $data] )>
114 =head3 C<Xchat::hook_fd( $handle, $callback, [ \%options ] )>
116 These functions can be to intercept various events.
117 hook_server can be used to intercept any incoming message from the IRC server.
118 hook_command can be used to intercept any command, if the command doesn't currently exist then a new one is created.
119 hook_print can be used to intercept any of the events listed in Setttings-E<gt>Advanced-E<gt>Text Events
120 hook_timer can be used to create a new timer
126 C<$message> - server message to hook such as PRIVMSG
129 C<$command> - command to intercept, without the leading /
132 C<$event> - one of the events listed in Settings-E<gt>Advanced-E<gt>Text Events
135 C<$timeout> - timeout in milliseconds
138 C<$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 L<fileno|http://perldoc.perl.org/functions/fileno.html>
141 C<$callback> - callback function, this is called whenever
142 the hooked event is trigged, the following are
143 the conditions that will trigger the different hooks.
144 This can be either a reference to a
145 function or an anonymous sub reference.
148 \%options - a hash reference containing addional options for the hooks
152 Valid keys for \%options:
159 <td>data</td> <td>Additional data that is to be associated with the<br />
160 hook. For timer hooks this value can be provided either as<br />
161 <code>Xchat::hook_timer( $timeout, $cb,{data=>$data})</code><br />
162 or <code>Xchat::hook_timer( $timeout, $cb, $data )</code>.<br />
163 However, this means that hook_timer cannot be provided<br />
164 with a hash reference containing data as a key.<br />
167 my $options = { data => [@arrayOfStuff] };<br />
168 Xchat::hook_timer( $timeout, $cb, $options );<br />
170 In this example, the timer's data will be<br />
171 [@arrayOfStuff] and not { data => [@arrayOfStuff] }<br />
173 This key is valid for all of the hook functions.<br />
175 Default is undef.<br />
180 <td>priority</td> <td>Sets the priority for the hook.<br />
181 It can be set to one of the
182 <code>Xchat::PRI_*</code> constants.<br />
184 This key only applies to server, command
185 and print hooks.<br />
187 Default is <code>Xchat::PRI_NORM</code>.
193 <td>help_text</td> <td>Text displayed for /help $command.<br />
195 This key only applies to command hooks.<br />
202 <td>flags</td> <td>Specify the flags for a fd hook.<br />
204 See <a href="#hook_fd_flags">hook fd flags</a> section for valid values.<br />
206 On Windows if the handle is a pipe you specify<br />
207 Xchat::FD_NOTSOCKET in addition to any other flags you might be using.<br />
209 This key only applies to fd hooks.<br />
210 Default is Xchat::FD_READ
218 =head4 When callbacks are invoked
220 Each of the hooks will be triggered at different times depending on the type
227 <tr style="background-color: #dddddd">
228 <td>Hook Type</td> <td>When the callback will be invoked</td>
232 <td>server hooks</td> <td>a <code>$message</code> message is
233 received from the server
238 <td>command hooks</td> <td>the <code>$command</code> command is
239 executed, either by the user or from a script
244 <td>print hooks</td> <td>X-Chat is about to print the message for the
245 <code>$event</code> event
250 <td>timer hooks</td> <td>called every <code>$timeout</code> milliseconds
251 (1000 millisecond is 1 second)<br />
252 the callback will be executed in the same context where
253 the hook_timer was called, if the context no longer exists
254 then it will execute in a random context
259 <td>fd hooks</td> <td>depends on the flags that were passed to hook_fd<br />
260 See <a href="#hook_fd_flags">hook_fd flags</a> section.
268 The value return from these hook functions can be passed to C<Xchat::unhook>
271 =head4 Callback Arguments
273 All callback functions will receive their arguments in C<@_> like every
274 other Perl subroutine.
279 Server and command callbacks<br />
281 <code>$_[0]</code> - array reference containing the IRC message or command and
282 arguments broken into words<br />
284 /command arg1 arg2 arg3<br />
285 <code>$_[0][0]</code> - command<br />
286 <code>$_[0][1]</code> - arg1<br />
287 <code>$_[0][2]</code> - arg2<br />
288 <code>$_[0][3]</code> - arg3<br />
290 <code>$_[1]</code> - array reference containing the Nth word to the last word<br />
292 /command arg1 arg2 arg3<br />
293 <code>$_[1][0]</code> - command arg1 arg2 arg3<br />
294 <code>$_[1][1]</code> - arg1 arg2 arg3<br />
295 <code>$_[1][2]</code> - arg2 arg3<br />
296 <code>$_[1][3]</code> - arg3<br />
298 <code>$_[2]</code> - the data that was passed to the hook function<br />
300 Print callbacks<br />
302 <code>$_[0]</code> - array reference containing the values for the
303 text event see Settings->Advanced->Text Events<br />
304 <code>$_[1]</code> - the data that was passed to the hook function<br />
306 Timer callbacks<br />
308 <code>$_[0]</code> - the data that was passed to the hook function<br />
313 <code>$_[0]</code> - the handle that was passed to hook_fd<br />
314 <code>$_[1]</code> - flags indicating why the callback was called<br />
315 <code>$_[2]</code> - the data that was passed to the hook function<br />
320 =head4 Callback return values
322 All server, command and print callbacks should return one of
323 the C<Xchat::EAT_*> constants.
324 Timer callbacks can return Xchat::REMOVE to remove
325 the timer or Xchat::KEEP to keep it going
327 =head4 Miscellaneous Hook Related Information
329 For server hooks, if C<$message> is "RAW LINE" then C<$cb> will be called for
330 every IRC message than X-Chat receives.
332 For command hooks if C<$command> is "" then C<$cb> will be called for
333 messages entered by the user that is not a command.
335 For print hooks besides those events listed in
336 Settings-E<gt>Advanced-E<gt>Text Events, these additional events can be used.
342 <tr style="background-color: #dddddd">
343 <td>Event</td> <td>Description</td>
347 <td>"Open Context"</td> <td>a new context is created</td>
351 <td>"Close Context"</td> <td>a context has been close</td>
355 <td>"Focus Tab"</td> <td>when a tab is brought to the front</td>
359 <td>"Focus Window"</td> <td>when a top level window is focused or the
360 main tab window is focused by the window manager
365 <td>"DCC Chat Text"</td> <td>when text from a DCC Chat arrives.
366 <code>$_[0]</code> will have these values<br />
368 <code>$_[0][0]</code> - Address<br />
369 <code>$_[0][1]</code> - Port<br />
370 <code>$_[0][2]</code> - Nick<br />
371 <code>$_[0][3]</code> - Message<br />
376 <td>"Key Press"</td> <td>used for intercepting key presses<br />
377 $_[0][0] - key value<br />
378 $_[0][1] - state bitfield, 1 - shift, 4 - control, 8 - alt<br />
379 $_[0][2] - string version of the key which might be empty for unprintable keys<br />
380 $_[0][3] - length of the string in $_[0][2]<br />
387 =head3 C<Xchat::unhook( $hook )>
392 C<$hook> - the hook that was previously returned by one of the C<Xchat::hook_*> functions
397 This function is used to removed a hook previously added with one of
398 the C<Xchat::hook_*> functions
400 It returns the data that was passed to the C<Xchat::hook_*> function when
404 =head3 C<Xchat::print( $text | \@lines, [$channel,[$server]] )>
409 C<$text> - the text to print
412 C<\@lines> - array reference containing lines of text to be printed
413 all the elements will be joined together before printing
416 C<$channel> - channel or tab with the given name where C<$text>
420 C<$server> - specifies that the text will be printed in a channel or tab
421 that is associated with C<$server>
425 The first argument can either be a string or an array reference of strings.
426 Either or both of C<$channel> and C<$server> can be undef.
428 If called as C<Xchat::print( $text )>, it will always return true.
429 If called with either the channel or the channel and the server
430 specified then it will return true if a context is found and
431 false otherwise. The text will not be printed if the context
432 is not found. The meaning of setting C<$channel> or C<$server> to
434 L<find_context|xchat_find_context>.
437 =head3 C<Xchat::printf( $format, LIST )>
442 C<$format> - a format string, see "perldoc -f L<sprintf|http://perldoc.perl.org/functions/sprintf.html>" for further detail
445 LIST - list of values for the format fields
449 =head3 C<Xchat::command( $command | \@commands, [$channel,[$server]] )>
454 C<$command> - the command to execute, without the leading /
457 C<\@commands> - array reference containing a list of commands to execute
460 C<$channel> - channel or tab with the given name where C<$command> will be executed
463 C<$server> - specifies that the command will be executed in a channel or tab that is associated with C<$server>
467 The first argument can either be a string or an array reference of strings.
468 Either or both of C<$channel> and C<$server> can be undef.
470 If called as C<Xchat::command( $command )>, it will always return true.
471 If called with either the channel or the channel and the server
472 specified then it will return true if a context is found and false
473 otherwise. The command will not be executed if the context is not found.
474 The meaning of setting C<$channel> or C<$server> to undef is the same
478 =head3 C<Xchat::commandf( $format, LIST )>
483 C<$format> - a format string, see "perldoc -f L<sprintf|http://perldoc.perl.org/functions/sprintf.html>" for further detail
486 LIST - list of values for the format fields
490 =head3 C<Xchat::find_context( [$channel, [$server]] )>
495 C<$channel> - name of a channel
498 C<$server> - name of a server
502 Either or both of C<$channel> and $server can be undef. Calling
503 C<Xchat::find_context()> is the same as calling
504 C<Xchat::find_context( undef, undef)> and
505 C<Xchat::find_context( $channel )> is
506 the same as C<Xchat::find_context( $channel, undef )>.
508 If C<$server> is undef, find any channel named $channel.
509 If C<$channel> is undef, find the front most window
510 or tab named C<$server>.If both $channel and
511 C<$server> are undef, find the currently focused tab or window.
513 Return the context found for one of the above situations or undef if such
514 a context cannot be found.
517 =head3 C<Xchat::get_context()>
523 Returns the current context.
525 =head3 C<Xchat::set_context( $context | $channel,[$server] )>
530 C<$context> - context value as returned from L<get_context|xchat_get_context>,L<find_context|xchat_find_context> or one
531 of the fields in the list of hashrefs returned by list_get
534 C<$channel> - name of a channel you want to switch context to
537 C<$server> - name of a server you want to switch context to
541 See L<find_context|xchat_find_context> for more details on C<$channel> and C<$server>.
543 Returns true on success, false on failure
545 =head3 C<Xchat::get_info( $id )>
550 C<$id> - one of the following case sensitive values
558 <tr style="background-color: #dddddd">
560 <td>Return value</td>
561 <td>Associated Command(s)</td>
566 <td>away reason or undef if you are not away</td>
572 <td>current channel name</td>
578 <td>character-set used in the current context</td>
583 <td>event_text <Event Name></td> <td>text event format string for <Event name><br />
585 <div class="example">
586 my $channel_msg_format = Xchat::get_info( "event_text Channel Message" );
593 <td>real hostname of the current server</td>
599 <td>connection id</td>
605 <td>contents of the inputbox</td>
611 <td>the system wide directory where xchat will look for plugins.
612 this string is in the same encoding as the local file system</td>
618 <td>the current channels modes or undef if not known</td>
624 <td>current network name or undef, this value is taken from the Network List</td>
630 <td>current nick</td>
636 <td>nickserv password for this network or undef, this value is taken from the Network List</td>
641 <td>server</td> <td>current server name <br />
642 (what the server claims to be) undef if not connected
648 <td>state_cursor</td>
649 <td>current inputbox cursor position in characters</td>
655 <td>current channel topic</td>
661 <td>xchat version number</td>
667 <td>status of the xchat window, possible values are "active", "hidden"
673 <td>win_ptr</td> <td>native window pointer, GtkWindow * on Unix, HWND on Win32.<br />
674 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 />
675 Additionally when you have detached tabs, each of the windows will return a different win_ptr for the different Gtk2::Window objects.<br />
676 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.
682 <td>similar to win_ptr except it will always be a GtkWindow *</td>
686 <td>xchatdir</td> <td>xchat config directory encoded in UTF-8<br />
688 /home/user/.xchat2<br />
689 C:\Documents and Settings\user\Application Data\X-Chat 2
695 <td>xchatdirfs</td> <td>same as xchatdir except encoded in the locale file system encoding</td>
700 <p>This function is used to retrieve certain information about the current
701 context. If there is an associated command then that command can be used to change the value for a particular ID.</p>
705 =head3 C<Xchat::get_prefs( $name )>
710 C<$name> - name of a X-Chat setting (available through the /set command)
714 This function provides a way to retrieve X-Chat's setting information.
716 Returns C<undef> if there is no setting called called C<$name>.
719 =head3 C<Xchat::emit_print( $event, LIST )>
724 C<$event> - name from the Event column in Settings-E<gt>Advanced-E<gt>Text Events
727 LIST - this depends on the Description column on the bottom of Settings-E<gt>Advanced-E<gt>Text Events
731 This functions is used to generate one of the events listed under
732 Settings-E<gt>Advanced-E<gt>Text Events
734 Note: when using this function you MUST return Xchat::EAT_ALL otherwise you will end up with duplicate events.
735 One is the original and the second is the one you emit.
737 Returns true on success, false on failure
739 =head3 C<Xchat::send_modes( $target | \@targets, $sign, $mode, [ $modes_per_line ] )>
744 C<$target> - a single nick to set the mode on
747 C<\@targets> - an array reference of the nicks to set the mode on
750 C<$sign> - the mode sign, either '+' or '-'
753 C<$mode> - the mode character such as 'o' and 'v', this can only be one character long
756 C<$modes_per_line> - an optional argument maximum number of modes to send per at once, pass 0 use the current server's maximum (default)
760 Send multiple mode changes for the current channel. It may send multiple MODE lines if the request doesn't fit on one.
765 <div class="example">
771 hook_command( "MODES", sub {
772 my (undef, $who, $sign, $mode) = @{$_[0]};
774 my @targets = split /,/, $who;
776 send_modes( \@targets, $sign, $mode, 1 );
778 send_modes( $who, $sign, $mode );
789 =head3 C<Xchat::nickcmp( $nick1, $nick2 )>
794 C<$nick1, $nick2> - the two nicks or channel names that are to be compared
798 The comparsion is based on the current server. Either a RFC1459 compliant
799 string compare or plain ascii will be using depending on the server. The
800 comparison is case insensitive.
802 Returns a number less than, equal to or greater than zero if
804 found respectively, to be less than, to match, or be greater than
808 =head3 C<Xchat::get_list( $name )>
813 C<$name> - name of the list, one of the following:
814 "channels", "dcc", "ignore", "notify", "users"
818 This function will return a list of hash references. The hash references
819 will have different keys depend on the list. An empty list is returned
820 if there is no such list.
824 <p>"channels" - list of channels, querys and their server</p>
828 <tr style="background-color: #dddddd">
829 <td>Key</td> <td>Description</td>
833 <td>channel</td> <td>tab name</td>
838 <td>channel types supported by the server, typically "#&"</td>
842 <td>context</td> <td>can be used with set_context</td>
846 <td>flags</td> <td>Server Bits:<br />
850 3 - EndOfMotd(Login complete)<br />
852 5 - Has IDMSG (FreeNode)<br />
854 <p>The following correspond to the /chanopt command</p>
855 6 - Hide Join/Part Message (text_hidejoinpart)<br />
856 7 - unused (was for color paste)<br />
857 8 - Beep on message (alert_beep)<br />
858 9 - Blink Tray (alert_tray)<br />
859 10 - Blink Task Bar (alert_taskbar)<br />
860 <p>Example of checking if the current context has Hide Join/Part messages set:</p>
861 <div class="example">
863 if( Xchat::context_info->{flags} & (1 << 6) ) {
864 Xchat::print( "Hide Join/Part messages is enabled" );
873 <td>id</td> <td>Unique server ID </td>
878 <td>lag in milliseconds</td>
882 <td>maxmodes</td> <td>Maximum modes per line</td>
886 <td>network</td> <td>network name to which this channel belongs</td>
890 <td>nickprefixes</td> <td>Nickname prefixes e.g. "+@"</td>
894 <td>nickmodes</td> <td>Nickname mode chars e.g. "vo"</td>
899 <td>number of bytes in the send queue</td>
903 <td>server</td> <td>server name to which this channel belongs</td>
907 <td>type</td> <td>the type of this context<br />
912 5 - server notices<br />
917 <td>users</td> <td>Number of users in this channel</td>
921 <p>"dcc" - list of DCC file transfers</p>
924 <tr style="background-color: #dddddd">
925 <td>Key</td> <td>Value</td>
929 <td>address32</td> <td>address of the remote user(ipv4 address)</td>
933 <td>cps</td> <td>bytes per second(speed)</td>
937 <td>destfile</td> <td>destination full pathname</td>
941 <td>file</td> <td>file name</td>
946 <td>nick of the person this DCC connection is connected to</td>
950 <td>port</td> <td>TCP port number</td>
954 <td>pos</td> <td>bytes sent/received</td>
958 <td>poshigh</td> <td>bytes sent/received, high order 32 bits</td>
962 <td>resume</td> <td>point at which this file was resumed<br />
963 (zero if it was not resumed)
968 <td>resumehigh</td> <td>point at which this file was resumed, high order 32 bits<br />
973 <td>size</td> <td>file size in bytes low order 32 bits</td>
977 <td>sizehigh</td> <td>file size in bytes, high order 32 bits (when the files is > 4GB)</td>
980 <td>status</td> <td>DCC Status:<br />
991 <td>type</td> <td>DCC Type:<br />
1001 <p>"ignore" - current ignore list</p>
1004 <tr style="background-color: #dddddd">
1005 <td>Key</td> <td>Value</td>
1009 <td>mask</td> <td>ignore mask. e.g: *!*@*.aol.com</td>
1013 <td>flags</td> <td>Bit field of flags.<br />
1027 <p>"notify" - list of people on notify</p>
1029 <tr style="background-color: #dddddd">
1030 <td>Key</td> <td>Value</td>
1035 <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>
1039 <td>nick</td> <td>nickname</td>
1043 <td>flags</td> <td>0 = is online</td>
1047 <td>on</td> <td>time when user came online</td>
1051 <td>off</td> <td>time when user went offline</td>
1055 <td>seen</td> <td>time when user was last verified still online</td>
1059 <p>the values indexed by on, off and seen can be passed to localtime
1060 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
1063 <p>"users" - list of users in the current channel</p>
1066 <tr style="background-color: #dddddd">
1067 <td>Key</td> <td>Value</td>
1071 <td>away</td> <td>away status(boolean)</td>
1076 <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>
1080 <td>nick</td> <td>nick name</td>
1085 <td>host name in the form: user@host or undef if not known</td>
1089 <td>prefix</td> <td>prefix character, .e.g: @ or +</td>
1094 <td>Real name or undef</td>
1099 <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>
1103 <p>"networks" - list of networks and the associated settings from network list</p>
1106 <tr style="background-color: #dddddd">
1107 <td>Key</td> <td>Value</td>
1111 <td>autojoins</td> <td>An object with the following methods:<br />
1115 <td>Description</td>
1120 <td>returns a list of this networks' autojoin channels in list context, a count of the number autojoin channels in scalar context</td>
1125 <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>
1130 <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>
1135 <td>return the pairs as a hash reference</td>
1139 <td>as_string()</td>
1140 <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>
1145 <td>return an array reference of hash references consisting of the keys "channel" and "key"</td>
1150 <td>returns true if the network has autojoins and false otherwise</td>
1157 <td>connect_commands</td> <td>An array reference containing the connect commands for a network. An empty array if there aren't any</td>
1161 <td>encoding</td> <td>the encoding for the network</td>
1168 a hash reference corresponding to the checkboxes in the network edit window
1171 <td>allow_invalid</td>
1172 <td>true if "Accept invalid SSL certificate" is checked</td>
1176 <td>autoconnect</td>
1177 <td>true if "Auto connect to this network at startup" is checked</td>
1182 <td>true if "Connect to selected server only" is <strong>NOT</strong> checked</td>
1187 <td>true if "Use global user information" is checked</td>
1192 <td>true if "Bypass proxy server" is <strong>NOT</strong> checked</td>
1197 <td>true if "Use SSL for all the servers on this network" is checked</td>
1206 <td>Corresponds with the "Nick name" field in the network edit window</td>
1211 <td>Corresponds with the "Second choice" field in the network edit window</td>
1215 <td>irc_real_name</td>
1216 <td>Corresponds with the "Real name" field in the network edit window</td>
1221 <td>irc_user_name</td>
1222 <td>Corresponds with the "User name" field in the network edit window</td>
1228 <td>Name of the network</td>
1232 <td>nickserv_password</td>
1233 <td>Corresponds with the "Nickserv password" field in the network edit window</td>
1238 <td>Index into the list of servers in the "servers" key, this is used if the "cycle" flag is false</td>
1242 <td>server_password</td>
1243 <td>Corresponds with the "Server password" field in the network edit window</td>
1248 <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>
1254 =head3 C<Xchat::user_info( [$nick] )>
1259 C<$nick> - the nick to look for, if this is not given your own nick will be
1264 This function is mainly intended to be used as a shortcut for when you need
1265 to retrieve some information about only one user in a channel. Otherwise it
1266 is better to use L<get_list|xchat_get_list>.
1267 If C<$nick> is found a hash reference containing the same keys as those in the
1268 "users" list of L<get_list|xchat_get_list> is returned otherwise undef is returned.
1269 Since it relies on L<get_list|xchat_get_list> this function can only be used in a
1272 =head3 C<Xchat::context_info( [$context] )>
1277 C<$context> - context returned from L<get_context|xchat_get_context>, L<find_context|xchat_find_context> and L<get_list|xchat_get_list>, this is the context that you want infomation about. If this is omitted, it will default to current context.
1281 This function will return the information normally retrieved with L<get_info|xchat_get_info>, 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 C<$id> you would normally supply to L<get_info|xchat_get_info> as well as all the keys that are valid for the items in the "channels" list from L<get_list|xchat_get_list>. Use of this function is more efficient than calling get_list( "channels" ) and searching through the result.
1286 <div class="example">
1289 use Xchat qw(:all); # imports all the functions documented on this page
1291 register( "User Count", "0.1",
1292 "Print out the number of users on the current channel" );
1294 hook_command( "UCOUNT", \&display_count );
1297 prnt "There are " . context_info()->{users} . " users in this channel.";
1304 =head3 C<Xchat::strip_code( $string )>
1309 C<$string> - string to remove codes from
1313 This function will remove bold, color, beep, reset, reverse and underline codes from C<$string>. It will also remove ANSI escape codes which might get used by certain terminal based clients. If it is called in void context C<$string> will be modified otherwise a modified copy of C<$string> is returned.
1317 =head3 Asynchronous DNS resolution with hook_fd
1321 <div class="example">
1328 hook_command( "BGDNS", sub {
1329 my $host = $_[0][1];
1330 my $resolver = Net::DNS::Resolver->new;
1331 my $sock = $resolver->bgsend( $host );
1333 hook_fd( $sock, sub {
1334 my $ready_sock = $_[0];
1335 my $packet = $resolver->bgread( $ready_sock );
1337 if( $packet->authority && (my @answers = $packet->answer ) ) {
1341 my $padding = " " x (length( $host ) + 2);
1342 for my $answer ( @answers ) {
1343 prnt $padding . $answer->rdatastr . ' ' . $answer->type;
1347 prnt "Unable to resolve $host";
1363 =head2 Contact Information
1365 Contact Lian Wan Situ at E<lt>atmcmnky [at] yahoo.comE<gt> for questions, comments and
1366 corrections about this page or the Perl plugin itself. You can also find me
1367 in #xchat on FreeNode under the nick Khisanth.