- Timestamp:
- Jul 22, 2009, 8:39:21 PM (15 years ago)
- Branches:
- master, release-1.10, release-1.7, release-1.8, release-1.9
- Children:
- a8a0b0a
- Parents:
- 1c45137
- Location:
- lib/BarnOwl/Module
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/BarnOwl/Module/Twitter.pm
r1c45137 refcd223 18 18 use Net::Twitter; 19 19 use JSON; 20 use List::Util qw(first); 20 21 21 22 use BarnOwl; … … 123 124 } 124 125 push @twitter_handles, $twitter_handle; 125 $default_handle = $twitter_handle if (!defined $twitter_handle && exists $cfg->{default_sender} && $cfg->{default_sender}); 126 } 127 128 $default_handle = first {$_->{cfg}->{default_sender}} @twitter_handles; 129 if (!$default_handle && @twitter_handles) { 130 $default_handle = $twitter_handles[0]; 126 131 } 127 132 … … 141 146 && $m->auth eq 'YES') { 142 147 for my $handle (@twitter_handles) { 143 $handle->twitter($m->body) if (!exists $handle->{cfg}->{publish_tweets} || $handle->{cfg}->{publish_tweets});148 $handle->twitter($m->body) if $handle->{cfg}->{publish_tweets}; 144 149 } 145 150 } … … 152 157 $next_service_to_poll = ($next_service_to_poll + 1) % scalar(@twitter_handles); 153 158 154 $handle->poll_twitter() if (!exists $handle->{cfg}->{poll_for_tweets} || $handle->{cfg}->{poll_for_tweets}); 155 $handle->poll_direct() if (!exists $handle->{cfg}->{poll_for_dms} || $handle->{cfg}->{poll_for_dms}); 159 $handle->poll_twitter() if $handle->{cfg}->{poll_for_tweets}; 160 $handle->poll_direct() if $handle->{cfg}->{poll_for_dms}; 161 } 162 163 sub find_account { 164 my $name = shift; 165 my $handle = first {$_->{cfg}->{account_nickname} eq $name} @twitter_handles; 166 if ($handle) { 167 return $handle; 168 } else { 169 die("No such Twitter account: $name\n"); 170 } 156 171 } 157 172 … … 161 176 my $sent = 0; 162 177 if (defined $account) { 163 for my $handle (@twitter_handles) { 164 if (defined $handle->{cfg}->{account_nickname} && $account eq $handle->{cfg}->{account_nickname}) { 165 $handle->twitter(@_); 166 $sent = 1; 167 last; 168 } 169 } 170 BarnOwl::message("No Twitter account named " . $account) unless $sent == 1 178 my $handle = find_account($account); 179 $handle->twitter(@_); 171 180 } 172 181 else { 173 182 # broadcast 174 183 for my $handle (@twitter_handles) { 175 $handle->twitter(@_) if (!exists $handle->{cfg}->{publish_tweets} || $handle->{cfg}->{publish_tweets});184 $handle->twitter(@_) if $handle->{cfg}->{publish_tweets}; 176 185 } 177 186 } … … 183 192 my $sent = 0; 184 193 if (defined $account) { 185 for my $handle (@twitter_handles) { 186 if (defined $handle->{cfg}->{account_nickname} && $account eq $handle->{cfg}->{account_nickname}) { 187 $handle->twitter_direct(@_); 188 $sent = 1; 189 last; 190 } 191 } 192 BarnOwl::message("No Twitter account named " . $account) unless $sent == 1 193 } 194 elsif (defined $default_handle) { 194 my $handle = find_account($account); 195 $handle->twitter_direct(@_); 196 } elsif (defined $default_handle) { 195 197 $default_handle->twitter_direct(@_); 196 198 } … … 205 207 my $sent = 0; 206 208 if (defined $account) { 207 for my $handle (@twitter_handles) { 208 if (defined $handle->{cfg}->{account_nickname} && $account eq $handle->{cfg}->{account_nickname}) { 209 $handle->twitter_atreply(@_); 210 $sent = 1; 211 last; 212 } 213 } 214 BarnOwl::message("No Twitter account named " . $account) unless $sent == 1 209 my $handle = find_account($account); 210 $handle->twitter_atreply(@_); 215 211 } 216 212 elsif (defined $default_handle) { -
lib/BarnOwl/Module/Twitter/Handle.pm
r82fd1e6 refcd223 34 34 35 35 sub new { 36 37 36 my $class = shift; 38 37 my $cfg = shift; 39 38 39 $cfg = { 40 account_nickname => '', 41 default_sender => 0, 42 poll_for_tweets => 1, 43 poll_for_dms => 1, 44 publish_tweets => 1, 45 %$cfg 46 }; 47 40 48 my $self = { 41 'user' => undef,42 49 'cfg' => $cfg, 43 50 'twitter' => undef,
Note: See TracChangeset
for help on using the changeset viewer.