Created
January 4, 2010 05:20
-
-
Save JEEN/268317 to your computer and use it in GitHub Desktop.
This file contains hidden or 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' | |
# made by Anti-Mac a.k.a @aer0 | |
use strict; | |
use warnings; | |
use Encode qw/encode decode/; | |
use String::IRC; | |
use AnyEvent::IRC::Client; | |
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 => 'Your Twitter USERNAME', | |
password => 'Your Twitter Password', | |
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