1 package Xchat::VPIT::Tools;
11 use lib get_info 'xchatdir';
13 use Xchat::XPI::Utils qw<gui save_context>;
15 use constant MAX_MATCHES => 10;
17 our $VERSION = '0.05';
22 $Data::Dumper::Indent = 1;
23 $Data::Dumper::Sortkeys = 1;
26 hook_command 'TC', sub {
27 my $guard = save_context;
28 for (get_list 'channels') {
29 set_context $_->{context};
34 help_text => 'TC, reset all tab color indicators'
37 sub d { return Dumper @_; }
38 sub dp { print $ph Dumper(@_), "\n" }
40 sub warneval { print $ph 'Warning: ' . (join ' ', @ _) }
42 hook_command 'PERL', sub {
43 return EAT_ALL unless defined $_[0][1];
44 if ($_[0][1] eq '-o') {
45 return EAT_ALL unless defined $_[1][2];
46 local $SIG{__WARN__} = \&warneval;
47 my @result = grep defined, (eval $_[1][2]);
48 local $SIG{__WARN__} = 'DEFAULT';
51 print $ph "Error: $@\n";
53 command join ' ', 'MSG', get_info('channel'), @result;
55 print $ph "No output\n";
58 local $SIG{__WARN__} = \&warneval;
59 my @result = eval $_[1][1];
60 local $SIG{__WARN__} = 'DEFAULT';
63 print $ph "Error: $@\n";
66 @result = ('(empty)') unless @result;
67 my ($c, @scalars) = (0);
69 (defined || (push @scalars, '(undef)') && 0)
70 && (ref || (push @scalars, $_) && 0)
71 && ((push @scalars, '$REF' . ++$c) || 1)
74 local $Data::Dumper::Varname = 'REF';
75 print $ph 'Return: ', (join ' | ', @scalars), "\n", d @refs;
80 help_text => 'PERL [-o] <perlexp>, evalute the expression with Perl'
83 hook_command 'URIESCAPE', sub {
84 return EAT_ALL unless defined $_[0][1];
85 my ($uri, $out, $protect);
86 if ($_[0][1] eq '-o') {
89 } elsif ($_[0][1] eq '-p') {
95 $uri = encode get_info('charset'), $uri;
96 $uri =~ s/([^A-Za-z0-9\-_.!~*'():\/])/sprintf("%%%02X",ord($1))/ge;
98 command 'SAY ' . $uri;
100 $uri =~ s/%/%%/g if $protect;
101 print $ph $uri, "\n";
105 help_text => 'URIESCAPE [-o|-p] <uri>, escape unsafe characters in the URI'
108 hook_command 'WIDE', sub {
110 return EAT_ALL unless defined $txt;
111 $txt =~ s/([\x21-\x7e])/chr 0xfee0 + ord $1/ge;
112 command 'SAY ' . $txt;
115 help_text => 'WIDE <text>, say text in wide unicode characters'
118 hook_command 'HGREP', sub {
120 return EAT_ALL unless defined $txt;
123 for (get_list 'users') {
124 my $host = strip_code $_->{host};
125 next unless $host =~ /$txt/;
126 push @matches, [ $_->{nick}, $host ];
129 print $ph ($nbr == 0 ? 'No' : $nbr)
130 . ' match' . ('es' x ($nbr > 1))
132 if (@matches < MAX_MATCHES) {
133 print $ph +(':' x ($nbr > 0)) . "\n";
134 print $ph "\002$_->[0]\002 ($_->[1])\n" for @matches;
136 print $ph " (too many of them, omitted)\n";
140 help_text => 'HGREP <text>, print users in the current context whose hostname matches text'
143 $ph = Xchat::XPI->new(
144 name => 'Misc tools',
146 desc => 'Perl interpretor, URI escaper',
147 author => 'Vincent Pit (VPIT)',
148 email => 'perl@profvince.com',
149 url => 'http://www.profvince.com',