X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=tools.pl;h=b554d4a7fc16ab636beb86b5563e76b1caac0017;hb=b9c3e00cbf52ff5ddb0d79fd66a6877f6feb508d;hp=bd98aa396028bcda91a20ed7c8f9726419cdd7ca;hpb=263b6777b90548951a13bd56419fa911b010eb9b;p=perl%2Fscripts%2Fxchat.git diff --git a/tools.pl b/tools.pl index bd98aa3..b554d4a 100755 --- a/tools.pl +++ b/tools.pl @@ -11,7 +11,9 @@ use Xchat qw/:all/; use lib get_info 'xchatdir'; use Xchat::XPI; -our $VERSION = '0.04'; +use constant MAX_MATCHES => 10; + +our $VERSION = '0.05'; my $ph; @@ -113,11 +115,38 @@ hook_command 'WIDE', sub { help_text => 'WIDE , say text in wide unicode characters' }; -$ph = new Xchat::XPI name => 'Misc tools', - tag => 'Tools', - desc => 'Perl interpretor, URI escaper', - author => 'Vincent Pit (VPIT)', - email => 'perl@profvince.com', - url => 'http://www.profvince.com'; +hook_command 'HGREP', sub { + my $txt = $_[1][1]; + return EAT_ALL unless defined $txt; + $txt = qr/$txt/i; + my @matches; + for (get_list 'users') { + my $host = $_->{host}; + next unless $host =~ /$txt/; + push @matches, [ $_->{nick}, $host ]; + } + my $nbr = @matches; + print $ph ($nbr == 0 ? 'No' : $nbr) + . ' match' . ('es' x ($nbr > 1)) + . ' to ' . $txt; + if (@matches < MAX_MATCHES) { + print $ph +(':' x ($nbr > 0)) . "\n"; + print $ph "\002$_->[0]\002 ($_->[1])\n" for @matches; + } else { + print $ph " (too many of them, omitted)\n"; + } + return EAT_ALL; +}, { + help_text => 'HGREP , print users in the current context whose hostname matches text' +}; + +$ph = Xchat::XPI->new( + name => 'Misc tools', + tag => 'Tools', + desc => 'Perl interpretor, URI escaper', + author => 'Vincent Pit (VPIT)', + email => 'perl@profvince.com', + url => 'http://www.profvince.com', +); 1;