chiark / gitweb /
add mdcommit and gnucommit, hacky variants of debcommit for other projects
[bin.git] / irccat
1 #! /usr/bin/perl -w
2 use strict;
3
4 use Getopt::Long;
5 use Net::IRC;
6
7 sub usage ()
8 {
9         print <<"EOF";
10 Usage: $0 [options] command [arguments]
11 EOF
12         print <<'EOF';
13
14 Options are as follows, with defaults in brackets:
15
16   -n, --nick=[$IRCNICK]         IRC nickname.
17   -s, --server=[$IRCSERVER]     IRC server.
18
19 Available commands (with arguments) are:
20
21   who #channel                  List the visible users on a channel.
22   whois username ...            Query information about particular users.
23
24 EOF
25         exit 1;
26 }
27
28 my %options = (
29     nick    => $ENV{IRCNICK},
30     server  => $ENV{IRCSERVER},
31 );
32
33 GetOptions(\%options,
34     'help|h|?',
35     'nick|n=s',
36     'server|s=s',
37 );
38
39 usage if $options{help};
40
41 my $command = shift or usage;
42 $command = lc $command;
43
44 if ($command eq 'who')
45 {
46     scalar @ARGV == 1 or usage;
47 }
48 elsif ($command eq 'whois')
49 {
50     scalar @ARGV > 0 or usage;
51 }
52 else
53 {
54     usage;
55 }
56
57 my $irc = new Net::IRC;
58
59 my $conn = $irc->newconn(Nick => $mynick, Server => $server)
60         or die "$0: can't connect to IRC server";
61
62 sub on_connect
63 {
64         my $self = shift;
65         $self->who($targetchannel);
66 }
67
68 sub on_whoreply
69 {
70         my ($self, $event) = @_;
71         my ($me, $channel, $user, $host,
72                 $server, $nick, $status, $realname) = $event->args;
73         printf "\%-12s  \%s\n", $nick, $realname;
74 }
75
76 sub on_endofwho
77 {
78         my $self = shift;
79         $self->quit;
80         exit;
81 }
82
83 $conn->add_handler('376', \&on_connect);
84 $conn->add_handler('352', \&on_whoreply);
85 $conn->add_handler('315', \&on_endofwho);
86
87 $irc->start;