Changeset 8618438 for lib/BarnOwl
- Timestamp:
- Nov 28, 2008, 12:29:38 PM (16 years ago)
- Branches:
- master, release-1.10, release-1.7, release-1.8, release-1.9
- Children:
- affa874
- Parents:
- 104f7d9
- Location:
- lib/BarnOwl
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/BarnOwl/Module/Twitter.pm
r104f7d9 r8618438 19 19 use BarnOwl; 20 20 use BarnOwl::Hooks; 21 use BarnOwl::Message::Twitter; 22 use HTML::Entities; 21 23 22 24 my $twitter; … … 102 104 } 103 105 106 my $last_poll = 0; 107 my $last_id = undef; 108 unless(defined($last_id)) { 109 $last_id = $twitter->friends_timeline({count => 1})->[0]{id}; 110 } 111 112 sub poll_messages { 113 return unless ( time - $last_poll ) >= 45; 114 $last_poll = time; 115 my $timeline = $twitter->friends_timeline( { since_id => $last_id } ); 116 unless(defined($timeline)) { 117 BarnOwl::error("Twitter returned error ... rate-limited?"); 118 # Sleep for 15 minutes 119 $last_poll = time + 60*15; 120 return; 121 }; 122 if ( scalar @$timeline ) { 123 for my $tweet ( reverse @$timeline ) { 124 if ( $tweet->{id} <= $last_id ) { 125 next; 126 } 127 my $msg = BarnOwl::Message->new( 128 type => 'Twitter', 129 sender => $tweet->{user}{screen_name}, 130 recipient => $cfg->{user} || $user, 131 direction => 'in', 132 source => decode_entities($tweet->{source}), 133 location => decode_entities($tweet->{user}{location}), 134 body => decode_entities($tweet->{text}) 135 ); 136 BarnOwl::queue_message($msg); 137 } 138 $last_id = $timeline->[0]{id}; 139 } else { 140 # BarnOwl::message("No new tweets..."); 141 } 142 } 143 104 144 sub twitter { 105 145 my $msg = shift; … … 128 168 eval { 129 169 $BarnOwl::Hooks::receiveMessage->add("BarnOwl::Module::Twitter::handle_message"); 170 $BarnOwl::Hooks::mainLoop->add("BarnOwl::Module::Twitter::poll_messages"); 130 171 }; 131 172 if($@) { 132 173 $BarnOwl::Hooks::receiveMessage->add(\&handle_message); 174 $BarnOwl::Hooks::mainLoop->add(\&poll_messages); 133 175 } 134 176 177 BarnOwl::command(qw(filter twitter type ^twitter$)); 178 135 179 1;
Note: See TracChangeset
for help on using the changeset viewer.