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 ) {
547 my $url = $twit->get_authorization_url;
551 ¬ice("ERROR: Failed to get OAuth authorization_url. Try again later.");
555 ¬ice("Twirssi not autorized to access $service for $user.");
556 ¬ice("Please authorize at the following url, then enter the pin ");
557 ¬ice("supplied with /twirssi_oauth $user\@$service <pin>");
560 $oauth{pending}{"$user\@$service"} = $twit;
565 $twit = "Net::$service"->new(
569 ssl => Irssi::settings_get_bool("twirssi_avoid_ssl") ? 0 : 1,
574 ¬ice("Failed to create Net::$service object! Aborting.");
578 return &verify_twitter_object($server, $win, $user, $service, $twit);
582 my ($data, $server, $win) = @_;
583 my ( $key, $pin ) = split ' ', $data;
584 my ($user, $service);
585 $key = &normalize_username($key);
586 if ( $key =~ /^(.*)@(Twitter|Identica)$/ ) {
587 ( $user, $service ) = ( $1, $2 );
590 print "Applying pin to $key" if &debug;
592 unless ( exists $oauth{pending}{$key} ) {
593 ¬ice("There isn't a pending oauth request for $key. "
594 . "Try /twitter_login first" );
598 my $twit = $oauth{pending}{$key};
599 my ( $access_token, $access_token_secret );
601 ( $access_token, $access_token_secret ) =
602 $twit->request_access_token( verifier => $pin );
606 ¬ice("Invalid pin, try again.");
610 delete $oauth{pending}{$key};
612 my $store_file = Irssi::settings_get_str("twirssi_oauth_store");
615 if ( open( OAUTH, $store_file ) ) {
625 push @store, "$key $access_token $access_token_secret";
627 if ( open( OAUTH, ">$store_file.new" ) ) {
628 print OAUTH "$_\n" foreach @store;
630 rename "$store_file.new", $store_file
631 or ¬ice("Failed to rename $store_file.new: $!");
633 ¬ice("Failed to write $store_file.new: $!");
636 ¬ice("No persistant storage set for OAuth. "
637 . "Please /set twirssi_oauth_store to a writable filename." );
640 return &verify_twitter_object($server, $win, $user, $service, $twit);
643 sub verify_twitter_object {
644 my ($server, $win, $user, $service, $twit) = @_;
646 if ( my $timeout = Irssi::settings_get_int("twitter_timeout")
647 and $twit->can('ua') )
649 $twit->ua->timeout($timeout);
650 ¬ice("Twitter timeout set to $timeout");
653 unless ( $twit->verify_credentials() ) {
654 ¬ice("Login as $user\@$service failed");
656 if ( not Irssi::settings_get_bool("twirssi_avoid_ssl") ) {
658 "It's possible you're missing one of the modules required for "
659 . "SSL logins. Try setting twirssi_avoid_ssl to on. See "
660 . "http://cpansearch.perl.org/src/GAAS/libwww-perl-5.831/README.SSL "
661 . "for the detailed requirements." );
666 &cmd_switch( ( keys %twits )[0], $server, $win );
671 my $rate_limit = $twit->rate_limit_status();
672 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
674 "Rate limit exceeded, try again after $rate_limit->{reset_time}" );
679 print "saving object for $user\@$service" if &debug;
680 $twits{"$user\@$service"} = $twit;
681 Irssi::timeout_remove($poll) if $poll;
682 $poll = Irssi::timeout_add( &get_poll_time * 1000, \&get_updates, "" );
683 ¬ice("Logged in as $user\@$service, loading friends list...");
685 ¬ice( "loaded friends: ", scalar keys %friends );
686 if ( Irssi::settings_get_bool("twirssi_first_run") ) {
687 Irssi::settings_set_bool( "twirssi_first_run", 0 );
695 my ( $data, $server, $win ) = @_;
698 ¬ice("Usage: /twitter_add_follow_extra <username>");
702 $data =~ s/^\s+|\s+$//;
706 if ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
707 ¬ice("Already following all replies by \@$data");
711 $id_map{__fixreplies}{"$user\@$defservice"}{$data} = 1;
712 ¬ice("Will now follow all replies by \@$data");
716 my ( $data, $server, $win ) = @_;
719 ¬ice("Usage: /twitter_del_follow_extra <username>");
723 $data =~ s/^\s+|\s+$//;
727 unless ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
728 ¬ice("Wasn't following all replies by \@$data");
732 delete $id_map{__fixreplies}{"$user\@$defservice"}{$data};
733 ¬ice("Will no longer follow all replies by \@$data");
736 sub cmd_list_follow {
737 my ( $data, $server, $win ) = @_;
740 foreach my $suser ( sort keys %{ $id_map{__fixreplies} } ) {
742 foreach my $fruser ( sort keys %{ $id_map{__fixreplies}{$suser} } ) {
743 $frusers = $frusers ? "$frusers, $fruser" : $fruser;
747 ¬ice("Following all replies as \@$suser: $frusers");
752 ¬ice("Not following all replies by anyone");
757 my ( $data, $server, $win ) = @_;
759 unless ( $twit and $twit->can('search') ) {
760 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
761 . "doesn't support searches." );
765 $data =~ s/^\s+|\s+$//;
769 ¬ice("Usage: /twitter_subscribe <topic>");
773 if ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
774 ¬ice("Already had a subscription for '$data'");
778 $id_map{__searches}{"$user\@$defservice"}{$data} = 1;
779 ¬ice("Added subscription for '$data'");
783 my ( $data, $server, $win ) = @_;
785 unless ( $twit and $twit->can('search') ) {
786 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
787 . "doesn't support searches." );
790 $data =~ s/^\s+|\s+$//;
794 ¬ice("Usage: /twitter_unsubscribe <topic>");
798 unless ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
799 ¬ice("No subscription found for '$data'");
803 delete $id_map{__searches}{"$user\@$defservice"}{$data};
804 ¬ice("Removed subscription for '$data'");
807 sub cmd_list_search {
808 my ( $data, $server, $win ) = @_;
811 foreach my $suser ( sort keys %{ $id_map{__searches} } ) {
813 foreach my $topic ( sort keys %{ $id_map{__searches}{$suser} } ) {
814 $topics = $topics ? "$topics, $topic" : $topic;
818 ¬ice("Search subscriptions for \@$suser: $topics");
823 ¬ice("No search subscriptions set up");
828 my ( $data, $server, $win ) = @_;
830 my $loc = Irssi::settings_get_str("twirssi_location");
832 ¬ice("$loc isn't writable, can't upgrade."
833 . " Perhaps you need to /set twirssi_location?" );
838 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
839 eval { use Digest::MD5; };
842 ¬ice("Failed to load Digest::MD5."
843 . " Try '/twirssi_upgrade nomd5' to skip MD5 verification" );
847 $md5 = get("http://twirssi.com/md5sum");
851 ¬ice("Failed to download md5sum from peeron! Aborting.");
855 unless ( open( CUR, $loc ) ) {
856 ¬ice("Failed to read $loc."
857 . " Check that /set twirssi_location is set to the correct location."
862 my $cur_md5 = Digest::MD5::md5_hex(<CUR>);
865 if ( $cur_md5 eq $md5 ) {
866 ¬ice("Current twirssi seems to be up to date.");
872 Irssi::settings_get_bool("twirssi_upgrade_beta")
873 ? "http://github.com/zigdon/twirssi/raw/master/twirssi.pl"
874 : "http://twirssi.com/twirssi.pl";
875 ¬ice("Downloading twirssi from $URL");
876 LWP::Simple::getstore( $URL, "$loc.upgrade" );
878 unless ( -s "$loc.upgrade" ) {
879 ¬ice("Failed to save $loc.upgrade."
880 . " Check that /set twirssi_location is set to the correct location."
885 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
886 unless ( open( NEW, "$loc.upgrade" ) ) {
887 ¬ice("Failed to read $loc.upgrade."
888 . " Check that /set twirssi_location is set to the correct location."
893 my $new_md5 = Digest::MD5::md5_hex(<NEW>);
896 if ( $new_md5 ne $md5 ) {
897 ¬ice("MD5 verification failed. expected $md5, got $new_md5");
902 rename $loc, "$loc.backup"
903 or ¬ice("Failed to back up $loc: $!. Aborting")
905 rename "$loc.upgrade", $loc
906 or ¬ice("Failed to rename $loc.upgrade: $!. Aborting")
909 my ( $dir, $file ) = ( $loc =~ m{(.*)/([^/]+)$} );
910 if ( -e "$dir/autorun/$file" ) {
911 ¬ice("Updating $dir/autorun/$file");
912 unlink "$dir/autorun/$file"
913 or ¬ice("Failed to remove old $file from autorun: $!");
914 symlink "../$file", "$dir/autorun/$file"
915 or ¬ice("Failed to create symlink in autorun directory: $!");
918 ¬ice("Download complete. Reload twirssi with /script load $file");
927 while ( $page < 11 and $cursor ne "0" )
929 print $fh "type:debug Loading friends page $page...\n"
930 if ( $fh and &debug );
932 if ( ref $twit =~ /^Net::Twitter/ ) {
933 $friends = $twit->friends( { cursor => $cursor } );
934 last unless $friends;
935 $cursor = $friends->{next_cursor};
936 $friends = $friends->{users};
938 $friends = $twit->friends( { page => $page } );
939 last unless $friends;
941 $new_friends{ $_->{screen_name} } = time foreach @$friends;
947 print $fh "type:debug Error during friends list update. Aborted.\n";
951 my ( $added, $removed ) = ( 0, 0 );
952 print $fh "type:debug Scanning for new friends...\n" if ( $fh and &debug );
953 foreach ( keys %new_friends ) {
954 next if exists $friends{$_};
959 print $fh "type:debug Scanning for removed friends...\n"
960 if ( $fh and &debug );
961 foreach ( keys %friends ) {
962 next if exists $new_friends{$_};
967 return ( $added, $removed );
971 print scalar localtime, " - get_updates starting" if &debug;
974 Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
977 ->print( "Can't find a window named '"
978 . Irssi::settings_get_str('twitter_window')
979 . "'. Create it or change the value of twitter_window" );
982 return unless &logged_in($twit);
984 my ( $fh, $filename ) = File::Temp::tempfile();
985 binmode( $fh, ":utf8" );
988 if ($child_pid) { # parent
989 Irssi::timeout_add_once( 5000, 'monitor_child',
990 [ "$filename.done", 0 ] );
991 Irssi::pidwait_add($child_pid);
992 } elsif ( defined $child_pid ) { # child
1001 foreach ( keys %twits ) {
1002 $error++ unless &do_updates( $fh, $_, $twits{$_}, \%context_cache );
1004 if ( $id_map{__fixreplies}{$_} ) {
1005 my @frusers = sort keys %{ $id_map{__fixreplies}{$_} };
1008 unless &get_timeline( $fh, $frusers[ $fix_replies_index{$_} ],
1009 $_, $twits{$_}, \%context_cache );
1011 $fix_replies_index{$_}++;
1012 $fix_replies_index{$_} = 0
1013 if $fix_replies_index{$_} >= @frusers;
1014 print $fh "id:$fix_replies_index{$_} ",
1015 "account:$_ type:fix_replies_index\n";
1019 print $fh "__friends__\n";
1021 time - $last_friends_poll >
1022 Irssi::settings_get_int('twitter_friends_poll') )
1024 print $fh "__updated ", time, "\n";
1025 my ( $added, $removed ) = &load_friends($fh);
1026 if ( $added + $removed ) {
1027 print $fh "type:debug %R***%n Friends list updated: ",
1029 sprintf( "%d added", $added ),
1030 sprintf( "%d removed", $removed ) ),
1035 foreach ( sort keys %friends ) {
1036 print $fh "$_ $friends{$_}\n";
1040 print $fh "type:debug Update encountered errors. Aborted\n";
1041 print $fh "-- $last_poll";
1043 print $fh "-- $new_poll";
1046 rename $filename, "$filename.done";
1049 &ccrap("Failed to fork for updating: $!");
1051 print scalar localtime, " - get_updates ends" if &debug;
1055 my ( $fh, $username, $obj, $cache ) = @_;
1058 my $rate_limit = $obj->rate_limit_status();
1059 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
1060 ¬ice("Rate limit exceeded for $username");
1065 print scalar localtime, " - Polling for updates for $username" if &debug;
1067 my $new_poll_id = 0;
1069 if ( $id_map{__last_id}{$username}{timeline} )
1071 $tweets = $obj->home_timeline( { count => 100 } );
1073 $tweets = $obj->home_timeline();
1078 print $fh "type:debug Error during home_timeline call: Aborted.\n";
1079 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1083 unless ( ref $tweets ) {
1084 if ( $obj->can("get_error") ) {
1085 my $error = "Unknown error";
1086 eval { $error = JSON::Any->jsonToObj( $obj->get_error() ) };
1087 unless ($@) { $error = $obj->get_error() }
1089 "type:debug API Error during home_timeline call: Aborted\n";
1090 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($error);
1094 "type:debug API Error during home_timeline call. Aborted.\n";
1099 foreach my $t ( reverse @$tweets ) {
1100 my $text = &get_text( $t, $obj );
1101 my $reply = "tweet";
1102 if ( Irssi::settings_get_bool("show_reply_context")
1103 and $t->{in_reply_to_screen_name} ne $username
1104 and $t->{in_reply_to_screen_name}
1105 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1107 $nicks{ $t->{in_reply_to_screen_name} } = time;
1109 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1111 $cache->{ $t->{in_reply_to_status_id} } =
1112 $obj->show_status( $t->{in_reply_to_status_id} );
1116 $context = $cache->{ $t->{in_reply_to_status_id} };
1119 my $ctext = &get_text( $context, $obj );
1120 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1121 $context->{id}, $username,
1122 $context->{user}{screen_name}, $ctext;
1127 if $t->{user}{screen_name} eq $username
1128 and not Irssi::settings_get_bool("show_own_tweets");
1129 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1130 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1131 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1133 printf $fh "id:%s account:%s type:last_id timeline\n",
1134 $new_poll_id, $username;
1136 print scalar localtime, " - Polling for replies since ",
1137 $id_map{__last_id}{$username}{reply}
1141 if ( $id_map{__last_id}{$username}{reply} )
1143 $tweets = $obj->replies(
1144 { since_id => $id_map{__last_id}{$username}{reply} } )
1147 $tweets = $obj->replies() || [];
1152 print $fh "type:debug Error during replies call. Aborted.\n";
1156 foreach my $t ( reverse @$tweets ) {
1158 if exists $friends{ $t->{user}{screen_name} };
1160 my $text = &get_text( $t, $obj );
1161 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1162 $t->{id}, $username, $t->{user}{screen_name}, $text;
1163 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1165 printf $fh "id:%s account:%s type:last_id reply\n", $new_poll_id, $username;
1167 print scalar localtime, " - Polling for DMs" if &debug;
1170 if ( $id_map{__last_id}{$username}{dm} )
1172 $tweets = $obj->direct_messages(
1173 { since_id => $id_map{__last_id}{$username}{dm} } )
1176 $tweets = $obj->direct_messages() || [];
1181 print $fh "type:debug Error during direct_messages call. Aborted.\n";
1185 foreach my $t ( reverse @$tweets ) {
1186 my $text = decode_entities( $t->{text} );
1187 $text =~ s/[\n\r]/ /g;
1188 printf $fh "id:%s account:%s nick:%s type:dm %s\n",
1189 $t->{id}, $username, $t->{sender_screen_name}, $text;
1190 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1192 printf $fh "id:%s account:%s type:last_id dm\n", $new_poll_id, $username;
1194 print scalar localtime, " - Polling for subscriptions" if &debug;
1195 if ( $obj->can('search') and $id_map{__searches}{$username} ) {
1197 foreach my $topic ( sort keys %{ $id_map{__searches}{$username} } ) {
1198 print $fh "type:debug searching for $topic since ",
1199 "$id_map{__searches}{$username}{$topic}\n";
1201 $search = $obj->search(
1204 since_id => $id_map{__searches}{$username}{$topic}
1211 "type:debug Error during search($topic) call. Aborted.\n";
1215 unless ( $search->{max_id} ) {
1216 print $fh "type:debug Invalid search results when searching",
1217 " for $topic. Aborted.\n";
1221 $id_map{__searches}{$username}{$topic} = $search->{max_id};
1222 printf $fh "id:%s account:%s type:searchid topic:%s\n",
1223 $search->{max_id}, $username, $topic;
1225 foreach my $t ( reverse @{ $search->{results} } ) {
1226 my $text = &get_text( $t, $obj );
1227 printf $fh "id:%s account:%s nick:%s type:search topic:%s %s\n",
1228 $t->{id}, $username, $t->{from_user}, $topic, $text;
1229 $new_poll_id = $t->{id}
1231 or $t->{id} < $new_poll_id;
1236 print scalar localtime, " - Done" if &debug;
1242 my ( $fh, $target, $username, $obj, $cache ) = @_;
1244 my $last_id = $id_map{__last_id}{$username}{$target};
1246 print $fh "type:debug get_timeline("
1247 . "$fix_replies_index{$username}=$target > $last_id) started."
1248 . " username = $username\n";
1250 $tweets = $obj->user_timeline(
1253 ( $last_id ? ( since_id => $last_id ) : () ),
1260 "type:debug Error during user_timeline($target) call: Aborted.\n";
1261 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1267 "type:debug user_timeline($target) call returned undef! Aborted\n";
1271 foreach my $t ( reverse @$tweets ) {
1272 my $text = &get_text( $t, $obj );
1273 my $reply = "tweet";
1274 if ( Irssi::settings_get_bool("show_reply_context")
1275 and $t->{in_reply_to_screen_name} ne $username
1276 and $t->{in_reply_to_screen_name}
1277 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1279 $nicks{ $t->{in_reply_to_screen_name} } = time;
1281 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1283 $cache->{ $t->{in_reply_to_status_id} } =
1284 $obj->show_status( $t->{in_reply_to_status_id} );
1288 $context = $cache->{ $t->{in_reply_to_status_id} };
1291 my $ctext = &get_text( $context, $obj );
1292 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1293 $context->{id}, $username,
1294 $context->{user}{screen_name}, $ctext;
1298 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1299 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1300 $last_id = $t->{id} if $last_id < $t->{id};
1302 printf $fh "id:%s account:%s type:last_id_fixreplies %s\n",
1303 $last_id, $username, $target;
1310 my $filename = $data->[0];
1311 my $attempt = $data->[1];
1313 print scalar localtime, " - checking child log at $filename ($attempt)"
1315 my ($new_last_poll);
1317 # reap any random leftover processes - work around a bug in irssi on gentoo
1318 waitpid( -1, WNOHANG );
1320 # first time we run we don't want to print out *everything*, so we just
1323 if ( open FILE, $filename ) {
1324 binmode FILE, ":utf8";
1328 last if /^__friends__/;
1329 unless (/\n$/) { # skip partial lines
1330 # print "Skipping partial line: $_" if &debug;
1337 foreach my $key (qw/id account nick type topic/) {
1338 if (s/^$key:(\S+)\s*//) {
1343 if ( $meta{type} and $meta{type} eq 'fix_replies_index' ) {
1344 $fix_replies_index{ $meta{account} } = $meta{id};
1345 print "fix_replies_index for $meta{account} set to $meta{id}"
1350 if ( not $meta{type} or $meta{type} !~ /searchid|last_id/ ) {
1351 if ( exists $meta{id} and exists $new_cache{ $meta{id} } ) {
1355 $new_cache{ $meta{id} } = time;
1357 if ( exists $meta{id} and exists $tweet_cache{ $meta{id} } ) {
1363 $meta{account} =~ s/\@(\w+)$//;
1364 $meta{service} = $1;
1366 lc $meta{service} eq
1367 lc Irssi::settings_get_str("twirssi_default_service") )
1369 $account = "$meta{account}: "
1370 if lc "$meta{account}\@$meta{service}" ne lc
1371 "$user\@$defservice";
1373 $account = "$meta{account}\@$meta{service}: ";
1377 if ( $meta{type} ne 'dm'
1378 and Irssi::settings_get_bool("twirssi_track_replies")
1382 $marker = ( $id_map{__indexes}{ $meta{nick} } + 1 ) % 100;
1383 $id_map{ lc $meta{nick} }[$marker] = $meta{id};
1384 $id_map{__indexes}{ $meta{nick} } = $marker;
1385 $id_map{__tweets}{ lc $meta{nick} }[$marker] = $_;
1386 $marker = ":$marker";
1390 $irssi_to_mirc_colors{ Irssi::settings_get_str("hilight_color") };
1391 my $nick = "\@$meta{account}";
1392 if ( $_ =~ /\Q$nick\E(?:\W|$)/i
1393 and Irssi::settings_get_bool("twirssi_hilights") )
1395 $meta{nick} = "\cC$hilight_color$meta{nick}\cO";
1396 $hilight = MSGLEVEL_HILIGHT;
1399 if ( $meta{type} =~ /tweet|reply/ ) {
1402 ( MSGLEVEL_PUBLIC | $hilight ),
1403 $meta{type}, $account, $meta{nick}, $marker, $_
1405 } elsif ( $meta{type} eq 'search' ) {
1408 ( MSGLEVEL_PUBLIC | $hilight ),
1409 $meta{type}, $account, $meta{topic},
1410 $meta{nick}, $marker, $_
1413 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1415 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1417 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1420 } elsif ( $meta{type} eq 'dm' ) {
1423 ( MSGLEVEL_MSGS | $hilight ),
1424 $meta{type}, $account, $meta{nick}, $_
1426 } elsif ( $meta{type} eq 'searchid' ) {
1427 print "Search '$meta{topic}' returned id $meta{id}" if &debug;
1430 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1432 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1434 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1437 print "Search '$meta{topic}' returned invalid id $meta{id}";
1439 } elsif ( $meta{type} eq 'last_id' ) {
1440 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1442 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1444 } elsif ( $meta{type} eq 'last_id_fixreplies' ) {
1445 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1447 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1449 } elsif ( $meta{type} eq 'error' ) {
1450 push @lines, [ MSGLEVEL_MSGS, $_ ];
1451 } elsif ( $meta{type} eq 'debug' ) {
1452 print "$_" if &debug,;
1454 print "Unknown line type $meta{type}: $_" if &debug,;
1460 if (/^__updated (\d+)$/) {
1461 $last_friends_poll = $1;
1462 print "Friend list updated" if &debug;
1467 $new_last_poll = $1;
1468 if ( $new_last_poll >= $last_poll ) {
1471 print "Impossible! ",
1472 "new_last_poll=$new_last_poll < last_poll=$last_poll!"
1474 undef $new_last_poll;
1478 my ( $f, $t ) = split ' ', $_;
1479 $nicks{$f} = $friends{$f} = $t;
1482 if ($new_last_poll) {
1483 print "new last_poll = $new_last_poll" if &debug;
1484 print "new last_poll_id = ", Dumper( $id_map{__last_id} ) if &debug;
1486 print "First call, not printing updates" if &debug;
1488 foreach my $line (@lines) {
1489 $window->printformat(
1491 "twirssi_" . $line->[1],
1492 @$line[ 2 .. $#$line - 1 ],
1493 &hilight( $line->[-1] )
1500 or warn "Failed to remove $filename: $!"
1503 # commit the pending cache lines to the actual cache, now that
1504 # we've printed our output
1505 %tweet_cache = ( %tweet_cache, %new_cache );
1507 # keep enough cached tweets, to make sure we don't show duplicates.
1508 foreach ( keys %tweet_cache ) {
1509 next if $tweet_cache{$_} >= $last_poll - 3600;
1510 delete $tweet_cache{$_};
1512 $last_poll = $new_last_poll;
1514 # make sure the pid is removed from the waitpid list
1515 Irssi::pidwait_remove($child_pid);
1517 # and that we don't leave any zombies behind, somehow
1523 Irssi::settings_get_str("twirssi_replies_store") )
1525 if ( open JSON, ">$file" ) {
1526 print JSON JSON::Any->objToJson( \%id_map );
1529 &ccrap("Failed to write replies to $file: $!");
1540 if ( $attempt < 24 ) {
1541 Irssi::timeout_add_once( 5000, 'monitor_child',
1542 [ $filename, $attempt + 1 ] );
1544 print "Giving up on polling $filename" if &debug;
1545 Irssi::pidwait_remove($child_pid);
1547 unlink $filename unless &debug;
1549 return unless Irssi::settings_get_bool("twirssi_notify_timeouts");
1552 my @time = localtime($last_poll);
1553 if ( time - $last_poll < 24 * 60 * 60 ) {
1554 $since = sprintf( "%d:%02d", @time[ 2, 1 ] );
1556 $since = scalar localtime($last_poll);
1559 if ( not $failwhale and time - $last_poll > 60 * 60 ) {
1564 q{ .--./ / | _.---.| },
1576 if ( time - $last_poll < 600 ) {
1577 &ccrap("Haven't been able to get updated tweets since $since");
1583 return Irssi::settings_get_bool("twirssi_debug");
1587 $window->print( "%R***%n @_", MSGLEVEL_PUBLIC );
1591 $window->print( "%R***%n @_", MSGLEVEL_CLIENTCRAP );
1597 if ( Irssi::settings_get_bool("tweet_to_away")
1599 and $data !~ /^[dD] / )
1602 Irssi::server_find_tag( Irssi::settings_get_str("bitlbee_server") );
1604 $server->send_raw("away :$data");
1607 &ccrap( "Can't find bitlbee server.",
1608 "Update bitlbee_server or disable tweet_to_away" );
1618 my $noalert = shift;
1620 if ( length $data > 140 ) {
1621 ¬ice( "Tweet too long (" . length($data) . " characters) - aborted" )
1629 sub valid_username {
1630 my $username = shift;
1632 $username = &normalize_username($username);
1634 unless ( exists $twits{$username} ) {
1635 ¬ice("Unknown username $username");
1645 ¬ice("Not logged in! Use /twitter_login username pass!");
1653 my ( $complist, $window, $word, $linestart, $want_space ) = @_;
1656 $linestart =~ /^\/(?:retweet|twitter_reply)(?:_as)?\s*$/
1657 or ( Irssi::settings_get_bool("twirssi_use_reply_aliases")
1658 and $linestart =~ /^\/reply(?:_as)?\s*$/ )
1660 { # /twitter_reply gets a nick:num
1662 @$complist = map { "$_:$id_map{__indexes}{$_}" }
1663 sort { $nicks{$b} <=> $nicks{$a} }
1665 keys %{ $id_map{__indexes} };
1669 /^\/(twitter_unfriend|twitter_add_follow_extra|twitter_del_follow_extra)\s*$/
1671 { # /twitter_unfriend gets a nick
1673 push @$complist, grep /^\Q$word/i,
1674 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1677 # /tweet, /tweet_as, /dm, /dm_as - complete @nicks (and nicks as the first
1679 if ( $linestart =~ /^\/(?:tweet|dm)/ ) {
1680 my $prefix = $word =~ s/^@//;
1681 $prefix = 0 if $linestart eq '/dm' or $linestart eq '/dm_as';
1682 push @$complist, grep /^\Q$word/i,
1683 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1684 @$complist = map { "\@$_" } @$complist if $prefix;
1688 sub event_send_text {
1689 my ( $line, $server, $win ) = @_;
1690 my $awin = Irssi::active_win();
1692 # if the window where we got our text was the twitter window, and the user
1693 # wants to be lazy, tweet away!
1694 if ( ( $awin->get_active_name() eq $window->{name} )
1695 and Irssi::settings_get_bool("tweet_window_input") )
1697 &cmd_tweet( $line, $server, $win );
1702 my $poll = Irssi::settings_get_int("twitter_poll_interval");
1703 return $poll if $poll >= 60;
1710 if ( Irssi::settings_get_str("twirssi_nick_color") ) {
1711 my $c = Irssi::settings_get_str("twirssi_nick_color");
1712 $c = $irssi_to_mirc_colors{$c};
1713 $text =~ s/(^|\W)\@(\w+)/$1\cC$c\@$2\cO/g if $c;
1715 if ( Irssi::settings_get_str("twirssi_topic_color") ) {
1716 my $c = Irssi::settings_get_str("twirssi_topic_color");
1717 $c = $irssi_to_mirc_colors{$c};
1718 $text =~ s/(^|\W)(\#|\!)([-\w]+)/$1\cC$c$2$3\cO/g if $c;
1720 $text =~ s/[\n\r]/ /g;
1728 my $provider = Irssi::settings_get_str("short_url_provider");
1731 Irssi::settings_get_bool("twirssi_always_shorten")
1732 or &too_long( $data, 1 )
1738 if ( $provider eq 'Bitly' ) {
1739 @args[ 1, 2 ] = split ',',
1740 Irssi::settings_get_str("short_url_args"), 2;
1741 unless ( @args == 3 ) {
1743 "WWW::Shorten::Bitly requires a username and API key.",
1744 "Set short_url_args to username,API_key or change your",
1745 "short_url_provider."
1747 return decode "utf8", $data;
1751 foreach my $url ( $data =~ /(https?:\/\/\S+[\w\/])/g ) {
1754 my $short = makeashorterlink(@args);
1756 $data =~ s/\Q$url/$short/g;
1758 ¬ice("Failed to shorten $url!");
1764 return decode "utf8", $data;
1767 sub normalize_username {
1770 my ( $username, $service ) = split /\@/, $user, 2;
1772 $service = ucfirst lc $service;
1775 ucfirst lc Irssi::settings_get_str("twirssi_default_service");
1776 unless ( exists $twits{"$username\@$service"} ) {
1778 foreach my $t ( sort keys %twits ) {
1779 next unless $t =~ /^\Q$username\E\@(Twitter|Identica)/;
1785 ¬ice("Can't find a logged in user '$user'");
1790 return "$username\@$service";
1796 my $text = decode_entities( $tweet->{text} );
1797 if ( $tweet->{truncated} ) {
1798 if ( exists $tweet->{retweeted_status} ) {
1799 $text = "RT \@$tweet->{retweeted_status}{user}{screen_name}: "
1800 . "$tweet->{retweeted_status}{text}";
1801 } elsif ( $object->isa('Net::Twitter') ) {
1802 $text .= " -- http://twitter.com/$tweet->{user}{screen_name}"
1803 . "/status/$tweet->{id}";
1807 $text =~ s/[\n\r]/ /g;
1812 Irssi::signal_add( "send text", "event_send_text" );
1814 Irssi::theme_register(
1816 'twirssi_tweet', '[$0%B@$1%n$2] $3',
1817 'twirssi_search', '[$0%r$1%n:%B@$2%n$3] $4',
1818 'twirssi_reply', '[$0\--> %B@$1%n$2] $3',
1819 'twirssi_dm', '[$0%r@$1%n (%WDM%n)] $2',
1820 'twirssi_error', 'ERROR: $0',
1824 Irssi::settings_add_int( "twirssi", "twitter_poll_interval", 300 );
1825 Irssi::settings_add_str( "twirssi", "twitter_window", "twitter" );
1826 Irssi::settings_add_str( "twirssi", "bitlbee_server", "bitlbee" );
1827 Irssi::settings_add_str( "twirssi", "short_url_provider", "TinyURL" );
1828 Irssi::settings_add_str( "twirssi", "short_url_args", undef );
1829 Irssi::settings_add_str( "twirssi", "twitter_usernames", undef );
1830 Irssi::settings_add_str( "twirssi", "twitter_passwords", undef );
1831 Irssi::settings_add_str( "twirssi", "twirssi_default_service", "Twitter" );
1832 Irssi::settings_add_str( "twirssi", "twirssi_nick_color", "%B" );
1833 Irssi::settings_add_str( "twirssi", "twirssi_topic_color", "%r" );
1834 Irssi::settings_add_str( "twirssi", "twirssi_retweet_format",
1835 'RT $n: "$t" ${-- $c$}' );
1836 Irssi::settings_add_str( "twirssi", "twirssi_location",
1837 "$ENV{HOME}/.irssi/scripts/twirssi.pl" );
1838 Irssi::settings_add_str( "twirssi", "twirssi_replies_store",
1839 "$ENV{HOME}/.irssi/scripts/twirssi.json" );
1840 Irssi::settings_add_str( "twirssi", "twirssi_oauth_store",
1841 "$ENV{HOME}/.irssi/scripts/twirssi.oauth" );
1843 Irssi::settings_add_int( "twirssi", "twitter_friends_poll", 600 );
1844 Irssi::settings_add_int( "twirssi", "twitter_timeout", 30 );
1846 Irssi::settings_add_bool( "twirssi", "twirssi_upgrade_beta", 0 );
1847 Irssi::settings_add_bool( "twirssi", "tweet_to_away", 0 );
1848 Irssi::settings_add_bool( "twirssi", "show_reply_context", 0 );
1849 Irssi::settings_add_bool( "twirssi", "show_own_tweets", 1 );
1850 Irssi::settings_add_bool( "twirssi", "twirssi_debug", 0 );
1851 Irssi::settings_add_bool( "twirssi", "twirssi_first_run", 1 );
1852 Irssi::settings_add_bool( "twirssi", "twirssi_track_replies", 1 );
1853 Irssi::settings_add_bool( "twirssi", "twirssi_replies_autonick", 1 );
1854 Irssi::settings_add_bool( "twirssi", "twirssi_use_reply_aliases", 0 );
1855 Irssi::settings_add_bool( "twirssi", "twirssi_notify_timeouts", 1 );
1856 Irssi::settings_add_bool( "twirssi", "twirssi_hilights", 1 );
1857 Irssi::settings_add_bool( "twirssi", "twirssi_always_shorten", 0 );
1858 Irssi::settings_add_bool( "twirssi", "tweet_window_input", 0 );
1859 Irssi::settings_add_bool( "twirssi", "twirssi_avoid_ssl", 0 );
1860 Irssi::settings_add_bool( "twirssi", "twirssi_use_oauth", 1 );
1862 $last_poll = time - &get_poll_time;
1863 $window = Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
1866 ->print( "Couldn't find a window named '"
1867 . Irssi::settings_get_str('twitter_window')
1868 . "', trying to create it." );
1870 Irssi::Windowitem::window_create(
1871 Irssi::settings_get_str('twitter_window'), 1 );
1872 $window->set_name( Irssi::settings_get_str('twitter_window') );
1876 Irssi::command_bind( "dm", "cmd_direct" );
1877 Irssi::command_bind( "dm_as", "cmd_direct_as" );
1878 Irssi::command_bind( "tweet", "cmd_tweet" );
1879 Irssi::command_bind( "tweet_as", "cmd_tweet_as" );
1880 Irssi::command_bind( "retweet", "cmd_retweet" );
1881 Irssi::command_bind( "retweet_as", "cmd_retweet_as" );
1882 Irssi::command_bind( "twitter_reply", "cmd_reply" );
1883 Irssi::command_bind( "twitter_reply_as", "cmd_reply_as" );
1884 Irssi::command_bind( "twitter_login", "cmd_login" );
1885 Irssi::command_bind( "twitter_logout", "cmd_logout" );
1886 Irssi::command_bind( "twitter_switch", "cmd_switch" );
1887 Irssi::command_bind( "twitter_subscribe", "cmd_add_search" );
1888 Irssi::command_bind( "twitter_unsubscribe", "cmd_del_search" );
1889 Irssi::command_bind( "twitter_list_subscriptions", "cmd_list_search" );
1890 Irssi::command_bind( "twirssi_upgrade", "cmd_upgrade" );
1891 Irssi::command_bind( "twirssi_oauth", "cmd_oauth" );
1892 Irssi::command_bind( "twitter_updates", "get_updates" );
1893 Irssi::command_bind( "twitter_add_follow_extra", "cmd_add_follow" );
1894 Irssi::command_bind( "twitter_del_follow_extra", "cmd_del_follow" );
1895 Irssi::command_bind( "twitter_list_follow_extra", "cmd_list_follow" );
1896 Irssi::command_bind( "bitlbee_away", "update_away" );
1897 if ( Irssi::settings_get_bool("twirssi_use_reply_aliases") ) {
1898 Irssi::command_bind( "reply", "cmd_reply" );
1899 Irssi::command_bind( "reply_as", "cmd_reply_as" );
1901 Irssi::command_bind(
1904 print "twits: ", join ", ",
1905 map { "u: $_->{username}\@" . ref($_) } values %twits;
1906 print "selected: $user\@$defservice";
1907 print "friends: ", join ", ", sort keys %friends;
1908 print "nicks: ", join ", ", sort keys %nicks;
1909 print "searches: ", Dumper \%{ $id_map{__searches} };
1910 print "last poll: $last_poll";
1911 if ( open DUMP, ">/tmp/twirssi.cache.txt" ) {
1912 print DUMP Dumper \%tweet_cache;
1914 print "cache written out to /tmp/twirssi.cache.txt";
1918 Irssi::command_bind(
1922 "Twirssi v$VERSION; "
1924 $Net::Twitter::VERSION
1925 ? "Net::Twitter v$Net::Twitter::VERSION. "
1929 $Net::Identica::VERSION
1930 ? "Net::Identica v$Net::Identica::VERSION. "
1934 . JSON::Any::handler()
1935 . ". See details at http://twirssi.com/"
1939 Irssi::command_bind(
1942 "/twitter_follow <username>",
1944 sub { ¬ice("Following $_[0]"); $nicks{ $_[0] } = time; }
1947 Irssi::command_bind(
1950 "/twitter_unfriend <username>",
1952 sub { ¬ice("Stopped following $_[0]"); delete $nicks{ $_[0] }; }
1955 Irssi::command_bind(
1956 "twitter_device_updates",
1958 "/twitter_device_updates none|im|sms",
1959 "update_delivery_device",
1960 sub { ¬ice("Device updated to $_[0]"); }
1963 Irssi::command_bind(
1966 "/twitter_block <username>",
1968 sub { ¬ice("Blocked $_[0]"); }
1971 Irssi::command_bind(
1974 "/twitter_unblock <username>",
1976 sub { ¬ice("Unblock $_[0]"); }
1979 Irssi::signal_add_last( 'complete word' => \&sig_complete );
1981 ¬ice(" %Y<%C(%B^%C)%N TWIRSSI v%R$VERSION%N");
1982 ¬ice(" %C(_(\\%N http://twirssi.com/ for full docs");
1984 " %Y||%C `%N Log in with /twitter_login, send updates with /tweet");
1986 my $file = Irssi::settings_get_str("twirssi_replies_store");
1987 if ( $file and -r $file ) {
1988 if ( open( JSON, $file ) ) {
1993 my $ref = JSON::Any->jsonToObj($json);
1995 my $num = keys %{ $id_map{__indexes} };
1996 ¬ice( sprintf "Loaded old replies from %d contact%s.",
1997 $num, ( $num == 1 ? "" : "s" ) );
2002 ¬ice("Failed to load old replies from $file: $!");
2006 if ( my $provider = Irssi::settings_get_str("short_url_provider") ) {
2007 ¬ice("Loading WWW::Shorten::$provider...");
2008 eval "use WWW::Shorten::$provider;";
2012 "Failed to load WWW::Shorten::$provider - either clear",
2013 "short_url_provider or install the CPAN module"
2018 if ( my $autouser = Irssi::settings_get_str("twitter_usernames") ) {
2025 ->print( "Create a window named "
2026 . Irssi::settings_get_str('twitter_window')
2027 . " or change the value of twitter_window. Then, reload twirssi." );
2030 # vim: set sts=4 expandtab: