Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use AnyEvent::IRC::Client;
- use AnyEvent::Twitter::Stream;
- use Net::Twitter::Lite;
- use Getopt::Long;
- use Encode;
- my $usage = <<EOF;
- anyevent-irc-bot.pl
- options:
- --username user name
- --password password
- --channel join channel
- EOF
- GetOptions(
- "username=s" => \my $user,
- "password=s" => \my $password,
- "channel=s" => \my $channel,
- );
- die $usage unless $user;
- die $usage unless $password;
- die $usage unless $channel;
- my $owner_id = '11902602';
- my $nt = Net::Twitter::Lite->new(
- username => $user,
- password => $password
- );
- 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 i import twitter" );
- $pc->connect( "irc.freenode.net", 6667,
- { nick => 'tw', user => 'tw', real => 'tw' } );
- my $following_ids = $nt->followers_ids;
- push @{ $following_ids }, $owner_id;
- my $streamer = AnyEvent::Twitter::Stream->new(
- username => $user,
- password => $password,
- method => 'filter',
- follow => join(",", @{ $following_ids }),
- on_tweet => sub {
- my $tweet = shift;
- $pc->send_chan( $channel, "PRIVMSG", $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;
Add Comment
Please, Sign In to add comment