10 use POSIX qw/:sys_wait_h/;
11 $Data::Dumper::Indent = 1;
13 use vars qw($VERSION %IRSSI);
15 $VERSION = "2.4.0beta";
17 authors => 'Dan Boger',
18 contact => 'zigdon@gmail.com',
20 description => 'Send twitter updates using /tweet. '
21 . 'Can optionally set your bitlbee /away message to same',
22 license => 'GNU GPL v2',
23 url => 'http://twirssi.com',
24 changed => '$Date: 2009-08-07 01:24:53 -0700 (Fri, 07 Aug 2009) $',
35 my $last_friends_poll = 0;
43 my %fix_replies_index;
45 my %irssi_to_mirc_colors = (
65 my ( $data, $server, $win ) = @_;
67 return unless &logged_in($twit);
69 my ( $target, $text ) = split ' ', $data, 2;
70 unless ( $target and $text ) {
71 ¬ice("Usage: /dm <nick> <message>");
75 &cmd_direct_as( "$user $data", $server, $win );
79 my ( $data, $server, $win ) = @_;
81 return unless &logged_in($twit);
83 my ( $username, $target, $text ) = split ' ', $data, 3;
84 unless ( $username and $target and $text ) {
85 ¬ice("Usage: /dm_as <username> <nick> <message>");
89 return unless $username = &valid_username($username);
92 if ( $twits{$username}
93 ->new_direct_message( { user => $target, text => $text } ) )
95 ¬ice("DM sent to $target: $text");
96 $nicks{$target} = time;
100 $error = JSON::Any->jsonToObj( $twits{$username}->get_error() );
101 $error = $error->{error};
103 die $error if $error;
104 ¬ice("DM to $target failed");
109 ¬ice("DM caused an error: $@");
115 my ( $data, $server, $win ) = @_;
117 return unless &logged_in($twit);
119 $data =~ s/^\s+|\s+$//;
121 ¬ice("Usage: /retweet <nick[:num]> [comment]");
125 my ( $id, $data ) = split ' ', $data, 2;
127 &cmd_retweet_as( "$user $id $data", $server, $win );
131 my ( $data, $server, $win ) = @_;
133 unless ( Irssi::settings_get_bool("twirssi_track_replies") ) {
134 ¬ice("twirssi_track_replies is required in order to reteet.");
138 return unless &logged_in($twit);
140 $data =~ s/^\s+|\s+$//;
141 my ( $username, $id, $data ) = split ' ', $data, 3;
144 ¬ice("Usage: /retweet_as <username> <nick[:num]> [comment]");
148 return unless $username = &valid_username($username);
151 $id =~ s/[^\w\d\-:]+//g;
152 ( $nick, $id ) = split /:/, $id;
153 unless ( exists $id_map{ lc $nick } ) {
154 ¬ice("Can't find a tweet from $nick to retweet!");
158 $id = $id_map{__indexes}{$nick} unless $id;
159 unless ( $id_map{ lc $nick }[$id] ) {
160 ¬ice("Can't find a tweet numbered $id from $nick to retweet!");
164 unless ( $id_map{__tweets}{ lc $nick }[$id] ) {
165 ¬ice("The text of this tweet isn't saved, sorry!");
169 # Irssi::settings_add_str( "twirssi", "twirssi_retweet_format", 'RT $n: $t ${-- $c$}' );
170 my $text = Irssi::settings_get_str("twirssi_retweet_format");
171 $text =~ s/\$n/\@$nick/g;
173 $text =~ s/\${|\$}//g;
174 $text =~ s/\$c/$data/;
176 $text =~ s/\${.*?\$}//;
178 $text =~ s/\$t/$id_map{__tweets}{ lc $nick }[$id]/;
180 my $modified = $data;
181 $data = &shorten($text);
183 return if $modified and &too_long($data);
189 $success = $twits{$username}->update(
193 # in_reply_to_status_id => $id_map{ lc $nick }[$id]
198 $twits{$username}->retweet( { id => $id_map{ lc $nick }[$id] } );
199 $success = $success->{id} if ref $success;
201 ¬ice("Update failed") unless $success;
203 return unless $success;
206 ¬ice("Update caused an error: $@. Aborted");
210 foreach ( $data =~ /@([-\w]+)/ ) {
214 ¬ice("Retweet sent");
218 my ( $data, $server, $win ) = @_;
220 return unless &logged_in($twit);
222 $data =~ s/^\s+|\s+$//;
224 ¬ice("Usage: /tweet <update>");
228 &cmd_tweet_as( "$user\@$defservice $data", $server, $win );
232 my ( $data, $server, $win ) = @_;
234 return unless &logged_in($twit);
236 $data =~ s/^\s+|\s+$//;
237 $data =~ s/\s\s+/ /g;
238 my ( $username, $data ) = split ' ', $data, 2;
240 unless ( $username and $data ) {
241 ¬ice("Usage: /tweet_as <username> <update>");
245 return unless $username = &valid_username($username);
247 $data = &shorten($data);
249 return if &too_long($data);
253 unless ( $twits{$username}->update($data) )
255 ¬ice("Update failed");
259 return unless $success;
262 ¬ice("Update caused an error: $@. Aborted.");
266 foreach ( $data =~ /@([-\w]+)/ ) {
270 my $away = &update_away($data);
272 ¬ice( "Update sent" . ( $away ? " (and away msg set)" : "" ) );
276 my ( $data, $server, $win ) = @_;
278 return unless &logged_in($twit);
280 $data =~ s/^\s+|\s+$//;
282 ¬ice("Usage: /reply <nick[:num]> <update>");
286 my ( $id, $data ) = split ' ', $data, 2;
287 unless ( $id and $data ) {
288 ¬ice("Usage: /reply <nick[:num]> <update>");
292 &cmd_reply_as( "$user $id $data", $server, $win );
296 my ( $data, $server, $win ) = @_;
298 unless ( Irssi::settings_get_bool("twirssi_track_replies") ) {
299 ¬ice("twirssi_track_replies is required in order to reply to "
300 . "specific tweets. Either enable it, or just use /tweet "
301 . "\@username <text>." );
305 return unless &logged_in($twit);
307 $data =~ s/^\s+|\s+$//;
308 my ( $username, $id, $data ) = split ' ', $data, 3;
310 unless ( $username and $data ) {
311 ¬ice("Usage: /reply_as <username> <nick[:num]> <update>");
315 return unless $username = &valid_username($username);
318 $id =~ s/[^\w\d\-:]+//g;
319 ( $nick, $id ) = split /:/, $id;
320 unless ( exists $id_map{ lc $nick } ) {
321 ¬ice("Can't find a tweet from $nick to reply to!");
325 $id = $id_map{__indexes}{$nick} unless $id;
326 unless ( $id_map{ lc $nick }[$id] ) {
327 ¬ice("Can't find a tweet numbered $id from $nick to reply to!");
331 if ( Irssi::settings_get_bool("twirssi_replies_autonick") ) {
333 # remove any @nick at the beginning of the reply, as we'll add it anyway
334 $data =~ s/^\s*\@?$nick\s*//;
335 $data = "\@$nick " . $data;
338 $data = &shorten($data);
340 return if &too_long($data);
345 $twits{$username}->update(
348 in_reply_to_status_id => $id_map{ lc $nick }[$id]
353 ¬ice("Update failed");
357 return unless $success;
360 ¬ice("Update caused an error: $@. Aborted");
364 foreach ( $data =~ /@([-\w]+)/ ) {
368 my $away = &update_away($data);
370 ¬ice( "Update sent" . ( $away ? " (and away msg set)" : "" ) );
374 my ( $usage_str, $api_name, $post_ref ) = @_;
377 my ( $data, $server, $win ) = @_;
379 return unless &logged_in($twit);
381 $data =~ s/^\s+|\s+$//;
383 ¬ice("Usage: $usage_str");
389 unless ( $twit->$api_name($data) )
391 ¬ice("$api_name failed");
395 return unless $success;
398 ¬ice("$api_name caused an error. Aborted.");
402 &$post_ref($data) if $post_ref;
407 my ( $data, $server, $win ) = @_;
409 $data =~ s/^\s+|\s+$//g;
410 $data = &normalize_username($data);
411 if ( exists $twits{$data} ) {
412 ¬ice("Switching to $data");
413 $twit = $twits{$data};
414 if ( $data =~ /(.*)\@(.*)/ ) {
418 ¬ice("Couldn't figure out what service '$data' is on");
421 ¬ice("Unknown user $data");
426 my ( $data, $server, $win ) = @_;
428 $data =~ s/^\s+|\s+$//g;
429 $data = $user unless $data;
430 return unless $data = &valid_username($data);
432 ¬ice("Logging out $data...");
434 $twits{$data}->end_session();
436 delete $twits{$data};
439 &cmd_switch( ( keys %twits )[0], $server, $win );
441 Irssi::timeout_remove($poll) if $poll;
447 my ( $data, $server, $win ) = @_;
449 print "logging in: $data" if &debug;
451 print "manual data login" if &debug;
452 ( $user, $pass ) = split ' ', $data, 2;
453 unless (Irssi::settings_get_bool("twirssi_use_oauth") or $pass) {
454 ¬ice("usage: /twitter_login <username>[\@<service>] <password>");
457 } elsif ( Irssi::settings_get_bool("twirssi_use_oauth") and
458 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 print "Loading Net::$service" if &debug;
513 eval "use Net::$service 3.05";
516 "Failed to load Net::$service when trying to log in as $user: $@");
520 if ( Irssi::settings_get_bool("twirssi_use_oauth") ) {
521 print "Attempting OAuth for $user\@$service" if &debug;
523 $twit = "Net::$service"->new(
524 traits => [ 'API::REST', 'OAuth' ],
525 consumer_key => 'BZVAvBma4GxdiRwXIvbnw',
526 consumer_secret => '0T5kahwLyb34vciGZsgkA9lsjtGCQ05vxVE2APXM',
528 ssl => Irssi::settings_get_bool("twirssi_avoid_ssl") ? 0 : 1,
533 if (open( OAUTH, Irssi::settings_get_str("twirssi_oauth_store") ) ) {
536 next unless m/$user\@$service (\S+) (\S+)/i;
537 print "Trying cached oauth creds for $user\@$service" if &debug;
538 $twit->access_token($1);
539 $twit->access_token_secret($2);
545 unless ( $twit->authorized ) {
548 $url = $twit->get_authorization_url;
552 ¬ice("ERROR: Failed to get OAuth authorization_url. Try again later.");
556 ¬ice("Twirssi not autorized to access $service for $user.");
557 ¬ice("Please authorize at the following url, then enter the pin ");
558 ¬ice("supplied with /twirssi_oauth $user\@$service <pin>");
561 $oauth{pending}{"$user\@$service"} = $twit;
566 $twit = "Net::$service"->new(
570 ssl => Irssi::settings_get_bool("twirssi_avoid_ssl") ? 0 : 1,
575 ¬ice("Failed to create Net::$service object! Aborting.");
579 return &verify_twitter_object($server, $win, $user, $service, $twit);
583 my ($data, $server, $win) = @_;
584 my ( $key, $pin ) = split ' ', $data;
585 my ($user, $service);
586 $key = &normalize_username($key);
587 if ( $key =~ /^(.*)@(Twitter|Identica)$/ ) {
588 ( $user, $service ) = ( $1, $2 );
591 print "Applying pin to $key" if &debug;
593 unless ( exists $oauth{pending}{$key} ) {
594 ¬ice("There isn't a pending oauth request for $key. "
595 . "Try /twitter_login first" );
599 my $twit = $oauth{pending}{$key};
600 my ( $access_token, $access_token_secret );
602 ( $access_token, $access_token_secret ) =
603 $twit->request_access_token( verifier => $pin );
607 ¬ice("Invalid pin, try again.");
611 delete $oauth{pending}{$key};
613 my $store_file = Irssi::settings_get_str("twirssi_oauth_store");
616 if ( open( OAUTH, $store_file ) ) {
626 push @store, "$key $access_token $access_token_secret";
628 if ( open( OAUTH, ">$store_file.new" ) ) {
629 print OAUTH "$_\n" foreach @store;
631 rename "$store_file.new", $store_file
632 or ¬ice("Failed to rename $store_file.new: $!");
634 ¬ice("Failed to write $store_file.new: $!");
637 ¬ice("No persistant storage set for OAuth. "
638 . "Please /set twirssi_oauth_store to a writable filename." );
641 return &verify_twitter_object($server, $win, $user, $service, $twit);
644 sub verify_twitter_object {
645 my ($server, $win, $user, $service, $twit) = @_;
647 if ( my $timeout = Irssi::settings_get_int("twitter_timeout")
648 and $twit->can('ua') )
650 $twit->ua->timeout($timeout);
651 ¬ice("Twitter timeout set to $timeout");
654 unless ( $twit->verify_credentials() ) {
655 ¬ice("Login as $user\@$service failed");
657 if ( not Irssi::settings_get_bool("twirssi_avoid_ssl") ) {
659 "It's possible you're missing one of the modules required for "
660 . "SSL logins. Try setting twirssi_avoid_ssl to on. See "
661 . "http://cpansearch.perl.org/src/GAAS/libwww-perl-5.831/README.SSL "
662 . "for the detailed requirements." );
667 &cmd_switch( ( keys %twits )[0], $server, $win );
672 my $rate_limit = $twit->rate_limit_status();
673 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
675 "Rate limit exceeded, try again after $rate_limit->{reset_time}" );
680 print "saving object for $user\@$service" if &debug;
681 $twits{"$user\@$service"} = $twit;
682 Irssi::timeout_remove($poll) if $poll;
683 $poll = Irssi::timeout_add( &get_poll_time * 1000, \&get_updates, "" );
684 ¬ice("Logged in as $user\@$service, loading friends list...");
686 ¬ice( "loaded friends: ", scalar keys %friends );
687 if ( Irssi::settings_get_bool("twirssi_first_run") ) {
688 Irssi::settings_set_bool( "twirssi_first_run", 0 );
696 my ( $data, $server, $win ) = @_;
699 ¬ice("Usage: /twitter_add_follow_extra <username>");
703 $data =~ s/^\s+|\s+$//;
707 if ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
708 ¬ice("Already following all replies by \@$data");
712 $id_map{__fixreplies}{"$user\@$defservice"}{$data} = 1;
713 ¬ice("Will now follow all replies by \@$data");
717 my ( $data, $server, $win ) = @_;
720 ¬ice("Usage: /twitter_del_follow_extra <username>");
724 $data =~ s/^\s+|\s+$//;
728 unless ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
729 ¬ice("Wasn't following all replies by \@$data");
733 delete $id_map{__fixreplies}{"$user\@$defservice"}{$data};
734 ¬ice("Will no longer follow all replies by \@$data");
737 sub cmd_list_follow {
738 my ( $data, $server, $win ) = @_;
741 foreach my $suser ( sort keys %{ $id_map{__fixreplies} } ) {
743 foreach my $fruser ( sort keys %{ $id_map{__fixreplies}{$suser} } ) {
744 $frusers = $frusers ? "$frusers, $fruser" : $fruser;
748 ¬ice("Following all replies as \@$suser: $frusers");
753 ¬ice("Not following all replies by anyone");
758 my ( $data, $server, $win ) = @_;
760 unless ( $twit and $twit->can('search') ) {
761 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
762 . "doesn't support searches." );
766 $data =~ s/^\s+|\s+$//;
770 ¬ice("Usage: /twitter_subscribe <topic>");
774 if ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
775 ¬ice("Already had a subscription for '$data'");
779 $id_map{__searches}{"$user\@$defservice"}{$data} = 1;
780 ¬ice("Added subscription for '$data'");
784 my ( $data, $server, $win ) = @_;
786 unless ( $twit and $twit->can('search') ) {
787 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
788 . "doesn't support searches." );
791 $data =~ s/^\s+|\s+$//;
795 ¬ice("Usage: /twitter_unsubscribe <topic>");
799 unless ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
800 ¬ice("No subscription found for '$data'");
804 delete $id_map{__searches}{"$user\@$defservice"}{$data};
805 ¬ice("Removed subscription for '$data'");
808 sub cmd_list_search {
809 my ( $data, $server, $win ) = @_;
812 foreach my $suser ( sort keys %{ $id_map{__searches} } ) {
814 foreach my $topic ( sort keys %{ $id_map{__searches}{$suser} } ) {
815 $topics = $topics ? "$topics, $topic" : $topic;
819 ¬ice("Search subscriptions for \@$suser: $topics");
824 ¬ice("No search subscriptions set up");
829 my ( $data, $server, $win ) = @_;
831 my $loc = Irssi::settings_get_str("twirssi_location");
833 ¬ice("$loc isn't writable, can't upgrade."
834 . " Perhaps you need to /set twirssi_location?" );
839 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
840 eval { use Digest::MD5; };
843 ¬ice("Failed to load Digest::MD5."
844 . " Try '/twirssi_upgrade nomd5' to skip MD5 verification" );
848 $md5 = get("http://twirssi.com/md5sum");
852 ¬ice("Failed to download md5sum from peeron! Aborting.");
856 unless ( open( CUR, $loc ) ) {
857 ¬ice("Failed to read $loc."
858 . " Check that /set twirssi_location is set to the correct location."
863 my $cur_md5 = Digest::MD5::md5_hex(<CUR>);
866 if ( $cur_md5 eq $md5 ) {
867 ¬ice("Current twirssi seems to be up to date.");
873 Irssi::settings_get_bool("twirssi_upgrade_beta")
874 ? "http://github.com/zigdon/twirssi/raw/master/twirssi.pl"
875 : "http://twirssi.com/twirssi.pl";
876 ¬ice("Downloading twirssi from $URL");
877 LWP::Simple::getstore( $URL, "$loc.upgrade" );
879 unless ( -s "$loc.upgrade" ) {
880 ¬ice("Failed to save $loc.upgrade."
881 . " Check that /set twirssi_location is set to the correct location."
886 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
887 unless ( open( NEW, "$loc.upgrade" ) ) {
888 ¬ice("Failed to read $loc.upgrade."
889 . " Check that /set twirssi_location is set to the correct location."
894 my $new_md5 = Digest::MD5::md5_hex(<NEW>);
897 if ( $new_md5 ne $md5 ) {
898 ¬ice("MD5 verification failed. expected $md5, got $new_md5");
903 rename $loc, "$loc.backup"
904 or ¬ice("Failed to back up $loc: $!. Aborting")
906 rename "$loc.upgrade", $loc
907 or ¬ice("Failed to rename $loc.upgrade: $!. Aborting")
910 my ( $dir, $file ) = ( $loc =~ m{(.*)/([^/]+)$} );
911 if ( -e "$dir/autorun/$file" ) {
912 ¬ice("Updating $dir/autorun/$file");
913 unlink "$dir/autorun/$file"
914 or ¬ice("Failed to remove old $file from autorun: $!");
915 symlink "../$file", "$dir/autorun/$file"
916 or ¬ice("Failed to create symlink in autorun directory: $!");
919 ¬ice("Download complete. Reload twirssi with /script load $file");
928 while ( $page < 11 and $cursor ne "0" )
930 print $fh "type:debug Loading friends page $page...\n"
931 if ( $fh and &debug );
933 if ( ref $twit =~ /^Net::Twitter/ ) {
934 $friends = $twit->friends( { cursor => $cursor } );
935 last unless $friends;
936 $cursor = $friends->{next_cursor};
937 $friends = $friends->{users};
939 $friends = $twit->friends( { page => $page } );
940 last unless $friends;
942 $new_friends{ $_->{screen_name} } = time foreach @$friends;
948 print $fh "type:debug Error during friends list update. Aborted.\n";
952 my ( $added, $removed ) = ( 0, 0 );
953 print $fh "type:debug Scanning for new friends...\n" if ( $fh and &debug );
954 foreach ( keys %new_friends ) {
955 next if exists $friends{$_};
960 print $fh "type:debug Scanning for removed friends...\n"
961 if ( $fh and &debug );
962 foreach ( keys %friends ) {
963 next if exists $new_friends{$_};
968 return ( $added, $removed );
972 print scalar localtime, " - get_updates starting" if &debug;
975 Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
978 ->print( "Can't find a window named '"
979 . Irssi::settings_get_str('twitter_window')
980 . "'. Create it or change the value of twitter_window" );
983 return unless &logged_in($twit);
985 my ( $fh, $filename ) = File::Temp::tempfile();
986 binmode( $fh, ":utf8" );
989 if ($child_pid) { # parent
990 Irssi::timeout_add_once( 5000, 'monitor_child',
991 [ "$filename.done", 0 ] );
992 Irssi::pidwait_add($child_pid);
993 } elsif ( defined $child_pid ) { # child
1002 foreach ( keys %twits ) {
1003 $error++ unless &do_updates( $fh, $_, $twits{$_}, \%context_cache );
1005 if ( $id_map{__fixreplies}{$_} ) {
1006 my @frusers = sort keys %{ $id_map{__fixreplies}{$_} };
1009 unless &get_timeline( $fh, $frusers[ $fix_replies_index{$_} ],
1010 $_, $twits{$_}, \%context_cache );
1012 $fix_replies_index{$_}++;
1013 $fix_replies_index{$_} = 0
1014 if $fix_replies_index{$_} >= @frusers;
1015 print $fh "id:$fix_replies_index{$_} ",
1016 "account:$_ type:fix_replies_index\n";
1020 print $fh "__friends__\n";
1022 time - $last_friends_poll >
1023 Irssi::settings_get_int('twitter_friends_poll') )
1025 print $fh "__updated ", time, "\n";
1026 my ( $added, $removed ) = &load_friends($fh);
1027 if ( $added + $removed ) {
1028 print $fh "type:debug %R***%n Friends list updated: ",
1030 sprintf( "%d added", $added ),
1031 sprintf( "%d removed", $removed ) ),
1036 foreach ( sort keys %friends ) {
1037 print $fh "$_ $friends{$_}\n";
1041 print $fh "type:debug Update encountered errors. Aborted\n";
1042 print $fh "-- $last_poll";
1044 print $fh "-- $new_poll";
1047 rename $filename, "$filename.done";
1050 &ccrap("Failed to fork for updating: $!");
1052 print scalar localtime, " - get_updates ends" if &debug;
1056 my ( $fh, $username, $obj, $cache ) = @_;
1059 my $rate_limit = $obj->rate_limit_status();
1060 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
1061 ¬ice("Rate limit exceeded for $username");
1066 print scalar localtime, " - Polling for updates for $username" if &debug;
1068 my $new_poll_id = 0;
1070 if ( $id_map{__last_id}{$username}{timeline} )
1072 $tweets = $obj->home_timeline( { count => 100 } );
1074 $tweets = $obj->home_timeline();
1079 print $fh "type:debug Error during home_timeline call: Aborted.\n";
1080 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1084 unless ( ref $tweets ) {
1085 if ( $obj->can("get_error") ) {
1086 my $error = "Unknown error";
1087 eval { $error = JSON::Any->jsonToObj( $obj->get_error() ) };
1088 unless ($@) { $error = $obj->get_error() }
1090 "type:debug API Error during home_timeline call: Aborted\n";
1091 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($error);
1095 "type:debug API Error during home_timeline call. Aborted.\n";
1100 foreach my $t ( reverse @$tweets ) {
1101 my $text = &get_text( $t, $obj );
1102 my $reply = "tweet";
1103 if ( Irssi::settings_get_bool("show_reply_context")
1104 and $t->{in_reply_to_screen_name} ne $username
1105 and $t->{in_reply_to_screen_name}
1106 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1108 $nicks{ $t->{in_reply_to_screen_name} } = time;
1110 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1112 $cache->{ $t->{in_reply_to_status_id} } =
1113 $obj->show_status( $t->{in_reply_to_status_id} );
1117 $context = $cache->{ $t->{in_reply_to_status_id} };
1120 my $ctext = &get_text( $context, $obj );
1121 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1122 $context->{id}, $username,
1123 $context->{user}{screen_name}, $ctext;
1128 if $t->{user}{screen_name} eq $username
1129 and not Irssi::settings_get_bool("show_own_tweets");
1130 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1131 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1132 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1134 printf $fh "id:%s account:%s type:last_id timeline\n",
1135 $new_poll_id, $username;
1137 print scalar localtime, " - Polling for replies since ",
1138 $id_map{__last_id}{$username}{reply}
1142 if ( $id_map{__last_id}{$username}{reply} )
1144 $tweets = $obj->replies(
1145 { since_id => $id_map{__last_id}{$username}{reply} } )
1148 $tweets = $obj->replies() || [];
1153 print $fh "type:debug Error during replies call. Aborted.\n";
1157 foreach my $t ( reverse @$tweets ) {
1159 if exists $friends{ $t->{user}{screen_name} };
1161 my $text = &get_text( $t, $obj );
1162 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1163 $t->{id}, $username, $t->{user}{screen_name}, $text;
1164 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1166 printf $fh "id:%s account:%s type:last_id reply\n", $new_poll_id, $username;
1168 print scalar localtime, " - Polling for DMs" if &debug;
1171 if ( $id_map{__last_id}{$username}{dm} )
1173 $tweets = $obj->direct_messages(
1174 { since_id => $id_map{__last_id}{$username}{dm} } )
1177 $tweets = $obj->direct_messages() || [];
1182 print $fh "type:debug Error during direct_messages call. Aborted.\n";
1186 foreach my $t ( reverse @$tweets ) {
1187 my $text = decode_entities( $t->{text} );
1188 $text =~ s/[\n\r]/ /g;
1189 printf $fh "id:%s account:%s nick:%s type:dm %s\n",
1190 $t->{id}, $username, $t->{sender_screen_name}, $text;
1191 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1193 printf $fh "id:%s account:%s type:last_id dm\n", $new_poll_id, $username;
1195 print scalar localtime, " - Polling for subscriptions" if &debug;
1196 if ( $obj->can('search') and $id_map{__searches}{$username} ) {
1198 foreach my $topic ( sort keys %{ $id_map{__searches}{$username} } ) {
1199 print $fh "type:debug searching for $topic since ",
1200 "$id_map{__searches}{$username}{$topic}\n";
1202 $search = $obj->search(
1205 since_id => $id_map{__searches}{$username}{$topic}
1212 "type:debug Error during search($topic) call. Aborted.\n";
1216 unless ( $search->{max_id} ) {
1217 print $fh "type:debug Invalid search results when searching",
1218 " for $topic. Aborted.\n";
1222 $id_map{__searches}{$username}{$topic} = $search->{max_id};
1223 printf $fh "id:%s account:%s type:searchid topic:%s\n",
1224 $search->{max_id}, $username, $topic;
1226 foreach my $t ( reverse @{ $search->{results} } ) {
1227 my $text = &get_text( $t, $obj );
1228 printf $fh "id:%s account:%s nick:%s type:search topic:%s %s\n",
1229 $t->{id}, $username, $t->{from_user}, $topic, $text;
1230 $new_poll_id = $t->{id}
1232 or $t->{id} < $new_poll_id;
1237 print scalar localtime, " - Done" if &debug;
1243 my ( $fh, $target, $username, $obj, $cache ) = @_;
1245 my $last_id = $id_map{__last_id}{$username}{$target};
1247 print $fh "type:debug get_timeline("
1248 . "$fix_replies_index{$username}=$target > $last_id) started."
1249 . " username = $username\n";
1251 $tweets = $obj->user_timeline(
1254 ( $last_id ? ( since_id => $last_id ) : () ),
1261 "type:debug Error during user_timeline($target) call: Aborted.\n";
1262 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1268 "type:debug user_timeline($target) call returned undef! Aborted\n";
1272 foreach my $t ( reverse @$tweets ) {
1273 my $text = &get_text( $t, $obj );
1274 my $reply = "tweet";
1275 if ( Irssi::settings_get_bool("show_reply_context")
1276 and $t->{in_reply_to_screen_name} ne $username
1277 and $t->{in_reply_to_screen_name}
1278 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1280 $nicks{ $t->{in_reply_to_screen_name} } = time;
1282 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1284 $cache->{ $t->{in_reply_to_status_id} } =
1285 $obj->show_status( $t->{in_reply_to_status_id} );
1289 $context = $cache->{ $t->{in_reply_to_status_id} };
1292 my $ctext = &get_text( $context, $obj );
1293 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1294 $context->{id}, $username,
1295 $context->{user}{screen_name}, $ctext;
1299 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1300 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1301 $last_id = $t->{id} if $last_id < $t->{id};
1303 printf $fh "id:%s account:%s type:last_id_fixreplies %s\n",
1304 $last_id, $username, $target;
1311 my $filename = $data->[0];
1312 my $attempt = $data->[1];
1314 print scalar localtime, " - checking child log at $filename ($attempt)"
1316 my ($new_last_poll);
1318 # reap any random leftover processes - work around a bug in irssi on gentoo
1319 waitpid( -1, WNOHANG );
1321 # first time we run we don't want to print out *everything*, so we just
1324 if ( open FILE, $filename ) {
1325 binmode FILE, ":utf8";
1329 last if /^__friends__/;
1330 unless (/\n$/) { # skip partial lines
1331 # print "Skipping partial line: $_" if &debug;
1338 foreach my $key (qw/id account nick type topic/) {
1339 if (s/^$key:(\S+)\s*//) {
1344 if ( $meta{type} and $meta{type} eq 'fix_replies_index' ) {
1345 $fix_replies_index{ $meta{account} } = $meta{id};
1346 print "fix_replies_index for $meta{account} set to $meta{id}"
1351 if ( not $meta{type} or $meta{type} !~ /searchid|last_id/ ) {
1352 if ( exists $meta{id} and exists $new_cache{ $meta{id} } ) {
1356 $new_cache{ $meta{id} } = time;
1358 if ( exists $meta{id} and exists $tweet_cache{ $meta{id} } ) {
1364 $meta{account} =~ s/\@(\w+)$//;
1365 $meta{service} = $1;
1367 lc $meta{service} eq
1368 lc Irssi::settings_get_str("twirssi_default_service") )
1370 $account = "$meta{account}: "
1371 if lc "$meta{account}\@$meta{service}" ne lc
1372 "$user\@$defservice";
1374 $account = "$meta{account}\@$meta{service}: ";
1378 if ( $meta{type} ne 'dm'
1379 and Irssi::settings_get_bool("twirssi_track_replies")
1383 $marker = ( $id_map{__indexes}{ $meta{nick} } + 1 ) % 100;
1384 $id_map{ lc $meta{nick} }[$marker] = $meta{id};
1385 $id_map{__indexes}{ $meta{nick} } = $marker;
1386 $id_map{__tweets}{ lc $meta{nick} }[$marker] = $_;
1387 $marker = ":$marker";
1391 $irssi_to_mirc_colors{ Irssi::settings_get_str("hilight_color") };
1392 my $nick = "\@$meta{account}";
1393 if ( $_ =~ /\Q$nick\E(?:\W|$)/i
1394 and Irssi::settings_get_bool("twirssi_hilights") )
1396 $meta{nick} = "\cC$hilight_color$meta{nick}\cO";
1397 $hilight = MSGLEVEL_HILIGHT;
1400 if ( $meta{type} =~ /tweet|reply/ ) {
1403 ( MSGLEVEL_PUBLIC | $hilight ),
1404 $meta{type}, $account, $meta{nick}, $marker, $_
1406 } elsif ( $meta{type} eq 'search' ) {
1409 ( MSGLEVEL_PUBLIC | $hilight ),
1410 $meta{type}, $account, $meta{topic},
1411 $meta{nick}, $marker, $_
1414 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1416 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1418 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1421 } elsif ( $meta{type} eq 'dm' ) {
1424 ( MSGLEVEL_MSGS | $hilight ),
1425 $meta{type}, $account, $meta{nick}, $_
1427 } elsif ( $meta{type} eq 'searchid' ) {
1428 print "Search '$meta{topic}' returned id $meta{id}" if &debug;
1431 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1433 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1435 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1438 print "Search '$meta{topic}' returned invalid id $meta{id}";
1440 } elsif ( $meta{type} eq 'last_id' ) {
1441 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1443 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1445 } elsif ( $meta{type} eq 'last_id_fixreplies' ) {
1446 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1448 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1450 } elsif ( $meta{type} eq 'error' ) {
1451 push @lines, [ MSGLEVEL_MSGS, $_ ];
1452 } elsif ( $meta{type} eq 'debug' ) {
1453 print "$_" if &debug,;
1455 print "Unknown line type $meta{type}: $_" if &debug,;
1461 if (/^__updated (\d+)$/) {
1462 $last_friends_poll = $1;
1463 print "Friend list updated" if &debug;
1468 $new_last_poll = $1;
1469 if ( $new_last_poll >= $last_poll ) {
1472 print "Impossible! ",
1473 "new_last_poll=$new_last_poll < last_poll=$last_poll!"
1475 undef $new_last_poll;
1479 my ( $f, $t ) = split ' ', $_;
1480 $nicks{$f} = $friends{$f} = $t;
1483 if ($new_last_poll) {
1484 print "new last_poll = $new_last_poll" if &debug;
1485 print "new last_poll_id = ", Dumper( $id_map{__last_id} ) if &debug;
1487 print "First call, not printing updates" if &debug;
1489 foreach my $line (@lines) {
1490 $window->printformat(
1492 "twirssi_" . $line->[1],
1493 @$line[ 2 .. $#$line - 1 ],
1494 &hilight( $line->[-1] )
1501 or warn "Failed to remove $filename: $!"
1504 # commit the pending cache lines to the actual cache, now that
1505 # we've printed our output
1506 %tweet_cache = ( %tweet_cache, %new_cache );
1508 # keep enough cached tweets, to make sure we don't show duplicates.
1509 foreach ( keys %tweet_cache ) {
1510 next if $tweet_cache{$_} >= $last_poll - 3600;
1511 delete $tweet_cache{$_};
1513 $last_poll = $new_last_poll;
1515 # make sure the pid is removed from the waitpid list
1516 Irssi::pidwait_remove($child_pid);
1518 # and that we don't leave any zombies behind, somehow
1524 Irssi::settings_get_str("twirssi_replies_store") )
1526 if ( open JSON, ">$file" ) {
1527 print JSON JSON::Any->objToJson( \%id_map );
1530 &ccrap("Failed to write replies to $file: $!");
1541 if ( $attempt < 24 ) {
1542 Irssi::timeout_add_once( 5000, 'monitor_child',
1543 [ $filename, $attempt + 1 ] );
1545 print "Giving up on polling $filename" if &debug;
1546 Irssi::pidwait_remove($child_pid);
1548 unlink $filename unless &debug;
1550 return unless Irssi::settings_get_bool("twirssi_notify_timeouts");
1553 my @time = localtime($last_poll);
1554 if ( time - $last_poll < 24 * 60 * 60 ) {
1555 $since = sprintf( "%d:%02d", @time[ 2, 1 ] );
1557 $since = scalar localtime($last_poll);
1560 if ( not $failwhale and time - $last_poll > 60 * 60 ) {
1565 q{ .--./ / | _.---.| },
1577 if ( time - $last_poll < 600 ) {
1578 &ccrap("Haven't been able to get updated tweets since $since");
1584 return Irssi::settings_get_bool("twirssi_debug");
1588 $window->print( "%R***%n @_", MSGLEVEL_PUBLIC );
1592 $window->print( "%R***%n @_", MSGLEVEL_CLIENTCRAP );
1598 if ( Irssi::settings_get_bool("tweet_to_away")
1600 and $data !~ /^[dD] / )
1603 Irssi::server_find_tag( Irssi::settings_get_str("bitlbee_server") );
1605 $server->send_raw("away :$data");
1608 &ccrap( "Can't find bitlbee server.",
1609 "Update bitlbee_server or disable tweet_to_away" );
1619 my $noalert = shift;
1621 if ( length $data > 140 ) {
1622 ¬ice( "Tweet too long (" . length($data) . " characters) - aborted" )
1630 sub valid_username {
1631 my $username = shift;
1633 $username = &normalize_username($username);
1635 unless ( exists $twits{$username} ) {
1636 ¬ice("Unknown username $username");
1646 ¬ice("Not logged in! Use /twitter_login username pass!");
1654 my ( $complist, $window, $word, $linestart, $want_space ) = @_;
1657 $linestart =~ /^\/(?:retweet|twitter_reply)(?:_as)?\s*$/
1658 or ( Irssi::settings_get_bool("twirssi_use_reply_aliases")
1659 and $linestart =~ /^\/reply(?:_as)?\s*$/ )
1661 { # /twitter_reply gets a nick:num
1663 @$complist = map { "$_:$id_map{__indexes}{$_}" }
1664 sort { $nicks{$b} <=> $nicks{$a} }
1666 keys %{ $id_map{__indexes} };
1670 /^\/(twitter_unfriend|twitter_add_follow_extra|twitter_del_follow_extra)\s*$/
1672 { # /twitter_unfriend gets a nick
1674 push @$complist, grep /^\Q$word/i,
1675 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1678 # /tweet, /tweet_as, /dm, /dm_as - complete @nicks (and nicks as the first
1680 if ( $linestart =~ /^\/(?:tweet|dm)/ ) {
1681 my $prefix = $word =~ s/^@//;
1682 $prefix = 0 if $linestart eq '/dm' or $linestart eq '/dm_as';
1683 push @$complist, grep /^\Q$word/i,
1684 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1685 @$complist = map { "\@$_" } @$complist if $prefix;
1689 sub event_send_text {
1690 my ( $line, $server, $win ) = @_;
1691 my $awin = Irssi::active_win();
1693 # if the window where we got our text was the twitter window, and the user
1694 # wants to be lazy, tweet away!
1695 if ( ( $awin->get_active_name() eq $window->{name} )
1696 and Irssi::settings_get_bool("tweet_window_input") )
1698 &cmd_tweet( $line, $server, $win );
1703 my $poll = Irssi::settings_get_int("twitter_poll_interval");
1704 return $poll if $poll >= 60;
1711 if ( Irssi::settings_get_str("twirssi_nick_color") ) {
1712 my $c = Irssi::settings_get_str("twirssi_nick_color");
1713 $c = $irssi_to_mirc_colors{$c};
1714 $text =~ s/(^|\W)\@(\w+)/$1\cC$c\@$2\cO/g if $c;
1716 if ( Irssi::settings_get_str("twirssi_topic_color") ) {
1717 my $c = Irssi::settings_get_str("twirssi_topic_color");
1718 $c = $irssi_to_mirc_colors{$c};
1719 $text =~ s/(^|\W)(\#|\!)([-\w]+)/$1\cC$c$2$3\cO/g if $c;
1721 $text =~ s/[\n\r]/ /g;
1729 my $provider = Irssi::settings_get_str("short_url_provider");
1732 Irssi::settings_get_bool("twirssi_always_shorten")
1733 or &too_long( $data, 1 )
1739 if ( $provider eq 'Bitly' ) {
1740 @args[ 1, 2 ] = split ',',
1741 Irssi::settings_get_str("short_url_args"), 2;
1742 unless ( @args == 3 ) {
1744 "WWW::Shorten::Bitly requires a username and API key.",
1745 "Set short_url_args to username,API_key or change your",
1746 "short_url_provider."
1748 return decode "utf8", $data;
1752 foreach my $url ( $data =~ /(https?:\/\/\S+[\w\/])/g ) {
1755 my $short = makeashorterlink(@args);
1757 $data =~ s/\Q$url/$short/g;
1759 ¬ice("Failed to shorten $url!");
1765 return decode "utf8", $data;
1768 sub normalize_username {
1771 my ( $username, $service ) = split /\@/, $user, 2;
1773 $service = ucfirst lc $service;
1776 ucfirst lc Irssi::settings_get_str("twirssi_default_service");
1777 unless ( exists $twits{"$username\@$service"} ) {
1779 foreach my $t ( sort keys %twits ) {
1780 next unless $t =~ /^\Q$username\E\@(Twitter|Identica)/;
1786 ¬ice("Can't find a logged in user '$user'");
1791 return "$username\@$service";
1797 my $text = decode_entities( $tweet->{text} );
1798 if ( $tweet->{truncated} ) {
1799 if ( exists $tweet->{retweeted_status} ) {
1800 $text = "RT \@$tweet->{retweeted_status}{user}{screen_name}: "
1801 . "$tweet->{retweeted_status}{text}";
1802 } elsif ( $object->isa('Net::Twitter') ) {
1803 $text .= " -- http://twitter.com/$tweet->{user}{screen_name}"
1804 . "/status/$tweet->{id}";
1808 $text =~ s/[\n\r]/ /g;
1813 Irssi::signal_add( "send text", "event_send_text" );
1815 Irssi::theme_register(
1817 'twirssi_tweet', '[$0%B@$1%n$2] $3',
1818 'twirssi_search', '[$0%r$1%n:%B@$2%n$3] $4',
1819 'twirssi_reply', '[$0\--> %B@$1%n$2] $3',
1820 'twirssi_dm', '[$0%r@$1%n (%WDM%n)] $2',
1821 'twirssi_error', 'ERROR: $0',
1825 Irssi::settings_add_int( "twirssi", "twitter_poll_interval", 300 );
1826 Irssi::settings_add_str( "twirssi", "twitter_window", "twitter" );
1827 Irssi::settings_add_str( "twirssi", "bitlbee_server", "bitlbee" );
1828 Irssi::settings_add_str( "twirssi", "short_url_provider", "TinyURL" );
1829 Irssi::settings_add_str( "twirssi", "short_url_args", undef );
1830 Irssi::settings_add_str( "twirssi", "twitter_usernames", undef );
1831 Irssi::settings_add_str( "twirssi", "twitter_passwords", undef );
1832 Irssi::settings_add_str( "twirssi", "twirssi_default_service", "Twitter" );
1833 Irssi::settings_add_str( "twirssi", "twirssi_nick_color", "%B" );
1834 Irssi::settings_add_str( "twirssi", "twirssi_topic_color", "%r" );
1835 Irssi::settings_add_str( "twirssi", "twirssi_retweet_format",
1836 'RT $n: "$t" ${-- $c$}' );
1837 Irssi::settings_add_str( "twirssi", "twirssi_location",
1838 "$ENV{HOME}/.irssi/scripts/twirssi.pl" );
1839 Irssi::settings_add_str( "twirssi", "twirssi_replies_store",
1840 "$ENV{HOME}/.irssi/scripts/twirssi.json" );
1841 Irssi::settings_add_str( "twirssi", "twirssi_oauth_store",
1842 "$ENV{HOME}/.irssi/scripts/twirssi.oauth" );
1844 Irssi::settings_add_int( "twirssi", "twitter_friends_poll", 600 );
1845 Irssi::settings_add_int( "twirssi", "twitter_timeout", 30 );
1847 Irssi::settings_add_bool( "twirssi", "twirssi_upgrade_beta", 0 );
1848 Irssi::settings_add_bool( "twirssi", "tweet_to_away", 0 );
1849 Irssi::settings_add_bool( "twirssi", "show_reply_context", 0 );
1850 Irssi::settings_add_bool( "twirssi", "show_own_tweets", 1 );
1851 Irssi::settings_add_bool( "twirssi", "twirssi_debug", 0 );
1852 Irssi::settings_add_bool( "twirssi", "twirssi_first_run", 1 );
1853 Irssi::settings_add_bool( "twirssi", "twirssi_track_replies", 1 );
1854 Irssi::settings_add_bool( "twirssi", "twirssi_replies_autonick", 1 );
1855 Irssi::settings_add_bool( "twirssi", "twirssi_use_reply_aliases", 0 );
1856 Irssi::settings_add_bool( "twirssi", "twirssi_notify_timeouts", 1 );
1857 Irssi::settings_add_bool( "twirssi", "twirssi_hilights", 1 );
1858 Irssi::settings_add_bool( "twirssi", "twirssi_always_shorten", 0 );
1859 Irssi::settings_add_bool( "twirssi", "tweet_window_input", 0 );
1860 Irssi::settings_add_bool( "twirssi", "twirssi_avoid_ssl", 0 );
1861 Irssi::settings_add_bool( "twirssi", "twirssi_use_oauth", 1 );
1863 $last_poll = time - &get_poll_time;
1864 $window = Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
1867 ->print( "Couldn't find a window named '"
1868 . Irssi::settings_get_str('twitter_window')
1869 . "', trying to create it." );
1871 Irssi::Windowitem::window_create(
1872 Irssi::settings_get_str('twitter_window'), 1 );
1873 $window->set_name( Irssi::settings_get_str('twitter_window') );
1877 Irssi::command_bind( "dm", "cmd_direct" );
1878 Irssi::command_bind( "dm_as", "cmd_direct_as" );
1879 Irssi::command_bind( "tweet", "cmd_tweet" );
1880 Irssi::command_bind( "tweet_as", "cmd_tweet_as" );
1881 Irssi::command_bind( "retweet", "cmd_retweet" );
1882 Irssi::command_bind( "retweet_as", "cmd_retweet_as" );
1883 Irssi::command_bind( "twitter_reply", "cmd_reply" );
1884 Irssi::command_bind( "twitter_reply_as", "cmd_reply_as" );
1885 Irssi::command_bind( "twitter_login", "cmd_login" );
1886 Irssi::command_bind( "twitter_logout", "cmd_logout" );
1887 Irssi::command_bind( "twitter_switch", "cmd_switch" );
1888 Irssi::command_bind( "twitter_subscribe", "cmd_add_search" );
1889 Irssi::command_bind( "twitter_unsubscribe", "cmd_del_search" );
1890 Irssi::command_bind( "twitter_list_subscriptions", "cmd_list_search" );
1891 Irssi::command_bind( "twirssi_upgrade", "cmd_upgrade" );
1892 Irssi::command_bind( "twirssi_oauth", "cmd_oauth" );
1893 Irssi::command_bind( "twitter_updates", "get_updates" );
1894 Irssi::command_bind( "twitter_add_follow_extra", "cmd_add_follow" );
1895 Irssi::command_bind( "twitter_del_follow_extra", "cmd_del_follow" );
1896 Irssi::command_bind( "twitter_list_follow_extra", "cmd_list_follow" );
1897 Irssi::command_bind( "bitlbee_away", "update_away" );
1898 if ( Irssi::settings_get_bool("twirssi_use_reply_aliases") ) {
1899 Irssi::command_bind( "reply", "cmd_reply" );
1900 Irssi::command_bind( "reply_as", "cmd_reply_as" );
1902 Irssi::command_bind(
1905 print "twits: ", join ", ",
1906 map { "u: $_->{username}\@" . ref($_) } values %twits;
1907 print "selected: $user\@$defservice";
1908 print "friends: ", join ", ", sort keys %friends;
1909 print "nicks: ", join ", ", sort keys %nicks;
1910 print "searches: ", Dumper \%{ $id_map{__searches} };
1911 print "last poll: $last_poll";
1912 if ( open DUMP, ">/tmp/twirssi.cache.txt" ) {
1913 print DUMP Dumper \%tweet_cache;
1915 print "cache written out to /tmp/twirssi.cache.txt";
1919 Irssi::command_bind(
1923 "Twirssi v$VERSION; "
1925 $Net::Twitter::VERSION
1926 ? "Net::Twitter v$Net::Twitter::VERSION. "
1930 $Net::Identica::VERSION
1931 ? "Net::Identica v$Net::Identica::VERSION. "
1935 . JSON::Any::handler()
1936 . ". See details at http://twirssi.com/"
1940 Irssi::command_bind(
1943 "/twitter_follow <username>",
1945 sub { ¬ice("Following $_[0]"); $nicks{ $_[0] } = time; }
1948 Irssi::command_bind(
1951 "/twitter_unfriend <username>",
1953 sub { ¬ice("Stopped following $_[0]"); delete $nicks{ $_[0] }; }
1956 Irssi::command_bind(
1957 "twitter_device_updates",
1959 "/twitter_device_updates none|im|sms",
1960 "update_delivery_device",
1961 sub { ¬ice("Device updated to $_[0]"); }
1964 Irssi::command_bind(
1967 "/twitter_block <username>",
1969 sub { ¬ice("Blocked $_[0]"); }
1972 Irssi::command_bind(
1975 "/twitter_unblock <username>",
1977 sub { ¬ice("Unblock $_[0]"); }
1980 Irssi::signal_add_last( 'complete word' => \&sig_complete );
1982 ¬ice(" %Y<%C(%B^%C)%N TWIRSSI v%R$VERSION%N");
1983 ¬ice(" %C(_(\\%N http://twirssi.com/ for full docs");
1985 " %Y||%C `%N Log in with /twitter_login, send updates with /tweet");
1987 my $file = Irssi::settings_get_str("twirssi_replies_store");
1988 if ( $file and -r $file ) {
1989 if ( open( JSON, $file ) ) {
1994 my $ref = JSON::Any->jsonToObj($json);
1996 my $num = keys %{ $id_map{__indexes} };
1997 ¬ice( sprintf "Loaded old replies from %d contact%s.",
1998 $num, ( $num == 1 ? "" : "s" ) );
2003 ¬ice("Failed to load old replies from $file: $!");
2007 if ( my $provider = Irssi::settings_get_str("short_url_provider") ) {
2008 ¬ice("Loading WWW::Shorten::$provider...");
2009 eval "use WWW::Shorten::$provider;";
2013 "Failed to load WWW::Shorten::$provider - either clear",
2014 "short_url_provider or install the CPAN module"
2019 if ( my $autouser = Irssi::settings_get_str("twitter_usernames") ) {
2026 ->print( "Create a window named "
2027 . Irssi::settings_get_str('twitter_window')
2028 . " or change the value of twitter_window. Then, reload twirssi." );
2031 # vim: set sts=4 expandtab: