10 use POSIX qw/:sys_wait_h/;
11 use Net::Twitter qw/3.05/;
12 $Data::Dumper::Indent = 1;
14 use vars qw($VERSION %IRSSI);
16 $VERSION = "2.4.1beta";
18 authors => 'Dan Boger',
19 contact => 'zigdon@gmail.com',
21 description => 'Send twitter updates using /tweet. '
22 . 'Can optionally set your bitlbee /away message to same',
23 license => 'GNU GPL v2',
24 url => 'http://twirssi.com',
25 changed => 'Fri Jan 22 14:40:48 PST 2010',
36 my $last_friends_poll = 0;
44 my %fix_replies_index;
46 my %irssi_to_mirc_colors = (
66 my ( $data, $server, $win ) = @_;
68 return unless &logged_in($twit);
70 my ( $target, $text ) = split ' ', $data, 2;
71 unless ( $target and $text ) {
72 ¬ice("Usage: /dm <nick> <message>");
76 &cmd_direct_as( "$user $data", $server, $win );
80 my ( $data, $server, $win ) = @_;
82 return unless &logged_in($twit);
84 my ( $username, $target, $text ) = split ' ', $data, 3;
85 unless ( $username and $target and $text ) {
86 ¬ice("Usage: /dm_as <username> <nick> <message>");
90 return unless $username = &valid_username($username);
93 if ( $twits{$username}
94 ->new_direct_message( { user => $target, text => $text } ) )
96 ¬ice("DM sent to $target: $text");
97 $nicks{$target} = time;
101 $error = JSON::Any->jsonToObj( $twits{$username}->get_error() );
102 $error = $error->{error};
104 die $error if $error;
105 ¬ice("DM to $target failed");
110 ¬ice("DM caused an error: $@");
116 my ( $data, $server, $win ) = @_;
118 return unless &logged_in($twit);
120 $data =~ s/^\s+|\s+$//;
122 ¬ice("Usage: /retweet <nick[:num]> [comment]");
126 my ( $id, $data ) = split ' ', $data, 2;
128 &cmd_retweet_as( "$user $id $data", $server, $win );
132 my ( $data, $server, $win ) = @_;
134 unless ( Irssi::settings_get_bool("twirssi_track_replies") ) {
135 ¬ice("twirssi_track_replies is required in order to reteet.");
139 return unless &logged_in($twit);
141 $data =~ s/^\s+|\s+$//;
142 my ( $username, $id, $data ) = split ' ', $data, 3;
145 ¬ice("Usage: /retweet_as <username> <nick[:num]> [comment]");
149 return unless $username = &valid_username($username);
152 $id =~ s/[^\w\d\-:]+//g;
153 ( $nick, $id ) = split /:/, $id;
154 unless ( exists $id_map{ lc $nick } ) {
155 ¬ice("Can't find a tweet from $nick to retweet!");
159 $id = $id_map{__indexes}{$nick} unless $id;
160 unless ( $id_map{ lc $nick }[$id] ) {
161 ¬ice("Can't find a tweet numbered $id from $nick to retweet!");
165 unless ( $id_map{__tweets}{ lc $nick }[$id] ) {
166 ¬ice("The text of this tweet isn't saved, sorry!");
170 # Irssi::settings_add_str( "twirssi", "twirssi_retweet_format", 'RT $n: $t ${-- $c$}' );
171 my $text = Irssi::settings_get_str("twirssi_retweet_format");
172 $text =~ s/\$n/\@$nick/g;
174 $text =~ s/\${|\$}//g;
175 $text =~ s/\$c/$data/;
177 $text =~ s/\${.*?\$}//;
179 $text =~ s/\$t/$id_map{__tweets}{ lc $nick }[$id]/;
181 my $modified = $data;
182 $data = &shorten($text);
184 return if $modified and &too_long($data);
190 $success = $twits{$username}->update(
194 # in_reply_to_status_id => $id_map{ lc $nick }[$id]
199 $twits{$username}->retweet( { id => $id_map{ lc $nick }[$id] } );
200 $success = $success->{id} if ref $success;
202 ¬ice("Update failed") unless $success;
204 return unless $success;
207 ¬ice("Update caused an error: $@. Aborted");
211 foreach ( $data =~ /@([-\w]+)/ ) {
215 ¬ice("Retweet sent");
219 my ( $data, $server, $win ) = @_;
221 return unless &logged_in($twit);
223 $data =~ s/^\s+|\s+$//;
225 ¬ice("Usage: /tweet <update>");
229 &cmd_tweet_as( "$user\@$defservice $data", $server, $win );
233 my ( $data, $server, $win ) = @_;
235 return unless &logged_in($twit);
237 $data =~ s/^\s+|\s+$//;
238 $data =~ s/\s\s+/ /g;
239 my ( $username, $data ) = split ' ', $data, 2;
241 unless ( $username and $data ) {
242 ¬ice("Usage: /tweet_as <username> <update>");
246 return unless $username = &valid_username($username);
248 $data = &shorten($data);
250 return if &too_long($data);
254 unless ( $twits{$username}->update($data) )
256 ¬ice("Update failed");
260 return unless $success;
263 ¬ice("Update caused an error: $@. Aborted.");
267 foreach ( $data =~ /@([-\w]+)/ ) {
271 my $away = &update_away($data);
273 ¬ice( "Update sent" . ( $away ? " (and away msg set)" : "" ) );
277 my ( $data, $server, $win ) = @_;
279 return unless &logged_in($twit);
281 $data =~ s/^\s+|\s+$//;
283 ¬ice("Usage: /reply <nick[:num]> <update>");
287 my ( $id, $data ) = split ' ', $data, 2;
288 unless ( $id and $data ) {
289 ¬ice("Usage: /reply <nick[:num]> <update>");
293 &cmd_reply_as( "$user $id $data", $server, $win );
297 my ( $data, $server, $win ) = @_;
299 unless ( Irssi::settings_get_bool("twirssi_track_replies") ) {
300 ¬ice("twirssi_track_replies is required in order to reply to "
301 . "specific tweets. Either enable it, or just use /tweet "
302 . "\@username <text>." );
306 return unless &logged_in($twit);
308 $data =~ s/^\s+|\s+$//;
309 my ( $username, $id, $data ) = split ' ', $data, 3;
311 unless ( $username and $data ) {
312 ¬ice("Usage: /reply_as <username> <nick[:num]> <update>");
316 return unless $username = &valid_username($username);
319 $id =~ s/[^\w\d\-:]+//g;
320 ( $nick, $id ) = split /:/, $id;
321 unless ( exists $id_map{ lc $nick } ) {
322 ¬ice("Can't find a tweet from $nick to reply to!");
326 $id = $id_map{__indexes}{$nick} unless $id;
327 unless ( $id_map{ lc $nick }[$id] ) {
328 ¬ice("Can't find a tweet numbered $id from $nick to reply to!");
332 if ( Irssi::settings_get_bool("twirssi_replies_autonick") ) {
334 # remove any @nick at the beginning of the reply, as we'll add it anyway
335 $data =~ s/^\s*\@?$nick\s*//;
336 $data = "\@$nick " . $data;
339 $data = &shorten($data);
341 return if &too_long($data);
346 $twits{$username}->update(
349 in_reply_to_status_id => $id_map{ lc $nick }[$id]
354 ¬ice("Update failed");
358 return unless $success;
361 ¬ice("Update caused an error: $@. Aborted");
365 foreach ( $data =~ /@([-\w]+)/ ) {
369 my $away = &update_away($data);
371 ¬ice( "Update sent" . ( $away ? " (and away msg set)" : "" ) );
375 my ( $usage_str, $api_name, $post_ref ) = @_;
378 my ( $data, $server, $win ) = @_;
380 return unless &logged_in($twit);
382 $data =~ s/^\s+|\s+$//;
384 ¬ice("Usage: $usage_str");
390 unless ( $twit->$api_name($data) )
392 ¬ice("$api_name failed");
396 return unless $success;
399 ¬ice("$api_name caused an error. Aborted.");
403 &$post_ref($data) if $post_ref;
408 my ( $data, $server, $win ) = @_;
410 $data =~ s/^\s+|\s+$//g;
411 $data = &normalize_username($data);
412 if ( exists $twits{$data} ) {
413 ¬ice("Switching to $data");
414 $twit = $twits{$data};
415 if ( $data =~ /(.*)\@(.*)/ ) {
419 ¬ice("Couldn't figure out what service '$data' is on");
422 ¬ice("Unknown user $data");
427 my ( $data, $server, $win ) = @_;
429 $data =~ s/^\s+|\s+$//g;
430 $data = $user unless $data;
431 return unless $data = &valid_username($data);
433 ¬ice("Logging out $data...");
435 $twits{$data}->end_session();
437 delete $twits{$data};
440 &cmd_switch( ( keys %twits )[0], $server, $win );
442 Irssi::timeout_remove($poll) if $poll;
448 my ( $data, $server, $win ) = @_;
450 print "logging in: $data" if &debug;
452 print "manual data login" if &debug;
453 ( $user, $pass ) = split ' ', $data, 2;
454 unless (Irssi::settings_get_bool("twirssi_use_oauth") or $pass) {
455 ¬ice("usage: /twitter_login <username>[\@<service>] <password>");
458 } elsif ( Irssi::settings_get_bool("twirssi_use_oauth") and
459 my $autouser = Irssi::settings_get_str("twitter_usernames") ) {
460 print "oauth autouser login" if &debug;
461 foreach my $user (split /,/, $autouser) {
465 } elsif ( my $autouser = Irssi::settings_get_str("twitter_usernames")
466 and my $autopass = Irssi::settings_get_str("twitter_passwords") )
468 print "autouser login" if &debug;
469 my @user = split /\s*,\s*/, $autouser;
470 my @pass = split /\s*,\s*/, $autopass;
472 # if a password ends with a '\', it was meant to escape the comma, and
473 # it should be concatinated with the next one
477 while ( $p =~ /\\$/ and @pass ) {
478 $p .= "," . shift @pass;
483 if ( @user != @unescaped ) {
484 ¬ice("Number of usernames doesn't match "
485 . "the number of passwords - auto-login failed" );
488 while ( @user and @unescaped ) {
490 $p = shift @unescaped;
496 ¬ice("/twitter_login requires either a username/password "
497 . "or twitter_usernames and twitter_passwords to be set. "
498 . "Note that if twirssi_use_oauth is true, passwords are "
503 %friends = %nicks = ();
506 if ( $user =~ /^(.*)@(twitter|identica)$/ ) {
507 ( $user, $service ) = ( $1, $2 );
509 $service = Irssi::settings_get_str("twirssi_default_service");
511 $defservice = $service = ucfirst lc $service;
513 if ( $service eq 'Twitter' and
514 Irssi::settings_get_bool("twirssi_use_oauth") ) {
515 print "Attempting OAuth for $user\@$service" if &debug;
517 $twit = Net::Twitter->new(
518 $service eq 'Identica' ? ( identica => 1 ) : (),
519 traits => [ 'API::REST', 'OAuth' ],
520 consumer_key => 'BZVAvBma4GxdiRwXIvbnw',
521 consumer_secret => '0T5kahwLyb34vciGZsgkA9lsjtGCQ05vxVE2APXM',
523 ssl => Irssi::settings_get_bool("twirssi_avoid_ssl") ? 0 : 1,
528 if (open( OAUTH, Irssi::settings_get_str("twirssi_oauth_store") ) ) {
531 next unless m/$user\@$service (\S+) (\S+)/i;
532 print "Trying cached oauth creds for $user\@$service" if &debug;
533 $twit->access_token($1);
534 $twit->access_token_secret($2);
540 unless ( $twit->authorized ) {
543 $url = $twit->get_authorization_url;
547 ¬ice("ERROR: Failed to get OAuth authorization_url. Try again later.");
551 ¬ice("Twirssi not autorized to access $service for $user.");
552 ¬ice("Please authorize at the following url, then enter the pin ");
553 ¬ice("supplied with /twirssi_oauth $user\@$service <pin>");
556 $oauth{pending}{"$user\@$service"} = $twit;
561 $twit = Net::Twitter->new(
562 $service eq 'Identica' ? ( identica => 1 ) : (),
566 ssl => Irssi::settings_get_bool("twirssi_avoid_ssl") ? 0 : 1,
571 ¬ice("Failed to create object! Aborting.");
575 return &verify_twitter_object($server, $win, $user, $service, $twit);
579 my ($data, $server, $win) = @_;
580 my ( $key, $pin ) = split ' ', $data;
581 my ($user, $service);
582 $key = &normalize_username($key);
583 if ( $key =~ /^(.*)@(Twitter|Identica)$/ ) {
584 ( $user, $service ) = ( $1, $2 );
587 print "Applying pin to $key" if &debug;
589 unless ( exists $oauth{pending}{$key} ) {
590 ¬ice("There isn't a pending oauth request for $key. "
591 . "Try /twitter_login first" );
595 my $twit = $oauth{pending}{$key};
596 my ( $access_token, $access_token_secret );
598 ( $access_token, $access_token_secret ) =
599 $twit->request_access_token( verifier => $pin );
603 ¬ice("Invalid pin, try again.");
607 delete $oauth{pending}{$key};
609 my $store_file = Irssi::settings_get_str("twirssi_oauth_store");
612 if ( open( OAUTH, $store_file ) ) {
622 push @store, "$key $access_token $access_token_secret";
624 if ( open( OAUTH, ">$store_file.new" ) ) {
625 print OAUTH "$_\n" foreach @store;
627 rename "$store_file.new", $store_file
628 or ¬ice("Failed to rename $store_file.new: $!");
630 ¬ice("Failed to write $store_file.new: $!");
633 ¬ice("No persistant storage set for OAuth. "
634 . "Please /set twirssi_oauth_store to a writable filename." );
637 return &verify_twitter_object($server, $win, $user, $service, $twit);
640 sub verify_twitter_object {
641 my ($server, $win, $user, $service, $twit) = @_;
643 if ( my $timeout = Irssi::settings_get_int("twitter_timeout")
644 and $twit->can('ua') )
646 $twit->ua->timeout($timeout);
647 ¬ice("Twitter timeout set to $timeout");
650 unless ( $twit->verify_credentials() ) {
651 ¬ice("Login as $user\@$service failed");
653 if ( not Irssi::settings_get_bool("twirssi_avoid_ssl") ) {
655 "It's possible you're missing one of the modules required for "
656 . "SSL logins. Try setting twirssi_avoid_ssl to on. See "
657 . "http://cpansearch.perl.org/src/GAAS/libwww-perl-5.831/README.SSL "
658 . "for the detailed requirements." );
663 &cmd_switch( ( keys %twits )[0], $server, $win );
668 my $rate_limit = $twit->rate_limit_status();
669 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
671 "Rate limit exceeded, try again after $rate_limit->{reset_time}" );
676 print "saving object for $user\@$service" if &debug;
677 $twits{"$user\@$service"} = $twit;
678 Irssi::timeout_remove($poll) if $poll;
679 $poll = Irssi::timeout_add( &get_poll_time * 1000, \&get_updates, "" );
680 ¬ice("Logged in as $user\@$service, loading friends list...");
682 ¬ice( "loaded friends: ", scalar keys %friends );
683 if ( Irssi::settings_get_bool("twirssi_first_run") ) {
684 Irssi::settings_set_bool( "twirssi_first_run", 0 );
692 my ( $data, $server, $win ) = @_;
695 ¬ice("Usage: /twitter_add_follow_extra <username>");
699 $data =~ s/^\s+|\s+$//;
703 if ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
704 ¬ice("Already following all replies by \@$data");
708 $id_map{__fixreplies}{"$user\@$defservice"}{$data} = 1;
709 ¬ice("Will now follow all replies by \@$data");
713 my ( $data, $server, $win ) = @_;
716 ¬ice("Usage: /twitter_del_follow_extra <username>");
720 $data =~ s/^\s+|\s+$//;
724 unless ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
725 ¬ice("Wasn't following all replies by \@$data");
729 delete $id_map{__fixreplies}{"$user\@$defservice"}{$data};
730 ¬ice("Will no longer follow all replies by \@$data");
733 sub cmd_list_follow {
734 my ( $data, $server, $win ) = @_;
737 foreach my $suser ( sort keys %{ $id_map{__fixreplies} } ) {
739 foreach my $fruser ( sort keys %{ $id_map{__fixreplies}{$suser} } ) {
740 $frusers = $frusers ? "$frusers, $fruser" : $fruser;
744 ¬ice("Following all replies as \@$suser: $frusers");
749 ¬ice("Not following all replies by anyone");
754 my ( $data, $server, $win ) = @_;
756 unless ( $twit and $twit->can('search') ) {
757 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
758 . "doesn't support searches." );
762 $data =~ s/^\s+|\s+$//;
766 ¬ice("Usage: /twitter_subscribe <topic>");
770 if ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
771 ¬ice("Already had a subscription for '$data'");
775 $id_map{__searches}{"$user\@$defservice"}{$data} = 1;
776 ¬ice("Added subscription for '$data'");
780 my ( $data, $server, $win ) = @_;
782 unless ( $twit and $twit->can('search') ) {
783 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
784 . "doesn't support searches." );
787 $data =~ s/^\s+|\s+$//;
791 ¬ice("Usage: /twitter_unsubscribe <topic>");
795 unless ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
796 ¬ice("No subscription found for '$data'");
800 delete $id_map{__searches}{"$user\@$defservice"}{$data};
801 ¬ice("Removed subscription for '$data'");
804 sub cmd_list_search {
805 my ( $data, $server, $win ) = @_;
808 foreach my $suser ( sort keys %{ $id_map{__searches} } ) {
810 foreach my $topic ( sort keys %{ $id_map{__searches}{$suser} } ) {
811 $topics = $topics ? "$topics, $topic" : $topic;
815 ¬ice("Search subscriptions for \@$suser: $topics");
820 ¬ice("No search subscriptions set up");
825 my ( $data, $server, $win ) = @_;
827 my $loc = Irssi::settings_get_str("twirssi_location");
829 ¬ice("$loc isn't writable, can't upgrade."
830 . " Perhaps you need to /set twirssi_location?" );
835 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
836 eval { use Digest::MD5; };
839 ¬ice("Failed to load Digest::MD5."
840 . " Try '/twirssi_upgrade nomd5' to skip MD5 verification" );
844 $md5 = get("http://twirssi.com/md5sum");
848 ¬ice("Failed to download md5sum from peeron! Aborting.");
852 unless ( open( CUR, $loc ) ) {
853 ¬ice("Failed to read $loc."
854 . " Check that /set twirssi_location is set to the correct location."
859 my $cur_md5 = Digest::MD5::md5_hex(<CUR>);
862 if ( $cur_md5 eq $md5 ) {
863 ¬ice("Current twirssi seems to be up to date.");
869 Irssi::settings_get_bool("twirssi_upgrade_beta")
870 ? "http://github.com/zigdon/twirssi/raw/master/twirssi.pl"
871 : "http://twirssi.com/twirssi.pl";
872 ¬ice("Downloading twirssi from $URL");
873 LWP::Simple::getstore( $URL, "$loc.upgrade" );
875 unless ( -s "$loc.upgrade" ) {
876 ¬ice("Failed to save $loc.upgrade."
877 . " Check that /set twirssi_location is set to the correct location."
882 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
883 unless ( open( NEW, "$loc.upgrade" ) ) {
884 ¬ice("Failed to read $loc.upgrade."
885 . " Check that /set twirssi_location is set to the correct location."
890 my $new_md5 = Digest::MD5::md5_hex(<NEW>);
893 if ( $new_md5 ne $md5 ) {
894 ¬ice("MD5 verification failed. expected $md5, got $new_md5");
899 rename $loc, "$loc.backup"
900 or ¬ice("Failed to back up $loc: $!. Aborting")
902 rename "$loc.upgrade", $loc
903 or ¬ice("Failed to rename $loc.upgrade: $!. Aborting")
906 my ( $dir, $file ) = ( $loc =~ m{(.*)/([^/]+)$} );
907 if ( -e "$dir/autorun/$file" ) {
908 ¬ice("Updating $dir/autorun/$file");
909 unlink "$dir/autorun/$file"
910 or ¬ice("Failed to remove old $file from autorun: $!");
911 symlink "../$file", "$dir/autorun/$file"
912 or ¬ice("Failed to create symlink in autorun directory: $!");
915 ¬ice("Download complete. Reload twirssi with /script load $file");
924 while ( $page < 11 and $cursor ne "0" )
926 print $fh "type:debug Loading friends page $page...\n"
927 if ( $fh and &debug );
929 if ( ref $twit =~ /^Net::Twitter/ ) {
930 $friends = $twit->friends( { cursor => $cursor } );
931 last unless $friends;
932 $cursor = $friends->{next_cursor};
933 $friends = $friends->{users};
935 $friends = $twit->friends( { page => $page } );
936 last unless $friends;
938 $new_friends{ $_->{screen_name} } = time foreach @$friends;
944 print $fh "type:debug Error during friends list update. Aborted.\n";
948 my ( $added, $removed ) = ( 0, 0 );
949 print $fh "type:debug Scanning for new friends...\n" if ( $fh and &debug );
950 foreach ( keys %new_friends ) {
951 next if exists $friends{$_};
956 print $fh "type:debug Scanning for removed friends...\n"
957 if ( $fh and &debug );
958 foreach ( keys %friends ) {
959 next if exists $new_friends{$_};
964 return ( $added, $removed );
968 print scalar localtime, " - get_updates starting" if &debug;
971 Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
974 ->print( "Can't find a window named '"
975 . Irssi::settings_get_str('twitter_window')
976 . "'. Create it or change the value of twitter_window" );
979 return unless &logged_in($twit);
981 my ( $fh, $filename ) = File::Temp::tempfile();
982 binmode( $fh, ":utf8" );
985 if ($child_pid) { # parent
986 Irssi::timeout_add_once( 5000, 'monitor_child',
987 [ "$filename.done", 0 ] );
988 Irssi::pidwait_add($child_pid);
989 } elsif ( defined $child_pid ) { # child
998 foreach ( keys %twits ) {
999 $error++ unless &do_updates( $fh, $_, $twits{$_}, \%context_cache );
1001 if ( $id_map{__fixreplies}{$_} ) {
1002 my @frusers = sort keys %{ $id_map{__fixreplies}{$_} };
1005 unless &get_timeline( $fh, $frusers[ $fix_replies_index{$_} ],
1006 $_, $twits{$_}, \%context_cache );
1008 $fix_replies_index{$_}++;
1009 $fix_replies_index{$_} = 0
1010 if $fix_replies_index{$_} >= @frusers;
1011 print $fh "id:$fix_replies_index{$_} ",
1012 "account:$_ type:fix_replies_index\n";
1016 print $fh "__friends__\n";
1018 time - $last_friends_poll >
1019 Irssi::settings_get_int('twitter_friends_poll') )
1021 print $fh "__updated ", time, "\n";
1022 my ( $added, $removed ) = &load_friends($fh);
1023 if ( $added + $removed ) {
1024 print $fh "type:debug %R***%n Friends list updated: ",
1026 sprintf( "%d added", $added ),
1027 sprintf( "%d removed", $removed ) ),
1032 foreach ( sort keys %friends ) {
1033 print $fh "$_ $friends{$_}\n";
1037 print $fh "type:debug Update encountered errors. Aborted\n";
1038 print $fh "-- $last_poll";
1040 print $fh "-- $new_poll";
1043 rename $filename, "$filename.done";
1046 &ccrap("Failed to fork for updating: $!");
1048 print scalar localtime, " - get_updates ends" if &debug;
1052 my ( $fh, $username, $obj, $cache ) = @_;
1055 my $rate_limit = $obj->rate_limit_status();
1056 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
1057 ¬ice("Rate limit exceeded for $username");
1062 print scalar localtime, " - Polling for updates for $username" if &debug;
1064 my $new_poll_id = 0;
1066 if ( $id_map{__last_id}{$username}{timeline} )
1068 $tweets = $obj->home_timeline( { count => 100 } );
1070 $tweets = $obj->home_timeline();
1075 print $fh "type:debug Error during home_timeline call: Aborted.\n";
1076 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1080 unless ( ref $tweets ) {
1081 if ( $obj->can("get_error") ) {
1082 my $error = "Unknown error";
1083 eval { $error = JSON::Any->jsonToObj( $obj->get_error() ) };
1084 unless ($@) { $error = $obj->get_error() }
1086 "type:debug API Error during home_timeline call: Aborted\n";
1087 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($error);
1091 "type:debug API Error during home_timeline call. Aborted.\n";
1096 foreach my $t ( reverse @$tweets ) {
1097 my $text = &get_text( $t, $obj );
1098 my $reply = "tweet";
1099 if ( Irssi::settings_get_bool("show_reply_context")
1100 and $t->{in_reply_to_screen_name} ne $username
1101 and $t->{in_reply_to_screen_name}
1102 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1104 $nicks{ $t->{in_reply_to_screen_name} } = time;
1106 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1108 $cache->{ $t->{in_reply_to_status_id} } =
1109 $obj->show_status( $t->{in_reply_to_status_id} );
1113 $context = $cache->{ $t->{in_reply_to_status_id} };
1116 my $ctext = &get_text( $context, $obj );
1117 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1118 $context->{id}, $username,
1119 $context->{user}{screen_name}, $ctext;
1124 if $t->{user}{screen_name} eq $username
1125 and not Irssi::settings_get_bool("show_own_tweets");
1126 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1127 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1128 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1130 printf $fh "id:%s account:%s type:last_id timeline\n",
1131 $new_poll_id, $username;
1133 print scalar localtime, " - Polling for replies since ",
1134 $id_map{__last_id}{$username}{reply}
1138 if ( $id_map{__last_id}{$username}{reply} )
1140 $tweets = $obj->replies(
1141 { since_id => $id_map{__last_id}{$username}{reply} } )
1144 $tweets = $obj->replies() || [];
1149 print $fh "type:debug Error during replies call. Aborted.\n";
1153 foreach my $t ( reverse @$tweets ) {
1155 if exists $friends{ $t->{user}{screen_name} };
1157 my $text = &get_text( $t, $obj );
1158 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1159 $t->{id}, $username, $t->{user}{screen_name}, $text;
1160 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1162 printf $fh "id:%s account:%s type:last_id reply\n", $new_poll_id, $username;
1164 print scalar localtime, " - Polling for DMs" if &debug;
1167 if ( $id_map{__last_id}{$username}{dm} )
1169 $tweets = $obj->direct_messages(
1170 { since_id => $id_map{__last_id}{$username}{dm} } )
1173 $tweets = $obj->direct_messages() || [];
1178 print $fh "type:debug Error during direct_messages call. Aborted.\n";
1182 foreach my $t ( reverse @$tweets ) {
1183 my $text = decode_entities( $t->{text} );
1184 $text =~ s/[\n\r]/ /g;
1185 printf $fh "id:%s account:%s nick:%s type:dm %s\n",
1186 $t->{id}, $username, $t->{sender_screen_name}, $text;
1187 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1189 printf $fh "id:%s account:%s type:last_id dm\n", $new_poll_id, $username;
1191 print scalar localtime, " - Polling for subscriptions" if &debug;
1192 if ( $obj->can('search') and $id_map{__searches}{$username} ) {
1194 foreach my $topic ( sort keys %{ $id_map{__searches}{$username} } ) {
1195 print $fh "type:debug searching for $topic since ",
1196 "$id_map{__searches}{$username}{$topic}\n";
1198 $search = $obj->search(
1201 since_id => $id_map{__searches}{$username}{$topic}
1208 "type:debug Error during search($topic) call. Aborted.\n";
1212 unless ( $search->{max_id} ) {
1213 print $fh "type:debug Invalid search results when searching",
1214 " for $topic. Aborted.\n";
1218 $id_map{__searches}{$username}{$topic} = $search->{max_id};
1219 printf $fh "id:%s account:%s type:searchid topic:%s\n",
1220 $search->{max_id}, $username, $topic;
1222 foreach my $t ( reverse @{ $search->{results} } ) {
1223 my $text = &get_text( $t, $obj );
1224 printf $fh "id:%s account:%s nick:%s type:search topic:%s %s\n",
1225 $t->{id}, $username, $t->{from_user}, $topic, $text;
1226 $new_poll_id = $t->{id}
1228 or $t->{id} < $new_poll_id;
1233 print scalar localtime, " - Done" if &debug;
1239 my ( $fh, $target, $username, $obj, $cache ) = @_;
1241 my $last_id = $id_map{__last_id}{$username}{$target};
1243 print $fh "type:debug get_timeline("
1244 . "$fix_replies_index{$username}=$target > $last_id) started."
1245 . " username = $username\n";
1247 $tweets = $obj->user_timeline(
1250 ( $last_id ? ( since_id => $last_id ) : () ),
1257 "type:debug Error during user_timeline($target) call: Aborted.\n";
1258 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1264 "type:debug user_timeline($target) call returned undef! Aborted\n";
1268 foreach my $t ( reverse @$tweets ) {
1269 my $text = &get_text( $t, $obj );
1270 my $reply = "tweet";
1271 if ( Irssi::settings_get_bool("show_reply_context")
1272 and $t->{in_reply_to_screen_name} ne $username
1273 and $t->{in_reply_to_screen_name}
1274 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1276 $nicks{ $t->{in_reply_to_screen_name} } = time;
1278 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1280 $cache->{ $t->{in_reply_to_status_id} } =
1281 $obj->show_status( $t->{in_reply_to_status_id} );
1285 $context = $cache->{ $t->{in_reply_to_status_id} };
1288 my $ctext = &get_text( $context, $obj );
1289 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1290 $context->{id}, $username,
1291 $context->{user}{screen_name}, $ctext;
1295 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1296 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1297 $last_id = $t->{id} if $last_id < $t->{id};
1299 printf $fh "id:%s account:%s type:last_id_fixreplies %s\n",
1300 $last_id, $username, $target;
1307 my $filename = $data->[0];
1308 my $attempt = $data->[1];
1310 print scalar localtime, " - checking child log at $filename ($attempt)"
1312 my ($new_last_poll);
1314 # reap any random leftover processes - work around a bug in irssi on gentoo
1315 waitpid( -1, WNOHANG );
1317 # first time we run we don't want to print out *everything*, so we just
1320 if ( open FILE, $filename ) {
1321 binmode FILE, ":utf8";
1325 last if /^__friends__/;
1326 unless (/\n$/) { # skip partial lines
1327 # print "Skipping partial line: $_" if &debug;
1334 foreach my $key (qw/id account nick type topic/) {
1335 if (s/^$key:(\S+)\s*//) {
1340 if ( $meta{type} and $meta{type} eq 'fix_replies_index' ) {
1341 $fix_replies_index{ $meta{account} } = $meta{id};
1342 print "fix_replies_index for $meta{account} set to $meta{id}"
1347 if ( not $meta{type} or $meta{type} !~ /searchid|last_id/ ) {
1348 if ( exists $meta{id} and exists $new_cache{ $meta{id} } ) {
1352 $new_cache{ $meta{id} } = time;
1354 if ( exists $meta{id} and exists $tweet_cache{ $meta{id} } ) {
1360 $meta{account} =~ s/\@(\w+)$//;
1361 $meta{service} = $1;
1363 lc $meta{service} eq
1364 lc Irssi::settings_get_str("twirssi_default_service") )
1366 $account = "$meta{account}: "
1367 if lc "$meta{account}\@$meta{service}" ne lc
1368 "$user\@$defservice";
1370 $account = "$meta{account}\@$meta{service}: ";
1374 if ( $meta{type} ne 'dm'
1375 and Irssi::settings_get_bool("twirssi_track_replies")
1379 $marker = ( $id_map{__indexes}{ $meta{nick} } + 1 ) % 100;
1380 $id_map{ lc $meta{nick} }[$marker] = $meta{id};
1381 $id_map{__indexes}{ $meta{nick} } = $marker;
1382 $id_map{__tweets}{ lc $meta{nick} }[$marker] = $_;
1383 $marker = ":$marker";
1387 $irssi_to_mirc_colors{ Irssi::settings_get_str("hilight_color") };
1388 my $nick = "\@$meta{account}";
1389 if ( $_ =~ /\Q$nick\E(?:\W|$)/i
1390 and Irssi::settings_get_bool("twirssi_hilights") )
1392 $meta{nick} = "\cC$hilight_color$meta{nick}\cO";
1393 $hilight = MSGLEVEL_HILIGHT;
1396 if ( $meta{type} =~ /tweet|reply/ ) {
1399 ( MSGLEVEL_PUBLIC | $hilight ),
1400 $meta{type}, $account, $meta{nick}, $marker, $_
1402 } elsif ( $meta{type} eq 'search' ) {
1405 ( MSGLEVEL_PUBLIC | $hilight ),
1406 $meta{type}, $account, $meta{topic},
1407 $meta{nick}, $marker, $_
1410 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1412 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1414 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1417 } elsif ( $meta{type} eq 'dm' ) {
1420 ( MSGLEVEL_MSGS | $hilight ),
1421 $meta{type}, $account, $meta{nick}, $_
1423 } elsif ( $meta{type} eq 'searchid' ) {
1424 print "Search '$meta{topic}' returned id $meta{id}" if &debug;
1427 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1429 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1431 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1434 print "Search '$meta{topic}' returned invalid id $meta{id}";
1436 } elsif ( $meta{type} eq 'last_id' ) {
1437 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1439 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1441 } elsif ( $meta{type} eq 'last_id_fixreplies' ) {
1442 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1444 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1446 } elsif ( $meta{type} eq 'error' ) {
1447 push @lines, [ MSGLEVEL_MSGS, $_ ];
1448 } elsif ( $meta{type} eq 'debug' ) {
1449 print "$_" if &debug,;
1451 print "Unknown line type $meta{type}: $_" if &debug,;
1457 if (/^__updated (\d+)$/) {
1458 $last_friends_poll = $1;
1459 print "Friend list updated" if &debug;
1464 $new_last_poll = $1;
1465 if ( $new_last_poll >= $last_poll ) {
1468 print "Impossible! ",
1469 "new_last_poll=$new_last_poll < last_poll=$last_poll!"
1471 undef $new_last_poll;
1475 my ( $f, $t ) = split ' ', $_;
1476 $nicks{$f} = $friends{$f} = $t;
1479 if ($new_last_poll) {
1480 print "new last_poll = $new_last_poll" if &debug;
1481 print "new last_poll_id = ", Dumper( $id_map{__last_id} ) if &debug;
1483 print "First call, not printing updates" if &debug;
1485 foreach my $line (@lines) {
1486 $window->printformat(
1488 "twirssi_" . $line->[1],
1489 @$line[ 2 .. $#$line - 1 ],
1490 &hilight( $line->[-1] )
1497 or warn "Failed to remove $filename: $!"
1500 # commit the pending cache lines to the actual cache, now that
1501 # we've printed our output
1502 %tweet_cache = ( %tweet_cache, %new_cache );
1504 # keep enough cached tweets, to make sure we don't show duplicates.
1505 foreach ( keys %tweet_cache ) {
1506 next if $tweet_cache{$_} >= $last_poll - 3600;
1507 delete $tweet_cache{$_};
1509 $last_poll = $new_last_poll;
1511 # make sure the pid is removed from the waitpid list
1512 Irssi::pidwait_remove($child_pid);
1514 # and that we don't leave any zombies behind, somehow
1520 Irssi::settings_get_str("twirssi_replies_store") )
1522 if ( open JSON, ">$file" ) {
1523 print JSON JSON::Any->objToJson( \%id_map );
1526 &ccrap("Failed to write replies to $file: $!");
1537 if ( $attempt < 24 ) {
1538 Irssi::timeout_add_once( 5000, 'monitor_child',
1539 [ $filename, $attempt + 1 ] );
1541 print "Giving up on polling $filename" if &debug;
1542 Irssi::pidwait_remove($child_pid);
1544 unlink $filename unless &debug;
1546 return unless Irssi::settings_get_bool("twirssi_notify_timeouts");
1549 my @time = localtime($last_poll);
1550 if ( time - $last_poll < 24 * 60 * 60 ) {
1551 $since = sprintf( "%d:%02d", @time[ 2, 1 ] );
1553 $since = scalar localtime($last_poll);
1556 if ( not $failwhale and time - $last_poll > 60 * 60 ) {
1561 q{ .--./ / | _.---.| },
1573 if ( time - $last_poll < 600 ) {
1574 &ccrap("Haven't been able to get updated tweets since $since");
1580 return Irssi::settings_get_bool("twirssi_debug");
1584 $window->print( "%R***%n @_", MSGLEVEL_PUBLIC );
1588 $window->print( "%R***%n @_", MSGLEVEL_CLIENTCRAP );
1594 if ( Irssi::settings_get_bool("tweet_to_away")
1596 and $data !~ /^[dD] / )
1599 Irssi::server_find_tag( Irssi::settings_get_str("bitlbee_server") );
1601 $server->send_raw("away :$data");
1604 &ccrap( "Can't find bitlbee server.",
1605 "Update bitlbee_server or disable tweet_to_away" );
1615 my $noalert = shift;
1617 if ( length $data > 140 ) {
1618 ¬ice( "Tweet too long (" . length($data) . " characters) - aborted" )
1626 sub valid_username {
1627 my $username = shift;
1629 $username = &normalize_username($username);
1631 unless ( exists $twits{$username} ) {
1632 ¬ice("Unknown username $username");
1642 ¬ice("Not logged in! Use /twitter_login username pass!");
1650 my ( $complist, $window, $word, $linestart, $want_space ) = @_;
1653 $linestart =~ /^\/(?:retweet|twitter_reply)(?:_as)?\s*$/
1654 or ( Irssi::settings_get_bool("twirssi_use_reply_aliases")
1655 and $linestart =~ /^\/reply(?:_as)?\s*$/ )
1657 { # /twitter_reply gets a nick:num
1659 @$complist = map { "$_:$id_map{__indexes}{$_}" }
1660 sort { $nicks{$b} <=> $nicks{$a} }
1662 keys %{ $id_map{__indexes} };
1666 /^\/(twitter_unfriend|twitter_add_follow_extra|twitter_del_follow_extra)\s*$/
1668 { # /twitter_unfriend gets a nick
1670 push @$complist, grep /^\Q$word/i,
1671 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1674 # /tweet, /tweet_as, /dm, /dm_as - complete @nicks (and nicks as the first
1676 if ( $linestart =~ /^\/(?:tweet|dm)/ ) {
1677 my $prefix = $word =~ s/^@//;
1678 $prefix = 0 if $linestart eq '/dm' or $linestart eq '/dm_as';
1679 push @$complist, grep /^\Q$word/i,
1680 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1681 @$complist = map { "\@$_" } @$complist if $prefix;
1685 sub event_send_text {
1686 my ( $line, $server, $win ) = @_;
1687 my $awin = Irssi::active_win();
1689 # if the window where we got our text was the twitter window, and the user
1690 # wants to be lazy, tweet away!
1691 if ( ( $awin->get_active_name() eq $window->{name} )
1692 and Irssi::settings_get_bool("tweet_window_input") )
1694 &cmd_tweet( $line, $server, $win );
1699 my $poll = Irssi::settings_get_int("twitter_poll_interval");
1700 return $poll if $poll >= 60;
1707 if ( Irssi::settings_get_str("twirssi_nick_color") ) {
1708 my $c = Irssi::settings_get_str("twirssi_nick_color");
1709 $c = $irssi_to_mirc_colors{$c};
1710 $text =~ s/(^|\W)\@(\w+)/$1\cC$c\@$2\cO/g if $c;
1712 if ( Irssi::settings_get_str("twirssi_topic_color") ) {
1713 my $c = Irssi::settings_get_str("twirssi_topic_color");
1714 $c = $irssi_to_mirc_colors{$c};
1715 $text =~ s/(^|\W)(\#|\!)([-\w]+)/$1\cC$c$2$3\cO/g if $c;
1717 $text =~ s/[\n\r]/ /g;
1725 my $provider = Irssi::settings_get_str("short_url_provider");
1728 Irssi::settings_get_bool("twirssi_always_shorten")
1729 or &too_long( $data, 1 )
1735 if ( $provider eq 'Bitly' ) {
1736 @args[ 1, 2 ] = split ',',
1737 Irssi::settings_get_str("short_url_args"), 2;
1738 unless ( @args == 3 ) {
1740 "WWW::Shorten::Bitly requires a username and API key.",
1741 "Set short_url_args to username,API_key or change your",
1742 "short_url_provider."
1744 return decode "utf8", $data;
1748 foreach my $url ( $data =~ /(https?:\/\/\S+[\w\/])/g ) {
1751 my $short = makeashorterlink(@args);
1753 $data =~ s/\Q$url/$short/g;
1755 ¬ice("Failed to shorten $url!");
1761 return decode "utf8", $data;
1764 sub normalize_username {
1767 my ( $username, $service ) = split /\@/, $user, 2;
1769 $service = ucfirst lc $service;
1772 ucfirst lc Irssi::settings_get_str("twirssi_default_service");
1773 unless ( exists $twits{"$username\@$service"} ) {
1775 foreach my $t ( sort keys %twits ) {
1776 next unless $t =~ /^\Q$username\E\@(Twitter|Identica)/;
1782 ¬ice("Can't find a logged in user '$user'");
1787 return "$username\@$service";
1793 my $text = decode_entities( $tweet->{text} );
1794 if ( $tweet->{truncated} ) {
1795 if ( exists $tweet->{retweeted_status} ) {
1796 $text = "RT \@$tweet->{retweeted_status}{user}{screen_name}: "
1797 . "$tweet->{retweeted_status}{text}";
1798 } elsif ( $object->isa('Net::Twitter') ) {
1799 $text .= " -- http://twitter.com/$tweet->{user}{screen_name}"
1800 . "/status/$tweet->{id}";
1804 $text =~ s/[\n\r]/ /g;
1809 Irssi::signal_add( "send text", "event_send_text" );
1811 Irssi::theme_register(
1813 'twirssi_tweet', '[$0%B@$1%n$2] $3',
1814 'twirssi_search', '[$0%r$1%n:%B@$2%n$3] $4',
1815 'twirssi_reply', '[$0\--> %B@$1%n$2] $3',
1816 'twirssi_dm', '[$0%r@$1%n (%WDM%n)] $2',
1817 'twirssi_error', 'ERROR: $0',
1821 Irssi::settings_add_int( "twirssi", "twitter_poll_interval", 300 );
1822 Irssi::settings_add_str( "twirssi", "twitter_window", "twitter" );
1823 Irssi::settings_add_str( "twirssi", "bitlbee_server", "bitlbee" );
1824 Irssi::settings_add_str( "twirssi", "short_url_provider", "TinyURL" );
1825 Irssi::settings_add_str( "twirssi", "short_url_args", undef );
1826 Irssi::settings_add_str( "twirssi", "twitter_usernames", undef );
1827 Irssi::settings_add_str( "twirssi", "twitter_passwords", undef );
1828 Irssi::settings_add_str( "twirssi", "twirssi_default_service", "Twitter" );
1829 Irssi::settings_add_str( "twirssi", "twirssi_nick_color", "%B" );
1830 Irssi::settings_add_str( "twirssi", "twirssi_topic_color", "%r" );
1831 Irssi::settings_add_str( "twirssi", "twirssi_retweet_format",
1832 'RT $n: "$t" ${-- $c$}' );
1833 Irssi::settings_add_str( "twirssi", "twirssi_location",
1834 "$ENV{HOME}/.irssi/scripts/twirssi.pl" );
1835 Irssi::settings_add_str( "twirssi", "twirssi_replies_store",
1836 "$ENV{HOME}/.irssi/scripts/twirssi.json" );
1837 Irssi::settings_add_str( "twirssi", "twirssi_oauth_store",
1838 "$ENV{HOME}/.irssi/scripts/twirssi.oauth" );
1840 Irssi::settings_add_int( "twirssi", "twitter_friends_poll", 600 );
1841 Irssi::settings_add_int( "twirssi", "twitter_timeout", 30 );
1843 Irssi::settings_add_bool( "twirssi", "twirssi_upgrade_beta", 0 );
1844 Irssi::settings_add_bool( "twirssi", "tweet_to_away", 0 );
1845 Irssi::settings_add_bool( "twirssi", "show_reply_context", 0 );
1846 Irssi::settings_add_bool( "twirssi", "show_own_tweets", 1 );
1847 Irssi::settings_add_bool( "twirssi", "twirssi_debug", 0 );
1848 Irssi::settings_add_bool( "twirssi", "twirssi_first_run", 1 );
1849 Irssi::settings_add_bool( "twirssi", "twirssi_track_replies", 1 );
1850 Irssi::settings_add_bool( "twirssi", "twirssi_replies_autonick", 1 );
1851 Irssi::settings_add_bool( "twirssi", "twirssi_use_reply_aliases", 0 );
1852 Irssi::settings_add_bool( "twirssi", "twirssi_notify_timeouts", 1 );
1853 Irssi::settings_add_bool( "twirssi", "twirssi_hilights", 1 );
1854 Irssi::settings_add_bool( "twirssi", "twirssi_always_shorten", 0 );
1855 Irssi::settings_add_bool( "twirssi", "tweet_window_input", 0 );
1856 Irssi::settings_add_bool( "twirssi", "twirssi_avoid_ssl", 0 );
1857 Irssi::settings_add_bool( "twirssi", "twirssi_use_oauth", 1 );
1859 $last_poll = time - &get_poll_time;
1860 $window = Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
1863 ->print( "Couldn't find a window named '"
1864 . Irssi::settings_get_str('twitter_window')
1865 . "', trying to create it." );
1867 Irssi::Windowitem::window_create(
1868 Irssi::settings_get_str('twitter_window'), 1 );
1869 $window->set_name( Irssi::settings_get_str('twitter_window') );
1873 Irssi::command_bind( "dm", "cmd_direct" );
1874 Irssi::command_bind( "dm_as", "cmd_direct_as" );
1875 Irssi::command_bind( "tweet", "cmd_tweet" );
1876 Irssi::command_bind( "tweet_as", "cmd_tweet_as" );
1877 Irssi::command_bind( "retweet", "cmd_retweet" );
1878 Irssi::command_bind( "retweet_as", "cmd_retweet_as" );
1879 Irssi::command_bind( "twitter_reply", "cmd_reply" );
1880 Irssi::command_bind( "twitter_reply_as", "cmd_reply_as" );
1881 Irssi::command_bind( "twitter_login", "cmd_login" );
1882 Irssi::command_bind( "twitter_logout", "cmd_logout" );
1883 Irssi::command_bind( "twitter_switch", "cmd_switch" );
1884 Irssi::command_bind( "twitter_subscribe", "cmd_add_search" );
1885 Irssi::command_bind( "twitter_unsubscribe", "cmd_del_search" );
1886 Irssi::command_bind( "twitter_list_subscriptions", "cmd_list_search" );
1887 Irssi::command_bind( "twirssi_upgrade", "cmd_upgrade" );
1888 Irssi::command_bind( "twirssi_oauth", "cmd_oauth" );
1889 Irssi::command_bind( "twitter_updates", "get_updates" );
1890 Irssi::command_bind( "twitter_add_follow_extra", "cmd_add_follow" );
1891 Irssi::command_bind( "twitter_del_follow_extra", "cmd_del_follow" );
1892 Irssi::command_bind( "twitter_list_follow_extra", "cmd_list_follow" );
1893 Irssi::command_bind( "bitlbee_away", "update_away" );
1894 if ( Irssi::settings_get_bool("twirssi_use_reply_aliases") ) {
1895 Irssi::command_bind( "reply", "cmd_reply" );
1896 Irssi::command_bind( "reply_as", "cmd_reply_as" );
1898 Irssi::command_bind(
1901 print "twits: ", join ", ",
1902 map { "u: $_->{username}\@" . ref($_) } values %twits;
1903 print "selected: $user\@$defservice";
1904 print "friends: ", join ", ", sort keys %friends;
1905 print "nicks: ", join ", ", sort keys %nicks;
1906 print "searches: ", Dumper \%{ $id_map{__searches} };
1907 print "last poll: $last_poll";
1908 if ( open DUMP, ">/tmp/twirssi.cache.txt" ) {
1909 print DUMP Dumper \%tweet_cache;
1911 print "cache written out to /tmp/twirssi.cache.txt";
1915 Irssi::command_bind(
1919 "Twirssi v$VERSION; "
1921 $Net::Twitter::VERSION
1922 ? "Net::Twitter v$Net::Twitter::VERSION. "
1926 $Net::Identica::VERSION
1927 ? "Net::Identica v$Net::Identica::VERSION. "
1931 . JSON::Any::handler()
1932 . ". See details at http://twirssi.com/"
1936 Irssi::command_bind(
1939 "/twitter_follow <username>",
1941 sub { ¬ice("Following $_[0]"); $nicks{ $_[0] } = time; }
1944 Irssi::command_bind(
1947 "/twitter_unfriend <username>",
1949 sub { ¬ice("Stopped following $_[0]"); delete $nicks{ $_[0] }; }
1952 Irssi::command_bind(
1953 "twitter_device_updates",
1955 "/twitter_device_updates none|im|sms",
1956 "update_delivery_device",
1957 sub { ¬ice("Device updated to $_[0]"); }
1960 Irssi::command_bind(
1963 "/twitter_block <username>",
1965 sub { ¬ice("Blocked $_[0]"); }
1968 Irssi::command_bind(
1971 "/twitter_unblock <username>",
1973 sub { ¬ice("Unblock $_[0]"); }
1976 Irssi::signal_add_last( 'complete word' => \&sig_complete );
1978 ¬ice(" %Y<%C(%B^%C)%N TWIRSSI v%R$VERSION%N");
1979 ¬ice(" %C(_(\\%N http://twirssi.com/ for full docs");
1981 " %Y||%C `%N Log in with /twitter_login, send updates with /tweet");
1983 my $file = Irssi::settings_get_str("twirssi_replies_store");
1984 if ( $file and -r $file ) {
1985 if ( open( JSON, $file ) ) {
1990 my $ref = JSON::Any->jsonToObj($json);
1992 my $num = keys %{ $id_map{__indexes} };
1993 ¬ice( sprintf "Loaded old replies from %d contact%s.",
1994 $num, ( $num == 1 ? "" : "s" ) );
1999 ¬ice("Failed to load old replies from $file: $!");
2003 if ( my $provider = Irssi::settings_get_str("short_url_provider") ) {
2004 ¬ice("Loading WWW::Shorten::$provider...");
2005 eval "use WWW::Shorten::$provider;";
2009 "Failed to load WWW::Shorten::$provider - either clear",
2010 "short_url_provider or install the CPAN module"
2015 if ( my $autouser = Irssi::settings_get_str("twitter_usernames") ) {
2022 ->print( "Create a window named "
2023 . Irssi::settings_get_str('twitter_window')
2024 . " or change the value of twitter_window. Then, reload twirssi." );
2027 # vim: set sts=4 expandtab: