Created
December 6, 2010 03:07
-
-
Save aero/729778 to your computer and use it in GitHub Desktop.
twit2irc.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Usage: twit2irc.pl irc.example.com 6667 nickname '#channel1' '#channel2' '#channel3' | |
use strict; | |
use warnings; | |
use Encode qw/encode decode/; | |
use URI::Escape; | |
use utf8; | |
use String::IRC; | |
use AnyEvent::IRC::Client; | |
#use AnyEvent::Socket; | |
#use AnyEvent::Handle; | |
use AnyEvent::Twitter::Stream; | |
my($server, $port, $nick, @channels) = @ARGV; | |
warn join ', ', @channels; | |
my $c = AE::cv; | |
my $con = AnyEvent::IRC::Client->new; | |
$con->reg_cb (connect => sub { | |
my ($con, $err) = @_; | |
if (defined $err) { | |
warn "connect error: $err\n"; | |
return; | |
} | |
}); | |
$con->reg_cb (registered => sub { print "I'm in!\n"; }); | |
$con->reg_cb (disconnect => sub { print "I'm out!\n"; $c->broadcast }); | |
warn "$server, $port"; | |
$con->connect ($server, $port, { nick => $nick }); | |
warn "join channel; $_" for @channels; | |
$con->send_srv( JOIN => $_ ) for @channels; | |
my $guard = AnyEvent::Twitter::Stream->new( | |
username => 'id', | |
password => 'passwd', | |
method => 'filter', | |
track => 'perl,#perl', | |
on_tweet => sub { | |
my $tweet = shift; | |
my $msg = encode('utf8', String::IRC->new($tweet->{user}{screen_name})->bold ." | |
". String::IRC->new($tweet->{text})->purple ); | |
print "$msg\n"; | |
$con->send_chan( $_, "PRIVMSG", $_, $msg ) for @channels; | |
}, | |
on_error => sub { | |
my $error = shift; | |
warn "ERROR: $error"; | |
$c->send; | |
}, | |
on_eof => sub { | |
$c->send; | |
}, | |
); | |
$c->recv; | |
#$con->disconnect; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment