Bot-BasicBot-Pluggable-Module-TwitterFriendsStatus
view release on metacpan or search on metacpan
lib/Bot/BasicBot/Pluggable/Module/TwitterFriendsStatus.pm view on Meta::CPAN
use base 'Bot::BasicBot::Pluggable::Module';
our $VERSION = 0.2;
use constant {
CREDENTIALS => {
'netloc' => 'twitter.com:80',
'realm' => 'Twitter API',
},
URL => {
'verify_credentials' => 'http://twitter.com/account/verify_credentials.xml',
'friends_status' => 'http://twitter.com/statuses/friends_timeline.xml',
'friend_add' => [ 'http://twitter.com/friendships/create/', '.xml' ],
'friend_remove' => [ 'http://twitter.com/friendships/destroy/', '.xml' ],
},
TICK_INTERVAL => 60,
};
my $tick_counter = TICK_INTERVAL;
my $ua = LWP::UserAgent->new(
lib/Bot/BasicBot/Pluggable/Module/TwitterFriendsStatus.pm view on Meta::CPAN
);
}
sub init {
my ($self) = @_;
my ( $username, $password ) = ( $self->get('username'), $self->get('password') );
if ( $username and $password ) {
print "Twitter authentication previously successful. Using auth for $username\n";
$ua->credentials(
CREDENTIALS->{'netloc'},
CREDENTIALS->{'realm'},
$username,
$password,
);
}
_twitter_friends_status( $self, 0 );
}
sub said {
my ( $self, $message, $priority ) = @_;
return unless ( $priority == 2 );
if (my($user,$pass) = $message->{'body'} =~ /^\s*!\s*twitter\s*auth\s*(\S+)\s+(\S+)/ ) {
$ua->credentials( CREDENTIALS->{'netloc'}, CREDENTIALS->{'realm'}, $user, $pass );
my $response = $ua->get( URL->{'verify_credentials'} );
my $credentials = XMLin($response->content());
use Data::Dumper;
warn Dumper($credentials);
if ( $credentials->{name} eq $user) {
$self->reply(
$message,
"You have properly authenticated to Twitter as $user\n" .
"This authentication will be saved in the bot memory storage.\n" .
"$user has $credentials->{followers_count} followers and" .
"follows $credentials->{friends_count} users.\n"
);
$self->set( 'username' => $1 );
$self->set( 'password' => $2 );
}
else {
$self->reply(
$message,
"You have failed to properly authenticate with Twitter as $user",
);
$self->set( 'username' => '' );
( run in 0.259 second using v1.01-cache-2.11-cpan-4d50c553e7e )