10 use POSIX qw/:sys_wait_h/;
11 use Net::Twitter::Lite
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...");
434 eval { $twits{$data}->end_session(); };
435 delete $twits{$data};
438 &cmd_switch( ( keys %twits )[0], $server, $win );
440 Irssi::timeout_remove($poll) if $poll;
446 my ( $data, $server, $win ) = @_;
448 print "logging in: $data" if &debug;
450 print "manual data login" if &debug;
451 ( $user, $pass ) = split ' ', $data, 2;
452 unless ( Irssi::settings_get_bool("twirssi_use_oauth") or $pass ) {
453 ¬ice("usage: /twitter_login <username>[\@<service>] <password>");
456 } elsif ( Irssi::settings_get_bool("twirssi_use_oauth")
457 and my $autouser = Irssi::settings_get_str("twitter_usernames") )
459 print "oauth autouser login" if &debug;
460 foreach my $user ( split /,/, $autouser ) {
464 } elsif ( my $autouser = Irssi::settings_get_str("twitter_usernames")
465 and my $autopass = Irssi::settings_get_str("twitter_passwords") )
467 print "autouser login" if &debug;
468 my @user = split /\s*,\s*/, $autouser;
469 my @pass = split /\s*,\s*/, $autopass;
471 # if a password ends with a '\', it was meant to escape the comma, and
472 # it should be concatinated with the next one
476 while ( $p =~ /\\$/ and @pass ) {
477 $p .= "," . shift @pass;
482 if ( @user != @unescaped ) {
483 ¬ice("Number of usernames doesn't match "
484 . "the number of passwords - auto-login failed" );
487 while ( @user and @unescaped ) {
489 $p = shift @unescaped;
495 ¬ice("/twitter_login requires either a username/password "
496 . "or twitter_usernames and twitter_passwords to be set. "
497 . "Note that if twirssi_use_oauth is true, passwords are "
502 %friends = %nicks = ();
505 if ( $user =~ /^(.*)@(twitter|identica)$/ ) {
506 ( $user, $service ) = ( $1, $2 );
508 $service = Irssi::settings_get_str("twirssi_default_service");
510 $defservice = $service = ucfirst lc $service;
512 $twit = Net::Twitter::Lite->new(
518 ¬ice("Failed to create object! Aborting.");
522 return &verify_twitter_object( $server, $win, $user, $service, $twit );
526 my ( $data, $server, $win ) = @_;
527 my ( $key, $pin ) = split ' ', $data;
528 my ( $user, $service );
529 $key = &normalize_username($key);
530 if ( $key =~ /^(.*)@(Twitter|Identica)$/ ) {
531 ( $user, $service ) = ( $1, $2 );
534 print "Applying pin to $key" if &debug;
536 unless ( exists $oauth{pending}{$key} ) {
537 ¬ice("There isn't a pending oauth request for $key. "
538 . "Try /twitter_login first" );
542 my $twit = $oauth{pending}{$key};
543 my ( $access_token, $access_token_secret );
545 ( $access_token, $access_token_secret ) =
546 $twit->request_access_token( verifier => $pin );
550 ¬ice("Invalid pin, try again.");
554 delete $oauth{pending}{$key};
556 my $store_file = Irssi::settings_get_str("twirssi_oauth_store");
559 if ( open( OAUTH, $store_file ) ) {
569 push @store, "$key $access_token $access_token_secret";
571 if ( open( OAUTH, ">$store_file.new" ) ) {
572 print OAUTH "$_\n" foreach @store;
574 rename "$store_file.new", $store_file
575 or ¬ice("Failed to rename $store_file.new: $!");
577 ¬ice("Failed to write $store_file.new: $!");
580 ¬ice("No persistant storage set for OAuth. "
581 . "Please /set twirssi_oauth_store to a writable filename." );
584 return &verify_twitter_object( $server, $win, $user, $service, $twit );
587 sub verify_twitter_object {
588 my ( $server, $win, $user, $service, $twit ) = @_;
590 if ( my $timeout = Irssi::settings_get_int("twitter_timeout")
591 and $twit->can('ua') )
593 $twit->ua->timeout($timeout);
594 ¬ice("Twitter timeout set to $timeout");
597 unless ( $twit->verify_credentials() ) {
598 ¬ice("Login as $user\@$service failed");
600 if ( not Irssi::settings_get_bool("twirssi_avoid_ssl") ) {
602 "It's possible you're missing one of the modules required for "
603 . "SSL logins. Try setting twirssi_avoid_ssl to on. See "
604 . "http://cpansearch.perl.org/src/GAAS/libwww-perl-5.831/README.SSL "
605 . "for the detailed requirements." );
610 &cmd_switch( ( keys %twits )[0], $server, $win );
615 my $rate_limit = $twit->rate_limit_status();
616 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
618 "Rate limit exceeded, try again after $rate_limit->{reset_time}");
623 print "saving object for $user\@$service" if &debug;
624 $twits{"$user\@$service"} = $twit;
625 Irssi::timeout_remove($poll) if $poll;
626 $poll = Irssi::timeout_add( &get_poll_time * 1000, \&get_updates, "" );
627 ¬ice("Logged in as $user\@$service, loading friends list...");
629 ¬ice( "loaded friends: ". scalar keys %friends );
630 if ( Irssi::settings_get_bool("twirssi_first_run") ) {
631 Irssi::settings_set_bool( "twirssi_first_run", 0 );
639 my ( $data, $server, $win ) = @_;
642 ¬ice("Usage: /twitter_add_follow_extra <username>");
646 $data =~ s/^\s+|\s+$//;
650 if ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
651 ¬ice("Already following all replies by \@$data");
655 $id_map{__fixreplies}{"$user\@$defservice"}{$data} = 1;
656 ¬ice("Will now follow all replies by \@$data");
660 my ( $data, $server, $win ) = @_;
663 ¬ice("Usage: /twitter_del_follow_extra <username>");
667 $data =~ s/^\s+|\s+$//;
671 unless ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
672 ¬ice("Wasn't following all replies by \@$data");
676 delete $id_map{__fixreplies}{"$user\@$defservice"}{$data};
677 ¬ice("Will no longer follow all replies by \@$data");
680 sub cmd_list_follow {
681 my ( $data, $server, $win ) = @_;
684 foreach my $suser ( sort keys %{ $id_map{__fixreplies} } ) {
686 foreach my $fruser ( sort keys %{ $id_map{__fixreplies}{$suser} } ) {
687 $frusers = $frusers ? "$frusers, $fruser" : $fruser;
691 ¬ice("Following all replies as \@$suser: $frusers");
696 ¬ice("Not following all replies by anyone");
701 my ( $data, $server, $win ) = @_;
703 unless ( $twit and $twit->can('search') ) {
704 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
705 . "doesn't support searches." );
709 $data =~ s/^\s+|\s+$//;
713 ¬ice("Usage: /twitter_subscribe <topic>");
717 if ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
718 ¬ice("Already had a subscription for '$data'");
722 $id_map{__searches}{"$user\@$defservice"}{$data} = 1;
723 ¬ice("Added subscription for '$data'");
727 my ( $data, $server, $win ) = @_;
729 unless ( $twit and $twit->can('search') ) {
730 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
731 . "doesn't support searches." );
734 $data =~ s/^\s+|\s+$//;
738 ¬ice("Usage: /twitter_unsubscribe <topic>");
742 unless ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
743 ¬ice("No subscription found for '$data'");
747 delete $id_map{__searches}{"$user\@$defservice"}{$data};
748 ¬ice("Removed subscription for '$data'");
751 sub cmd_list_search {
752 my ( $data, $server, $win ) = @_;
755 foreach my $suser ( sort keys %{ $id_map{__searches} } ) {
757 foreach my $topic ( sort keys %{ $id_map{__searches}{$suser} } ) {
758 $topics = $topics ? "$topics, $topic" : $topic;
762 ¬ice("Search subscriptions for \@$suser: $topics");
767 ¬ice("No search subscriptions set up");
772 my ( $data, $server, $win ) = @_;
774 my $loc = Irssi::settings_get_str("twirssi_location");
776 ¬ice("$loc isn't writable, can't upgrade."
777 . " Perhaps you need to /set twirssi_location?" );
782 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
783 eval { use Digest::MD5; };
786 ¬ice("Failed to load Digest::MD5."
787 . " Try '/twirssi_upgrade nomd5' to skip MD5 verification" );
791 $md5 = get("http://twirssi.com/md5sum");
795 ¬ice("Failed to download md5sum from peeron! Aborting.");
799 unless ( open( CUR, $loc ) ) {
800 ¬ice("Failed to read $loc."
801 . " Check that /set twirssi_location is set to the correct location."
806 my $cur_md5 = Digest::MD5::md5_hex(<CUR>);
809 if ( $cur_md5 eq $md5 ) {
810 ¬ice("Current twirssi seems to be up to date.");
816 Irssi::settings_get_bool("twirssi_upgrade_beta")
817 ? "http://github.com/zigdon/twirssi/raw/master/twirssi.pl"
818 : "http://twirssi.com/twirssi.pl";
819 ¬ice("Downloading twirssi from $URL");
820 LWP::Simple::getstore( $URL, "$loc.upgrade" );
822 unless ( -s "$loc.upgrade" ) {
823 ¬ice("Failed to save $loc.upgrade."
824 . " Check that /set twirssi_location is set to the correct location."
829 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
830 unless ( open( NEW, "$loc.upgrade" ) ) {
831 ¬ice("Failed to read $loc.upgrade."
832 . " Check that /set twirssi_location is set to the correct location."
837 my $new_md5 = Digest::MD5::md5_hex(<NEW>);
840 if ( $new_md5 ne $md5 ) {
841 ¬ice("MD5 verification failed. expected $md5, got $new_md5");
846 rename $loc, "$loc.backup"
847 or ¬ice("Failed to back up $loc: $!. Aborting")
849 rename "$loc.upgrade", $loc
850 or ¬ice("Failed to rename $loc.upgrade: $!. Aborting")
853 my ( $dir, $file ) = ( $loc =~ m{(.*)/([^/]+)$} );
854 if ( -e "$dir/autorun/$file" ) {
855 ¬ice("Updating $dir/autorun/$file");
856 unlink "$dir/autorun/$file"
857 or ¬ice("Failed to remove old $file from autorun: $!");
858 symlink "../$file", "$dir/autorun/$file"
859 or ¬ice("Failed to create symlink in autorun directory: $!");
862 ¬ice("Download complete. Reload twirssi with /script load $file");
871 while ( $page < 11 and $cursor ne "0" )
873 print $fh "type:debug Loading friends page $page...\n"
874 if ( $fh and &debug );
876 if ( ref $twit =~ /^Net::Twitter/ ) {
877 $friends = $twit->friends( { cursor => $cursor } );
878 last unless $friends;
879 $cursor = $friends->{next_cursor};
880 $friends = $friends->{users};
882 $friends = $twit->friends( { page => $page } );
883 last unless $friends;
885 $new_friends{ $_->{screen_name} } = time foreach @$friends;
891 print $fh "type:debug Error during friends list update. Aborted.\n"
896 my ( $added, $removed ) = ( 0, 0 );
897 print $fh "type:debug Scanning for new friends...\n" if ( $fh and &debug );
898 foreach ( keys %new_friends ) {
899 next if exists $friends{$_};
904 print $fh "type:debug Scanning for removed friends...\n"
905 if ( $fh and &debug );
906 foreach ( keys %friends ) {
907 next if exists $new_friends{$_};
912 return ( $added, $removed );
916 print scalar localtime, " - get_updates starting" if &debug;
919 Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
922 ->print( "Can't find a window named '"
923 . Irssi::settings_get_str('twitter_window')
924 . "'. Create it or change the value of twitter_window" );
927 return unless &logged_in($twit);
929 my ( $fh, $filename ) = File::Temp::tempfile();
930 binmode( $fh, ":utf8" );
933 if ($child_pid) { # parent
934 Irssi::timeout_add_once( 5000, 'monitor_child',
935 [ "$filename.done", 0 ] );
936 Irssi::pidwait_add($child_pid);
937 } elsif ( defined $child_pid ) { # child
946 foreach ( keys %twits ) {
947 $error++ unless &do_updates( $fh, $_, $twits{$_}, \%context_cache );
949 if ( $id_map{__fixreplies}{$_} ) {
950 my @frusers = sort keys %{ $id_map{__fixreplies}{$_} };
953 unless &get_timeline( $fh, $frusers[ $fix_replies_index{$_} ],
954 $_, $twits{$_}, \%context_cache );
956 $fix_replies_index{$_}++;
957 $fix_replies_index{$_} = 0
958 if $fix_replies_index{$_} >= @frusers;
959 print $fh "id:$fix_replies_index{$_} ",
960 "account:$_ type:fix_replies_index\n";
964 print $fh "__friends__\n";
966 time - $last_friends_poll >
967 Irssi::settings_get_int('twitter_friends_poll') )
969 print $fh "__updated ", time, "\n";
970 my ( $added, $removed ) = &load_friends($fh);
971 if ( $added + $removed ) {
972 print $fh "type:debug %R***%n Friends list updated: ",
974 sprintf( "%d added", $added ),
975 sprintf( "%d removed", $removed ) ),
980 foreach ( sort keys %friends ) {
981 print $fh "$_ $friends{$_}\n";
985 print $fh "type:debug Update encountered errors. Aborted\n";
986 print $fh "-- $last_poll";
988 print $fh "-- $new_poll";
991 rename $filename, "$filename.done";
994 &ccrap("Failed to fork for updating: $!");
996 print scalar localtime, " - get_updates ends" if &debug;
1000 my ( $fh, $username, $obj, $cache ) = @_;
1003 my $rate_limit = $obj->rate_limit_status();
1004 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
1005 ¬ice("Rate limit exceeded for $username");
1010 print scalar localtime, " - Polling for updates for $username" if &debug;
1012 my $new_poll_id = 0;
1014 if ( $id_map{__last_id}{$username}{timeline} )
1016 $tweets = $obj->home_timeline( { count => 100 } );
1018 $tweets = $obj->home_timeline();
1023 print $fh "type:debug Error during home_timeline call: Aborted.\n";
1024 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1028 unless ( ref $tweets ) {
1029 if ( $obj->can("get_error") ) {
1030 my $error = "Unknown error";
1031 eval { $error = JSON::Any->jsonToObj( $obj->get_error() ) };
1032 unless ($@) { $error = $obj->get_error() }
1034 "type:debug API Error during home_timeline call: Aborted\n";
1035 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($error);
1039 "type:debug API Error during home_timeline call. Aborted.\n";
1044 foreach my $t ( reverse @$tweets ) {
1045 my $text = &get_text( $t, $obj );
1046 my $reply = "tweet";
1047 if ( Irssi::settings_get_bool("show_reply_context")
1048 and $t->{in_reply_to_screen_name} ne $username
1049 and $t->{in_reply_to_screen_name}
1050 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1052 $nicks{ $t->{in_reply_to_screen_name} } = time;
1054 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1056 $cache->{ $t->{in_reply_to_status_id} } =
1057 $obj->show_status( $t->{in_reply_to_status_id} );
1061 $context = $cache->{ $t->{in_reply_to_status_id} };
1064 my $ctext = &get_text( $context, $obj );
1065 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1066 $context->{id}, $username,
1067 $context->{user}{screen_name}, $ctext;
1072 if $t->{user}{screen_name} eq $username
1073 and not Irssi::settings_get_bool("show_own_tweets");
1074 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1075 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1076 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1078 printf $fh "id:%s account:%s type:last_id timeline\n",
1079 $new_poll_id, $username;
1081 print scalar localtime, " - Polling for replies since ",
1082 $id_map{__last_id}{$username}{reply}
1086 if ( $id_map{__last_id}{$username}{reply} )
1088 $tweets = $obj->replies(
1089 { since_id => $id_map{__last_id}{$username}{reply} } )
1092 $tweets = $obj->replies() || [];
1097 print $fh "type:debug Error during replies call. Aborted.\n";
1101 foreach my $t ( reverse @$tweets ) {
1103 if exists $friends{ $t->{user}{screen_name} };
1105 my $text = &get_text( $t, $obj );
1106 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1107 $t->{id}, $username, $t->{user}{screen_name}, $text;
1108 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1110 printf $fh "id:%s account:%s type:last_id reply\n", $new_poll_id, $username;
1112 print scalar localtime, " - Polling for DMs" if &debug;
1115 if ( $id_map{__last_id}{$username}{dm} )
1117 $tweets = $obj->direct_messages(
1118 { since_id => $id_map{__last_id}{$username}{dm} } )
1121 $tweets = $obj->direct_messages() || [];
1126 print $fh "type:debug Error during direct_messages call. Aborted.\n";
1130 foreach my $t ( reverse @$tweets ) {
1131 my $text = decode_entities( $t->{text} );
1132 $text =~ s/[\n\r]/ /g;
1133 printf $fh "id:%s account:%s nick:%s type:dm %s\n",
1134 $t->{id}, $username, $t->{sender_screen_name}, $text;
1135 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1137 printf $fh "id:%s account:%s type:last_id dm\n", $new_poll_id, $username;
1139 print scalar localtime, " - Polling for subscriptions" if &debug;
1140 if ( $obj->can('search') and $id_map{__searches}{$username} ) {
1142 foreach my $topic ( sort keys %{ $id_map{__searches}{$username} } ) {
1143 print $fh "type:debug searching for $topic since ",
1144 "$id_map{__searches}{$username}{$topic}\n";
1146 $search = $obj->search(
1149 since_id => $id_map{__searches}{$username}{$topic}
1156 "type:debug Error during search($topic) call. Aborted.\n";
1160 unless ( $search->{max_id} ) {
1161 print $fh "type:debug Invalid search results when searching",
1162 " for $topic. Aborted.\n";
1166 $id_map{__searches}{$username}{$topic} = $search->{max_id};
1167 printf $fh "id:%s account:%s type:searchid topic:%s\n",
1168 $search->{max_id}, $username, $topic;
1170 foreach my $t ( reverse @{ $search->{results} } ) {
1171 my $text = &get_text( $t, $obj );
1172 printf $fh "id:%s account:%s nick:%s type:search topic:%s %s\n",
1173 $t->{id}, $username, $t->{from_user}, $topic, $text;
1174 $new_poll_id = $t->{id}
1176 or $t->{id} < $new_poll_id;
1181 print scalar localtime, " - Done" if &debug;
1187 my ( $fh, $target, $username, $obj, $cache ) = @_;
1189 my $last_id = $id_map{__last_id}{$username}{$target};
1191 print $fh "type:debug get_timeline("
1192 . "$fix_replies_index{$username}=$target > $last_id) started."
1193 . " username = $username\n";
1195 $tweets = $obj->user_timeline(
1198 ( $last_id ? ( since_id => $last_id ) : () ),
1205 "type:debug Error during user_timeline($target) call: Aborted.\n";
1206 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1212 "type:debug user_timeline($target) call returned undef! Aborted\n";
1216 foreach my $t ( reverse @$tweets ) {
1217 my $text = &get_text( $t, $obj );
1218 my $reply = "tweet";
1219 if ( Irssi::settings_get_bool("show_reply_context")
1220 and $t->{in_reply_to_screen_name} ne $username
1221 and $t->{in_reply_to_screen_name}
1222 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1224 $nicks{ $t->{in_reply_to_screen_name} } = time;
1226 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1228 $cache->{ $t->{in_reply_to_status_id} } =
1229 $obj->show_status( $t->{in_reply_to_status_id} );
1233 $context = $cache->{ $t->{in_reply_to_status_id} };
1236 my $ctext = &get_text( $context, $obj );
1237 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1238 $context->{id}, $username,
1239 $context->{user}{screen_name}, $ctext;
1243 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1244 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1245 $last_id = $t->{id} if $last_id < $t->{id};
1247 printf $fh "id:%s account:%s type:last_id_fixreplies %s\n",
1248 $last_id, $username, $target;
1255 my $filename = $data->[0];
1256 my $attempt = $data->[1];
1258 print scalar localtime, " - checking child log at $filename ($attempt)"
1260 my ($new_last_poll);
1262 # reap any random leftover processes - work around a bug in irssi on gentoo
1263 waitpid( -1, WNOHANG );
1265 # first time we run we don't want to print out *everything*, so we just
1268 if ( open FILE, $filename ) {
1269 binmode FILE, ":utf8";
1273 last if /^__friends__/;
1274 unless (/\n$/) { # skip partial lines
1275 # print "Skipping partial line: $_" if &debug;
1282 foreach my $key (qw/id account nick type topic/) {
1283 if (s/^$key:(\S+)\s*//) {
1288 if ( $meta{type} and $meta{type} eq 'fix_replies_index' ) {
1289 $fix_replies_index{ $meta{account} } = $meta{id};
1290 print "fix_replies_index for $meta{account} set to $meta{id}"
1295 if ( not $meta{type} or $meta{type} !~ /searchid|last_id/ ) {
1296 if ( exists $meta{id} and exists $new_cache{ $meta{id} } ) {
1300 $new_cache{ $meta{id} } = time;
1302 if ( exists $meta{id} and exists $tweet_cache{ $meta{id} } ) {
1308 $meta{account} =~ s/\@(\w+)$//;
1309 $meta{service} = $1;
1311 lc $meta{service} eq
1312 lc Irssi::settings_get_str("twirssi_default_service") )
1314 $account = "$meta{account}: "
1315 if lc "$meta{account}\@$meta{service}" ne lc
1316 "$user\@$defservice";
1318 $account = "$meta{account}\@$meta{service}: ";
1322 if ( $meta{type} ne 'dm'
1323 and Irssi::settings_get_bool("twirssi_track_replies")
1327 $marker = ( $id_map{__indexes}{ $meta{nick} } + 1 ) % 100;
1328 $id_map{ lc $meta{nick} }[$marker] = $meta{id};
1329 $id_map{__indexes}{ $meta{nick} } = $marker;
1330 $id_map{__tweets}{ lc $meta{nick} }[$marker] = $_;
1331 $marker = ":$marker";
1335 $irssi_to_mirc_colors{ Irssi::settings_get_str("hilight_color") };
1336 my $nick = "\@$meta{account}";
1337 if ( $_ =~ /\Q$nick\E(?:\W|$)/i
1338 and Irssi::settings_get_bool("twirssi_hilights") )
1340 $meta{nick} = "\cC$hilight_color$meta{nick}\cO";
1341 $hilight = MSGLEVEL_HILIGHT;
1344 if ( $meta{type} =~ /tweet|reply/ ) {
1347 ( MSGLEVEL_PUBLIC | $hilight ),
1348 $meta{type}, $account, $meta{nick}, $marker, $_
1350 } elsif ( $meta{type} eq 'search' ) {
1353 ( MSGLEVEL_PUBLIC | $hilight ),
1354 $meta{type}, $account, $meta{topic},
1355 $meta{nick}, $marker, $_
1358 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1360 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1362 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1365 } elsif ( $meta{type} eq 'dm' ) {
1368 ( MSGLEVEL_MSGS | $hilight ),
1369 $meta{type}, $account, $meta{nick}, $_
1371 } elsif ( $meta{type} eq 'searchid' ) {
1372 print "Search '$meta{topic}' returned id $meta{id}" if &debug;
1375 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1377 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1379 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1382 print "Search '$meta{topic}' returned invalid id $meta{id}";
1384 } elsif ( $meta{type} eq 'last_id' ) {
1385 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1387 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1389 } elsif ( $meta{type} eq 'last_id_fixreplies' ) {
1390 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1392 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1394 } elsif ( $meta{type} eq 'error' ) {
1395 push @lines, [ MSGLEVEL_MSGS, $_ ];
1396 } elsif ( $meta{type} eq 'debug' ) {
1397 print "$_" if &debug,;
1399 print "Unknown line type $meta{type}: $_" if &debug,;
1405 if (/^__updated (\d+)$/) {
1406 $last_friends_poll = $1;
1407 print "Friend list updated" if &debug;
1412 $new_last_poll = $1;
1413 if ( $new_last_poll >= $last_poll ) {
1416 print "Impossible! ",
1417 "new_last_poll=$new_last_poll < last_poll=$last_poll!"
1419 undef $new_last_poll;
1423 my ( $f, $t ) = split ' ', $_;
1424 $nicks{$f} = $friends{$f} = $t;
1427 if ($new_last_poll) {
1428 print "new last_poll = $new_last_poll" if &debug;
1429 print "new last_poll_id = ", Dumper( $id_map{__last_id} ) if &debug;
1431 print "First call, not printing updates" if &debug;
1433 foreach my $line (@lines) {
1434 $window->printformat(
1436 "twirssi_" . $line->[1],
1437 @$line[ 2 .. $#$line - 1 ],
1438 &hilight( $line->[-1] )
1445 or warn "Failed to remove $filename: $!"
1448 # commit the pending cache lines to the actual cache, now that
1449 # we've printed our output
1450 %tweet_cache = ( %tweet_cache, %new_cache );
1452 # keep enough cached tweets, to make sure we don't show duplicates.
1453 foreach ( keys %tweet_cache ) {
1454 next if $tweet_cache{$_} >= $last_poll - 3600;
1455 delete $tweet_cache{$_};
1457 $last_poll = $new_last_poll;
1459 # make sure the pid is removed from the waitpid list
1460 Irssi::pidwait_remove($child_pid);
1462 # and that we don't leave any zombies behind, somehow
1468 Irssi::settings_get_str("twirssi_replies_store") )
1470 if ( open JSON, ">$file" ) {
1471 print JSON JSON::Any->objToJson( \%id_map );
1474 &ccrap("Failed to write replies to $file: $!");
1485 if ( $attempt < 24 ) {
1486 Irssi::timeout_add_once( 5000, 'monitor_child',
1487 [ $filename, $attempt + 1 ] );
1489 print "Giving up on polling $filename" if &debug;
1490 Irssi::pidwait_remove($child_pid);
1492 unlink $filename unless &debug;
1494 return unless Irssi::settings_get_bool("twirssi_notify_timeouts");
1497 my @time = localtime($last_poll);
1498 if ( time - $last_poll < 24 * 60 * 60 ) {
1499 $since = sprintf( "%d:%02d", @time[ 2, 1 ] );
1501 $since = scalar localtime($last_poll);
1504 if ( not $failwhale and time - $last_poll > 60 * 60 ) {
1509 q{ .--./ / | _.---.| },
1518 if ( time - $last_poll < 600 ) {
1519 &ccrap("Haven't been able to get updated tweets since $since");
1525 return Irssi::settings_get_bool("twirssi_debug");
1529 foreach my $msg (@_) {
1530 $window->print( "%R***%n $msg", MSGLEVEL_PUBLIC );
1535 foreach my $msg (@_) {
1536 $window->print( "%R***%n $msg", MSGLEVEL_CLIENTCRAP );
1543 if ( Irssi::settings_get_bool("tweet_to_away")
1545 and $data !~ /^[dD] / )
1548 Irssi::server_find_tag( Irssi::settings_get_str("bitlbee_server") );
1550 $server->send_raw("away :$data");
1553 &ccrap( "Can't find bitlbee server.",
1554 "Update bitlbee_server or disable tweet_to_away" );
1564 my $noalert = shift;
1566 if ( length $data > 140 ) {
1567 ¬ice( "Tweet too long (" . length($data) . " characters) - aborted" )
1575 sub valid_username {
1576 my $username = shift;
1578 $username = &normalize_username($username);
1580 unless ( exists $twits{$username} ) {
1581 ¬ice("Unknown username $username");
1591 ¬ice("Not logged in! Use /twitter_login username pass!");
1599 my ( $complist, $window, $word, $linestart, $want_space ) = @_;
1602 $linestart =~ /^\/(?:retweet|twitter_reply)(?:_as)?\s*$/
1603 or ( Irssi::settings_get_bool("twirssi_use_reply_aliases")
1604 and $linestart =~ /^\/reply(?:_as)?\s*$/ )
1606 { # /twitter_reply gets a nick:num
1608 @$complist = map { "$_:$id_map{__indexes}{$_}" }
1609 sort { $nicks{$b} <=> $nicks{$a} }
1611 keys %{ $id_map{__indexes} };
1615 /^\/(twitter_unfriend|twitter_add_follow_extra|twitter_del_follow_extra)\s*$/
1617 { # /twitter_unfriend gets a nick
1619 push @$complist, grep /^\Q$word/i,
1620 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1623 # /tweet, /tweet_as, /dm, /dm_as - complete @nicks (and nicks as the first
1625 if ( $linestart =~ /^\/(?:tweet|dm)/ ) {
1626 my $prefix = $word =~ s/^@//;
1627 $prefix = 0 if $linestart eq '/dm' or $linestart eq '/dm_as';
1628 push @$complist, grep /^\Q$word/i,
1629 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1630 @$complist = map { "\@$_" } @$complist if $prefix;
1634 sub event_send_text {
1635 my ( $line, $server, $win ) = @_;
1636 my $awin = Irssi::active_win();
1638 # if the window where we got our text was the twitter window, and the user
1639 # wants to be lazy, tweet away!
1640 if ( ( $awin->get_active_name() eq $window->{name} )
1641 and Irssi::settings_get_bool("tweet_window_input") )
1643 &cmd_tweet( $line, $server, $win );
1648 my $poll = Irssi::settings_get_int("twitter_poll_interval");
1649 return $poll if $poll >= 60;
1656 if ( Irssi::settings_get_str("twirssi_nick_color") ) {
1657 my $c = Irssi::settings_get_str("twirssi_nick_color");
1658 $c = $irssi_to_mirc_colors{$c};
1659 $text =~ s/(^|\W)\@(\w+)/$1\cC$c\@$2\cO/g if $c;
1661 if ( Irssi::settings_get_str("twirssi_topic_color") ) {
1662 my $c = Irssi::settings_get_str("twirssi_topic_color");
1663 $c = $irssi_to_mirc_colors{$c};
1664 $text =~ s/(^|\W)(\#|\!)([-\w]+)/$1\cC$c$2$3\cO/g if $c;
1666 $text =~ s/[\n\r]/ /g;
1674 my $provider = Irssi::settings_get_str("short_url_provider");
1677 Irssi::settings_get_bool("twirssi_always_shorten")
1678 or &too_long( $data, 1 )
1684 if ( $provider eq 'Bitly' ) {
1685 @args[ 1, 2 ] = split ',',
1686 Irssi::settings_get_str("short_url_args"), 2;
1687 unless ( @args == 3 ) {
1689 "WWW::Shorten::Bitly requires a username and API key.",
1690 "Set short_url_args to username,API_key or change your",
1691 "short_url_provider."
1693 return decode "utf8", $data;
1697 foreach my $url ( $data =~ /(https?:\/\/\S+[\w\/])/g ) {
1700 my $short = makeashorterlink(@args);
1702 $data =~ s/\Q$url/$short/g;
1704 ¬ice("Failed to shorten $url!");
1710 return decode "utf8", $data;
1713 sub normalize_username {
1716 my ( $username, $service ) = split /\@/, $user, 2;
1718 $service = ucfirst lc $service;
1721 ucfirst lc Irssi::settings_get_str("twirssi_default_service");
1722 unless ( exists $twits{"$username\@$service"} ) {
1724 foreach my $t ( sort keys %twits ) {
1725 next unless $t =~ /^\Q$username\E\@(Twitter|Identica)/;
1731 ¬ice("Can't find a logged in user '$user'");
1736 return "$username\@$service";
1742 my $text = decode_entities( $tweet->{text} );
1743 if ( $tweet->{truncated} ) {
1744 if ( exists $tweet->{retweeted_status} ) {
1745 $text = "RT \@$tweet->{retweeted_status}{user}{screen_name}: "
1746 . "$tweet->{retweeted_status}{text}";
1747 } elsif ( $object->isa('Net::Twitter::Lite') ) {
1748 $text .= " -- http://twitter.com/$tweet->{user}{screen_name}"
1749 . "/status/$tweet->{id}";
1753 $text =~ s/[\n\r]/ /g;
1758 Irssi::signal_add( "send text", "event_send_text" );
1760 Irssi::theme_register(
1762 'twirssi_tweet', '[$0%B@$1%n$2] $3',
1763 'twirssi_search', '[$0%r$1%n:%B@$2%n$3] $4',
1764 'twirssi_reply', '[$0\--> %B@$1%n$2] $3',
1765 'twirssi_dm', '[$0%r@$1%n (%WDM%n)] $2',
1766 'twirssi_error', 'ERROR: $0',
1770 Irssi::settings_add_int( "twirssi", "twitter_poll_interval", 300 );
1771 Irssi::settings_add_str( "twirssi", "twitter_window", "twitter" );
1772 Irssi::settings_add_str( "twirssi", "bitlbee_server", "bitlbee" );
1773 Irssi::settings_add_str( "twirssi", "short_url_provider", "TinyURL" );
1774 Irssi::settings_add_str( "twirssi", "short_url_args", undef );
1775 Irssi::settings_add_str( "twirssi", "twitter_usernames", undef );
1776 Irssi::settings_add_str( "twirssi", "twitter_passwords", undef );
1777 Irssi::settings_add_str( "twirssi", "twirssi_default_service", "Twitter" );
1778 Irssi::settings_add_str( "twirssi", "twirssi_nick_color", "%B" );
1779 Irssi::settings_add_str( "twirssi", "twirssi_topic_color", "%r" );
1780 Irssi::settings_add_str( "twirssi", "twirssi_retweet_format",
1781 'RT $n: "$t" ${-- $c$}' );
1782 Irssi::settings_add_str( "twirssi", "twirssi_location",
1783 Irssi::get_irssi_dir . "/scripts/twirssi.pl" );
1784 Irssi::settings_add_str( "twirssi", "twirssi_replies_store",
1785 Irssi::get_irssi_dir . "/scripts/twirssi.json" );
1786 Irssi::settings_add_str( "twirssi", "twirssi_oauth_store",
1787 Irssi::get_irssi_dir . "/scripts/twirssi.oauth" );
1789 Irssi::settings_add_int( "twirssi", "twitter_friends_poll", 600 );
1790 Irssi::settings_add_int( "twirssi", "twitter_timeout", 30 );
1792 Irssi::settings_add_bool( "twirssi", "twirssi_upgrade_beta", 0 );
1793 Irssi::settings_add_bool( "twirssi", "tweet_to_away", 0 );
1794 Irssi::settings_add_bool( "twirssi", "show_reply_context", 0 );
1795 Irssi::settings_add_bool( "twirssi", "show_own_tweets", 1 );
1796 Irssi::settings_add_bool( "twirssi", "twirssi_debug", 0 );
1797 Irssi::settings_add_bool( "twirssi", "twirssi_first_run", 1 );
1798 Irssi::settings_add_bool( "twirssi", "twirssi_track_replies", 1 );
1799 Irssi::settings_add_bool( "twirssi", "twirssi_replies_autonick", 1 );
1800 Irssi::settings_add_bool( "twirssi", "twirssi_use_reply_aliases", 0 );
1801 Irssi::settings_add_bool( "twirssi", "twirssi_notify_timeouts", 1 );
1802 Irssi::settings_add_bool( "twirssi", "twirssi_hilights", 1 );
1803 Irssi::settings_add_bool( "twirssi", "twirssi_always_shorten", 0 );
1804 Irssi::settings_add_bool( "twirssi", "tweet_window_input", 0 );
1805 Irssi::settings_add_bool( "twirssi", "twirssi_avoid_ssl", 0 );
1806 Irssi::settings_add_bool( "twirssi", "twirssi_use_oauth", 1 );
1808 $last_poll = time - &get_poll_time;
1809 $window = Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
1812 ->print( "Couldn't find a window named '"
1813 . Irssi::settings_get_str('twitter_window')
1814 . "', trying to create it." );
1816 Irssi::Windowitem::window_create(
1817 Irssi::settings_get_str('twitter_window'), 1 );
1818 $window->set_name( Irssi::settings_get_str('twitter_window') );
1822 Irssi::command_bind( "dm", "cmd_direct" );
1823 Irssi::command_bind( "dm_as", "cmd_direct_as" );
1824 Irssi::command_bind( "tweet", "cmd_tweet" );
1825 Irssi::command_bind( "tweet_as", "cmd_tweet_as" );
1826 Irssi::command_bind( "retweet", "cmd_retweet" );
1827 Irssi::command_bind( "retweet_as", "cmd_retweet_as" );
1828 Irssi::command_bind( "twitter_reply", "cmd_reply" );
1829 Irssi::command_bind( "twitter_reply_as", "cmd_reply_as" );
1830 Irssi::command_bind( "twitter_login", "cmd_login" );
1831 Irssi::command_bind( "twitter_logout", "cmd_logout" );
1832 Irssi::command_bind( "twitter_switch", "cmd_switch" );
1833 Irssi::command_bind( "twitter_subscribe", "cmd_add_search" );
1834 Irssi::command_bind( "twitter_unsubscribe", "cmd_del_search" );
1835 Irssi::command_bind( "twitter_list_subscriptions", "cmd_list_search" );
1836 Irssi::command_bind( "twirssi_upgrade", "cmd_upgrade" );
1837 Irssi::command_bind( "twirssi_oauth", "cmd_oauth" );
1838 Irssi::command_bind( "twitter_updates", "get_updates" );
1839 Irssi::command_bind( "twitter_add_follow_extra", "cmd_add_follow" );
1840 Irssi::command_bind( "twitter_del_follow_extra", "cmd_del_follow" );
1841 Irssi::command_bind( "twitter_list_follow_extra", "cmd_list_follow" );
1842 Irssi::command_bind( "bitlbee_away", "update_away" );
1843 if ( Irssi::settings_get_bool("twirssi_use_reply_aliases") ) {
1844 Irssi::command_bind( "reply", "cmd_reply" );
1845 Irssi::command_bind( "reply_as", "cmd_reply_as" );
1847 Irssi::command_bind(
1850 print "twits: ", join ", ",
1851 map { "u: $_->{username}\@" . ref($_) } values %twits;
1852 print "selected: $user\@$defservice";
1853 print "friends: ", join ", ", sort keys %friends;
1854 print "nicks: ", join ", ", sort keys %nicks;
1855 print "searches: ", Dumper \%{ $id_map{__searches} };
1856 print "last poll: $last_poll";
1857 if ( open DUMP, ">/tmp/twirssi.cache.txt" ) {
1858 print DUMP Dumper \%tweet_cache;
1860 print "cache written out to /tmp/twirssi.cache.txt";
1864 Irssi::command_bind(
1868 "Twirssi v$VERSION; "
1870 $Net::Twitter::Lite::VERSION
1871 ? "Net::Twitter v$Net::Twitter::Lite::VERSION. "
1875 $Net::Identica::VERSION
1876 ? "Net::Identica v$Net::Identica::VERSION. "
1880 . JSON::Any::handler()
1881 . ". See details at http://twirssi.com/"
1885 Irssi::command_bind(
1888 "/twitter_follow <username>",
1890 sub { ¬ice("Following $_[0]"); $nicks{ $_[0] } = time; }
1893 Irssi::command_bind(
1896 "/twitter_unfriend <username>",
1898 sub { ¬ice("Stopped following $_[0]"); delete $nicks{ $_[0] }; }
1901 Irssi::command_bind(
1902 "twitter_device_updates",
1904 "/twitter_device_updates none|im|sms",
1905 "update_delivery_device",
1906 sub { ¬ice("Device updated to $_[0]"); }
1909 Irssi::command_bind(
1912 "/twitter_block <username>",
1914 sub { ¬ice("Blocked $_[0]"); }
1917 Irssi::command_bind(
1920 "/twitter_unblock <username>",
1922 sub { ¬ice("Unblock $_[0]"); }
1925 Irssi::signal_add_last( 'complete word' => \&sig_complete );
1927 ¬ice(" %Y<%C(%B^%C)%N TWIRSSI v%R$VERSION%N",
1928 " %C(_(\\%N http://twirssi.com/ for full docs",
1929 " %Y||%C `%N Log in with /twitter_login, send updates with /tweet");
1931 my $file = Irssi::settings_get_str("twirssi_replies_store");
1932 if ( $file and -r $file ) {
1933 if ( open( JSON, $file ) ) {
1938 my $ref = JSON::Any->jsonToObj($json);
1940 my $num = keys %{ $id_map{__indexes} };
1941 ¬ice( sprintf "Loaded old replies from %d contact%s.",
1942 $num, ( $num == 1 ? "" : "s" ) );
1947 ¬ice("Failed to load old replies from $file: $!");
1951 if ( my $provider = Irssi::settings_get_str("short_url_provider") ) {
1952 ¬ice("Loading WWW::Shorten::$provider...");
1953 eval "use WWW::Shorten::$provider;";
1957 "Failed to load WWW::Shorten::$provider - either clear",
1958 "short_url_provider or install the CPAN module"
1963 if ( my $autouser = Irssi::settings_get_str("twitter_usernames") ) {
1970 ->print( "Create a window named "
1971 . Irssi::settings_get_str('twitter_window')
1972 . " or change the value of twitter_window. Then, reload twirssi." );
1975 # vim: set sts=4 expandtab: