#!/usr/bin/perl -w # Autor : quinton@free.fr / quinquin/IRCnet # Date : october 1999. # see http://quinton.free.fr/xchat/ for other scripts, may be some # of them are usefull for you ! # This script is used to reformat output of /who *value* command # This command (/who) is used to scan for persons on IRC networks. # This script handle /who command, and default /who command is not called. # usage : /who arg1 arg2 arg3 # ex : /who *zed* *xchat* # I don't know really how pattern machting work for /who command? # so put * meta character every where you need ... # note the use of package to avoid name space conflicts # Configuration. # hum, no configuration needed for this simple script. # may be you can change display format, so just jump to XXXX tag ;-) # should make an effort to make a format string like this one # # $format = "%n : %c : %a", with %n = nick, %c = channel, %a = adress # # default is : $format = "*** "%-15s : %-12 : %s", $nick, $chan, $addr # end of configuration # ------------------------------------------------------------------------------------ IRC::print "\0035:: Loading Who-Handler script ::\003 \n"; $version = IRC::get_info(0); # get a string of the form 1.2.0 or 1.3.3 $version =~ s/\.//g; if ($version >= 120) { IRC::register("Who-Handler Script", "1.0", "", ""); } IRC::add_message_handler("352", "IRC::Xchat::WhoHandler::who_handler"); # /who IRC::add_message_handler("315", "IRC::Xchat::WhoHandler::who_end_handler"); # /who end IRC::add_command_handler("who", "IRC::Xchat::WhoHandler::who_cmd_handler"); package IRC::Xchat::WhoHandler; sub who_cmd_handler { local($cmds) = @_; # command line may contain extra white spaces. $cmds =~ s/\s+$//; # command line like /who arg1 arg2 arg3 are accepted all in one foreach $cmd ( split(/\s+/, $cmds)) { # IRC::print ".. /who $cmd\n"; IRC::send_raw("WHO $cmd\r\n"); } return 1; } # this handler is used to avoid printing of "End of list" message sub who_end_handler { local($line) = @_; # IRC::print "who_end_handler() ''$line''\n"; return 1; } # this is the real handler, it is used to reformat the /who command return values sub who_handler { local($line) = @_; # /who list # >> :server 352 me chan user addr serv2 nick flag1 :flag2 realname if($line =~ m/:(.*)\s+352\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?):(.*?)\s+(.*)/o) { $server = $1; # irc server adresse $me = $2; # my nick name $chan = $3; # which chan nick is on $user = $4; # username $addr = $5; # user adresse $serv2 = $6; # an other serv adress with meta char ? $nick = $7; # nickname $flag1 = $8; # flags ? $flag2 = $9; # flags ? $real = $10; # realname # XXXX : change display format here ! my $result = sprintf("%-15s : %-12s : %s", $nick, $chan, $addr); IRC::print "*** $result\n"; return 1; } else { # there may be a probleme with /who result that may have change format. IRC::print "xchat::who handler: may be a problem with return value of /who command\n"; IRC::print "xchat::who handler: this is a pattern matching problem.\n"; IRC::print "xchat::who handler: using default handler\n"; # so make default handler work ;-) return 0; } return 0; } 1; _END_