Skip to content

Instantly share code, notes, and snippets.

@yusukebe
Created September 9, 2009 16:40
Show Gist options
  • Select an option

  • Save yusukebe/183865 to your computer and use it in GitHub Desktop.

Select an option

Save yusukebe/183865 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use AnyEvent::IRC::Client;
use AnyEvent::Twitter::Stream;
use Encode;
my $user = 'yourname';
my $password = 'password';
my $channel = '#yapc.asia-ja';
my $cv = AnyEvent->condvar;
my $pc = AnyEvent::IRC::Client->new;
$pc->reg_cb(
connect => sub {
my ( $pc, $err ) = @_;
if ( defined $err ) {
print "Couldn't connect to server: $err\n";
}
},
registered => sub {
my ($self) = @_;
print "registered!\n";
$pc->enable_ping(60);
},
disconnect => sub {
print "disconnected: $_[1]!\n";
}
);
$pc->send_srv( "JOIN", $channel );
$pc->send_chan( $channel, "NOTICE", $channel, "hi" );
$pc->connect( "irc.freenode.net", 6667,
{ nick => 'twitter_bot', user => 'twitter_bot', real => 'twitter_bot' } );
my $streamer = AnyEvent::Twitter::Stream->new(
username => $user,
password => $password,
method => 'filter',
track => '#yapcasia2009,#yapc',
on_tweet => sub {
my $tweet = shift;
$pc->send_chan( $channel, "NOTICE", $channel,
encode( 'utf8', "$tweet->{user}{screen_name}: $tweet->{text}" ) );
},
on_error => sub {
my $error = shift;
warn "ERROR: $error";
$cv->send;
},
on_eof => sub {
$cv->send;
},
);
$cv->recv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment