Skip to content

Commit

Permalink
post to twitter native proc
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaddeus Wooster committed May 21, 2012
1 parent 4110b64 commit ff4b347
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions lib/Shittybot/TCL/Trait/Twitter.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package Shittybot::TCL::Trait::Twitter;

use Moose::Role;

use AnyEvent::Twitter;

has 'twitter_client' => (
is => 'ro',
isa => 'AnyEvent::Twitter',
lazy_build => 1,
);

sub _build_twitter_client {
my ($self) = @_;

my $config = $self->irc->config->{twitter}
or die "Trying to use Twitter trait but twitter config is missing";

my $client = AnyEvent::Twitter->new(%$config);

$client->get('account/verify_credentials', sub {
my ($header, $response, $reason) = @_;

print "Authenticated to twitter as $response->{screen_name}\n";
});

return $client;
}

sub BUILD{}; after 'BUILD' => sub {
my ($self) = @_;

$self->register_callbacks(
post_twat => \&post_to_twitter,
);
};

sub post_to_twitter {
my ($self, $nick, $mask, $handle, $channel, $proc, $args, $loglines) = @_;

my $twit = $self->twitter_client;

warn "$nick posting to twitter: '$args'\n";

$twit->post('statuses/update', {
status => $args,
}, sub {
my ($header, $response, $reason) = @_;
$self->irc->send_to_channel($channel, "posted to twitter: $response/$reason");
});
}

1;

0 comments on commit ff4b347

Please sign in to comment.