2 # This is a simple script that connects stdin/stdout with a client
3 # connection to an irc server. the command line arguments are:
5 # $ ./debug_console <nick> <server> <port>
10 use AnyEvent::IRC::Client;
11 use AnyEvent::IRC::Util qw/mk_msg parse_irc_msg encode_ctcp/;
13 use Data::Dump qw(dump);
15 my $nick = $ENV{IRC_NICK} || die "IRC_NICK";
17 my $pub = AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT} );
18 my $sub = AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT} );
20 my $c = AnyEvent->condvar;
21 my $stdout = AnyEvent::Handle->new (fh => \*STDOUT);
22 my $con = new AnyEvent::IRC::Client;
29 warn "Couldn't connect: $err\n";
32 $stdout->push_write ("Connected!\n");
35 $con->register ($nick, $nick, $nick);
41 . mk_msg ($msg->{prefix}, $msg->{command}, @{$msg->{params}})
45 if ( $msg->{command} eq 'PRIVMSG' ) {
46 my $channel = join(' ', 'channel', $msg->{params}->[0], $msg->{prefix});
47 $pub->publish( $channel, $msg->{params}->[1] );
53 "> " . mk_msg (undef, @msg) . "\n"
61 $stdin = AnyEvent::Handle->new (
64 warn "EOF on STDIN, disconnecting...\n";
65 $con->disconnect ("Console EOF");
68 warn "Error on STDIN: $!\n";
71 $stdin->push_read (line => sub {
72 my ($stdin, $line) = @_;
77 warn "eval error: $@\n";
79 $Data::Dumper::Terse = 1;
80 $stdout->push_write ("result: " . dump($r));
83 my $msg = parse_irc_msg ($line);
84 $con->send_msg ($msg->{command}, @{$msg->{params}});
91 warn "disconnect: $_[1]!\n";
96 $con->ctcp_auto_reply('VERSION', ['VERSION', 'MQR-IRC:0.1:Perl']);
98 $con->connect ($ENV{IRC_SERVER}, $ENV{IRC_PORT} || 6667);