| 1 | package App::Twirc::Plugin::SecondaryAccount; | ||
| 2 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use Net::Twitter; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use POE::Component::Server::Twirc; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 5 | |||
| 6 | has net_twitter_options => ( isa => 'HashRef', is => 'ro', default => sub { {} } ); | ||
| 7 | has username => ( isa => 'Str', is => 'ro', required => 1 ); | ||
| 8 | has password => ( isa => 'Str', is => 'ro', required => 1 ); | ||
| 9 | has option => ( isa => 'Str', is => 'ro' ); | ||
| 10 | has _twitter => ( isa => 'Net::Twitter', is => 'rw' ); | ||
| 11 | has _option_regex => ( isa => 'Maybe[RegexpRef]', is => 'rw', default => undef ); | ||
| 12 | has _useragent_class => ( isa => 'Str', is => 'ro', default => 'LWP::UserAgent::POE' ); | ||
| 13 | |||
| 14 | sub BUILD { | ||
| 15 | my $self = shift; | ||
| 16 | |||
| 17 | $self->_twitter(Net::Twitter->new( | ||
| 18 | username => $self->username, | ||
| 19 | password => $self->password, | ||
| 20 | source => 'twircgw', | ||
| 21 | useragent => 'twirc/' . POE::Component::Server::Twirc->VERSION, | ||
| 22 | useragent_class => $self->_useragent_class, | ||
| 23 | %{$self->net_twitter_options}, | ||
| 24 | )); | ||
| 25 | |||
| 26 | if ( $self->option ) { | ||
| 27 | my $option = quotemeta $self->option; | ||
| 28 | $self->_option_regex(qr/^-$option(only)?\s+/); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | sub cmd_post { | ||
| 33 | my ($self, $server, $channel, $nick, $textref) = @_; | ||
| 34 | |||
| 35 | my $only; | ||
| 36 | if ( my $option_regex = $self->_option_regex ) { | ||
| 37 | $$textref =~ s/$option_regex// || return; | ||
| 38 | $only = $1; | ||
| 39 | } | ||
| 40 | |||
| 41 | $self->_twitter->update($$textref); | ||
| 42 | return $only; # return a true value to stop the processing chain | ||
| 43 | } | ||
| 44 | |||
| 45 | no Moose; | ||
| 46 | |||
| 47 | __PACKAGE__->meta->make_immutable; | ||
| 48 | |||
| 49 | 1; | ||
| 50 | |||
| 51 | __END__ | ||
| 52 | |||
| 53 | =head1 NAME | ||
| 54 | |||
| 55 | App::Twirc::Plugin::SecondaryAccount - Cross post updates to another account | ||
| 56 | |||
| 57 | =head1 SYNOPSIS | ||
| 58 | |||
| 59 | # in config (.yml in this example) | ||
| 60 | plugins: | ||
| 61 | - SecondaryAccount | ||
| 62 | username: my_other_screen_name | ||
| 63 | password: my_other_twitter_password | ||
| 64 | option: fb | ||
| 65 | - SecondaryAccount | ||
| 66 | username: yet_another_screen_name | ||
| 67 | password: yet_another_password | ||
| 68 | net_twitter_options: | ||
| 69 | apiurl: http://identi.ca/api | ||
| 70 | |||
| 71 | # In your IRC client... | ||
| 72 | # ...post to your primary account *and* yet_another_screen_name | ||
| 73 | post Hello, world! | ||
| 74 | |||
| 75 | # ...post to your primary account and both secondary accounts | ||
| 76 | post -fb Hello, universe! | ||
| 77 | |||
| 78 | # ... post to my_other_screen name, only | ||
| 79 | post -fbonly Hello, alternate reality. | ||
| 80 | |||
| 81 | =head1 DESCRIPTION | ||
| 82 | |||
| 83 | This plugin allows cross-posting messages to multiple accounts. In | ||
| 84 | configuration, you can provide an C<option> value. When used as an option to | ||
| 85 | C<post>, your message will be cross-posted to your primary account and the | ||
| 86 | secondary account with that C<option> value. If you do not provide an | ||
| 87 | C<option> value, all messages are cross-posted to the secondary account. | ||
| 88 | |||
| 89 | By appending C<only> to the C<option> value, your status will only be posted to | ||
| 90 | the the account with that C<option> value. | ||
| 91 | |||
| 92 | I use a configuration similar to the one in the synopsis to cross-post my | ||
| 93 | Twitter status updates to Identi.ca, and optionally to Facebook. My Twitter | ||
| 94 | screen name is C<semifor>. I created an account with screen name C<semifor_fb> | ||
| 95 | and registered it with Twitter's Facebook application. In the C<twirc> | ||
| 96 | configuration file, I assigned C<option> value C<fb> to the account. | ||
| 97 | |||
| 98 | I created another secondary account with my Identi.ca screen name. In C<twirc> | ||
| 99 | configuration, I used the C<net_twitter_options> to specify Identi.ca's | ||
| 100 | C<apiurl>. | ||
| 101 | |||
| 102 | Now, when I post a normal status update, it is posted to C<semifor> on both | ||
| 103 | Twitter and Identi.ca. If I include a C<-fb> option to post, my status update | ||
| 104 | is posted to Twitter, Identi.ca, and Facebook. If I add a C<-fbonly> option to | ||
| 105 | C<post>, my status update is only posted to the Facebook account. | ||
| 106 | |||
| 107 | =head1 AUTHOR | ||
| 108 | |||
| 109 | Marc Mims <marc@questright.com> | ||
| 110 | |||
| 111 | =head1 LICENSE | ||
| 112 | |||
| 113 | Copyright (c) 2009 Marc Mims | ||
| 114 | |||
| 115 | You may distribute this code and/or modify it under the same terms as Perl itself. | ||
| 116 | |||
| 117 | =cut | ||