X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?p=bin.git;a=blobdiff_plain;f=irccat;h=3c927778580db679dfc74f4372693f6bb61e3c42;hp=5febfb0bbcf50ef49c7e330d1c331d0b089b175f;hb=0b942b568b5b6609aaa2ee4145d5633e662c91ea;hpb=88c7e302a60194f68bc1b6d20c1547b62e1436d3 diff --git a/irccat b/irccat old mode 100644 new mode 100755 index 5febfb0..3c92777 --- a/irccat +++ b/irccat @@ -20,6 +20,7 @@ Available commands (with arguments) are: who #channel List the visible users on a channel. whois username ... Query information about particular users. + list List channels. EOF exit 1; @@ -37,32 +38,47 @@ GetOptions(\%options, ); usage if $options{help}; +unless (defined $options{nick}) { + print STDERR "No nickname set; use --nick or IRCNICK.\n\n"; + usage; +} +unless (defined $options{server}) { + print STDERR "No server set; use --server or IRCSERVER.\n\n"; + usage; +} my $command = shift or usage; $command = lc $command; +my $irc = new Net::IRC; + +# TODO +my $conn = $irc->newconn(Nick => $options{nick}, Server => $options{server}) + or die "$0: can't connect to IRC server"; + if ($command eq 'who') { scalar @ARGV == 1 or usage; + $conn->add_handler('376', sub { + my $self = shift; + $self->who($ARGV[1]); + }); } elsif ($command eq 'whois') { scalar @ARGV > 0 or usage; } -else +elsif ($command eq 'list') { - usage; + scalar @ARGV == 0 or usage; + $conn->add_handler('376', sub { + my $self = shift; + $self->list('-yes'); + }); } - -my $irc = new Net::IRC; - -my $conn = $irc->newconn(Nick => $mynick, Server => $server) - or die "$0: can't connect to IRC server"; - -sub on_connect +else { - my $self = shift; - $self->who($targetchannel); + usage; } sub on_whoreply @@ -80,8 +96,14 @@ sub on_endofwho exit; } -$conn->add_handler('376', \&on_connect); +sub on_list +{ + my ($self, $event) = @_; + print $event->args, "\n"; +} + $conn->add_handler('352', \&on_whoreply); $conn->add_handler('315', \&on_endofwho); +$conn->add_handler('322', \&on_list); $irc->start;