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...");
433 $twits{$data}->end_session();
434 delete $twits{$data};
437 &cmd_switch( ( keys %twits )[0], $server, $win );
439 Irssi::timeout_remove($poll) if $poll;
445 my ( $data, $server, $win ) = @_;
447 print "logging in: $data" if &debug;
449 print "manual data login" if &debug;
450 ( $user, $pass ) = split ' ', $data, 2;
451 unless (Irssi::settings_get_bool("twirssi_use_oauth") or $pass) {
452 ¬ice("usage: /twitter_login <username>[\@<service>] <password>");
455 } elsif ( Irssi::settings_get_bool("twirssi_use_oauth") and
456 my $autouser = Irssi::settings_get_str("twitter_usernames") ) {
457 print "oauth autouser login" if &debug;
458 foreach my $user (split /,/, $autouser) {
462 } elsif ( my $autouser = Irssi::settings_get_str("twitter_usernames")
463 and my $autopass = Irssi::settings_get_str("twitter_passwords") )
465 print "autouser login" if &debug;
466 my @user = split /\s*,\s*/, $autouser;
467 my @pass = split /\s*,\s*/, $autopass;
469 # if a password ends with a '\', it was meant to escape the comma, and
470 # it should be concatinated with the next one
474 while ( $p =~ /\\$/ and @pass ) {
475 $p .= "," . shift @pass;
480 if ( @user != @unescaped ) {
481 ¬ice("Number of usernames doesn't match "
482 . "the number of passwords - auto-login failed" );
485 while ( @user and @unescaped ) {
487 $p = shift @unescaped;
493 ¬ice("/twitter_login requires either a username/password "
494 . "or twitter_usernames and twitter_passwords to be set. "
495 . "Note that if twirssi_use_oauth is true, passwords are "
500 %friends = %nicks = ();
503 if ( $user =~ /^(.*)@(twitter|identica)$/ ) {
504 ( $user, $service ) = ( $1, $2 );
506 $service = Irssi::settings_get_str("twirssi_default_service");
508 $defservice = $service = ucfirst lc $service;
510 print "Loading Net::$service" if &debug;
511 eval "use Net::$service 3.05";
514 "Failed to load Net::$service when trying to log in as $user: $@");
518 if ( Irssi::settings_get_bool("twirssi_use_oauth") ) {
519 print "Attempting OAuth for $user\@$service" if &debug;
521 $twit = "Net::$service"->new(
522 traits => [ 'API::REST', 'OAuth' ],
523 consumer_key => 'BZVAvBma4GxdiRwXIvbnw',
524 consumer_secret => '0T5kahwLyb34vciGZsgkA9lsjtGCQ05vxVE2APXM',
526 ssl => Irssi::settings_get_bool("twirssi_avoid_ssl") ? 0 : 1,
531 if (open( OAUTH, Irssi::settings_get_str("twirssi_oauth_store") ) ) {
534 next unless m/$user\@$service (\S+) (\S+)/i;
535 print "Trying cached oauth creds for $user\@$service" if &debug;
536 $twit->access_token($1);
537 $twit->access_token_secret($2);
543 unless ( $twit->authorized ) {
544 ¬ice("Twirssi not autorized to access $service for $user.");
545 ¬ice("Please authorize at the following url, then enter the pin ");
546 ¬ice("supplied with /twirssi_oath $user\@$service <pin>");
547 ¬ice($twit->get_authorization_url);
549 $oauth{pending}{"$user\@$service"} = $twit;
554 $twit = "Net::$service"->new(
558 ssl => Irssi::settings_get_bool("twirssi_avoid_ssl") ? 0 : 1,
563 ¬ice("Failed to create Net::$service object! Aborting.");
567 return &verify_twitter_object($server, $win, $user, $service, $twit);
571 my ($data, $server, $win) = @_;
572 my ( $key, $pin ) = split ' ', $data;
573 my ($user, $service);
574 $key = &normalize_username($key);
575 if ( $key =~ /^(.*)@(Twitter|Identica)$/ ) {
576 ( $user, $service ) = ( $1, $2 );
579 print "Applying pin to $key" if &debug;
581 unless ( exists $oauth{pending}{$key} ) {
582 ¬ice("There isn't a pending oauth request for $key. "
583 . "Try /twitter_login first" );
587 my $twit = $oauth{pending}{$key};
588 my ( $access_token, $access_token_secret );
590 ( $access_token, $access_token_secret ) =
591 $twit->request_access_token( verifier => $pin );
595 ¬ice("Invalid pin, try again.");
599 delete $oauth{pending}{$key};
601 my $store_file = Irssi::settings_get_str("twirssi_oauth_store");
604 if ( open( OAUTH, $store_file ) ) {
607 my ( $k, $v ) = split ' ', 2;
614 $store{$key} = "$access_token $access_token_secret";
616 if ( open( OAUTH, ">$store_file.new" ) ) {
617 print OAUTH "$_ $store{$_}\n" foreach keys %store;
619 rename "$store_file.new", $store_file
620 or ¬ice("Failed to rename $store_file.new: $!");
622 ¬ice("Failed to write $store_file.new: $!");
625 ¬ice("No persistant storage set for OAuth. "
626 . "Please /set twirssi_oauth_store to a writable filename." );
629 return &verify_twitter_object($server, $win, $user, $service, $twit);
632 sub verify_twitter_object {
633 my ($server, $win, $user, $service, $twit) = @_;
635 if ( my $timeout = Irssi::settings_get_int("twitter_timeout")
636 and $twit->can('ua') )
638 $twit->ua->timeout($timeout);
639 ¬ice("Twitter timeout set to $timeout");
642 unless ( $twit->verify_credentials() ) {
643 ¬ice("Login as $user\@$service failed");
645 if ( not Irssi::settings_get_bool("twirssi_avoid_ssl") ) {
647 "It's possible you're missing one of the modules required for "
648 . "SSL logins. Try setting twirssi_avoid_ssl to on. See "
649 . "http://cpansearch.perl.org/src/GAAS/libwww-perl-5.831/README.SSL "
650 . "for the detailed requirements." );
655 &cmd_switch( ( keys %twits )[0], $server, $win );
660 my $rate_limit = $twit->rate_limit_status();
661 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
663 "Rate limit exceeded, try again after $rate_limit->{reset_time}" );
668 print "saving object for $user\@$service" if &debug;
669 $twits{"$user\@$service"} = $twit;
670 Irssi::timeout_remove($poll) if $poll;
671 $poll = Irssi::timeout_add( &get_poll_time * 1000, \&get_updates, "" );
672 ¬ice("Logged in as $user\@$service, loading friends list...");
674 ¬ice( "loaded friends: ", scalar keys %friends );
675 if ( Irssi::settings_get_bool("twirssi_first_run") ) {
676 Irssi::settings_set_bool( "twirssi_first_run", 0 );
684 my ( $data, $server, $win ) = @_;
687 ¬ice("Usage: /twitter_add_follow_extra <username>");
691 $data =~ s/^\s+|\s+$//;
695 if ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
696 ¬ice("Already following all replies by \@$data");
700 $id_map{__fixreplies}{"$user\@$defservice"}{$data} = 1;
701 ¬ice("Will now follow all replies by \@$data");
705 my ( $data, $server, $win ) = @_;
708 ¬ice("Usage: /twitter_del_follow_extra <username>");
712 $data =~ s/^\s+|\s+$//;
716 unless ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
717 ¬ice("Wasn't following all replies by \@$data");
721 delete $id_map{__fixreplies}{"$user\@$defservice"}{$data};
722 ¬ice("Will no longer follow all replies by \@$data");
725 sub cmd_list_follow {
726 my ( $data, $server, $win ) = @_;
729 foreach my $suser ( sort keys %{ $id_map{__fixreplies} } ) {
731 foreach my $fruser ( sort keys %{ $id_map{__fixreplies}{$suser} } ) {
732 $frusers = $frusers ? "$frusers, $fruser" : $fruser;
736 ¬ice("Following all replies as \@$suser: $frusers");
741 ¬ice("Not following all replies by anyone");
746 my ( $data, $server, $win ) = @_;
748 unless ( $twit and $twit->can('search') ) {
749 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
750 . "doesn't support searches." );
754 $data =~ s/^\s+|\s+$//;
758 ¬ice("Usage: /twitter_subscribe <topic>");
762 if ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
763 ¬ice("Already had a subscription for '$data'");
767 $id_map{__searches}{"$user\@$defservice"}{$data} = 1;
768 ¬ice("Added subscription for '$data'");
772 my ( $data, $server, $win ) = @_;
774 unless ( $twit and $twit->can('search') ) {
775 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
776 . "doesn't support searches." );
779 $data =~ s/^\s+|\s+$//;
783 ¬ice("Usage: /twitter_unsubscribe <topic>");
787 unless ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
788 ¬ice("No subscription found for '$data'");
792 delete $id_map{__searches}{"$user\@$defservice"}{$data};
793 ¬ice("Removed subscription for '$data'");
796 sub cmd_list_search {
797 my ( $data, $server, $win ) = @_;
800 foreach my $suser ( sort keys %{ $id_map{__searches} } ) {
802 foreach my $topic ( sort keys %{ $id_map{__searches}{$suser} } ) {
803 $topics = $topics ? "$topics, $topic" : $topic;
807 ¬ice("Search subscriptions for \@$suser: $topics");
812 ¬ice("No search subscriptions set up");
817 my ( $data, $server, $win ) = @_;
819 my $loc = Irssi::settings_get_str("twirssi_location");
821 ¬ice("$loc isn't writable, can't upgrade."
822 . " Perhaps you need to /set twirssi_location?" );
827 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
828 eval { use Digest::MD5; };
831 ¬ice("Failed to load Digest::MD5."
832 . " Try '/twirssi_upgrade nomd5' to skip MD5 verification" );
836 $md5 = get("http://twirssi.com/md5sum");
840 ¬ice("Failed to download md5sum from peeron! Aborting.");
844 unless ( open( CUR, $loc ) ) {
845 ¬ice("Failed to read $loc."
846 . " Check that /set twirssi_location is set to the correct location."
851 my $cur_md5 = Digest::MD5::md5_hex(<CUR>);
854 if ( $cur_md5 eq $md5 ) {
855 ¬ice("Current twirssi seems to be up to date.");
861 Irssi::settings_get_bool("twirssi_upgrade_beta")
862 ? "http://github.com/zigdon/twirssi/raw/master/twirssi.pl"
863 : "http://twirssi.com/twirssi.pl";
864 ¬ice("Downloading twirssi from $URL");
865 LWP::Simple::getstore( $URL, "$loc.upgrade" );
867 unless ( -s "$loc.upgrade" ) {
868 ¬ice("Failed to save $loc.upgrade."
869 . " Check that /set twirssi_location is set to the correct location."
874 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
875 unless ( open( NEW, "$loc.upgrade" ) ) {
876 ¬ice("Failed to read $loc.upgrade."
877 . " Check that /set twirssi_location is set to the correct location."
882 my $new_md5 = Digest::MD5::md5_hex(<NEW>);
885 if ( $new_md5 ne $md5 ) {
886 ¬ice("MD5 verification failed. expected $md5, got $new_md5");
891 rename $loc, "$loc.backup"
892 or ¬ice("Failed to back up $loc: $!. Aborting")
894 rename "$loc.upgrade", $loc
895 or ¬ice("Failed to rename $loc.upgrade: $!. Aborting")
898 my ( $dir, $file ) = ( $loc =~ m{(.*)/([^/]+)$} );
899 if ( -e "$dir/autorun/$file" ) {
900 ¬ice("Updating $dir/autorun/$file");
901 unlink "$dir/autorun/$file"
902 or ¬ice("Failed to remove old $file from autorun: $!");
903 symlink "../$file", "$dir/autorun/$file"
904 or ¬ice("Failed to create symlink in autorun directory: $!");
907 ¬ice("Download complete. Reload twirssi with /script load $file");
916 while ( $page < 11 and $cursor ne "0" )
918 print $fh "type:debug Loading friends page $page...\n"
919 if ( $fh and &debug );
921 if ( ref $twit =~ /^Net::Twitter/ ) {
922 $friends = $twit->friends( { cursor => $cursor } );
923 last unless $friends;
924 $cursor = $friends->{next_cursor};
925 $friends = $friends->{users};
927 $friends = $twit->friends( { page => $page } );
928 last unless $friends;
930 $new_friends{ $_->{screen_name} } = time foreach @$friends;
936 print $fh "type:debug Error during friends list update. Aborted.\n";
940 my ( $added, $removed ) = ( 0, 0 );
941 print $fh "type:debug Scanning for new friends...\n" if ( $fh and &debug );
942 foreach ( keys %new_friends ) {
943 next if exists $friends{$_};
948 print $fh "type:debug Scanning for removed friends...\n"
949 if ( $fh and &debug );
950 foreach ( keys %friends ) {
951 next if exists $new_friends{$_};
956 return ( $added, $removed );
960 print scalar localtime, " - get_updates starting" if &debug;
963 Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
966 ->print( "Can't find a window named '"
967 . Irssi::settings_get_str('twitter_window')
968 . "'. Create it or change the value of twitter_window" );
971 return unless &logged_in($twit);
973 my ( $fh, $filename ) = File::Temp::tempfile();
974 binmode( $fh, ":utf8" );
977 if ($child_pid) { # parent
978 Irssi::timeout_add_once( 5000, 'monitor_child',
979 [ "$filename.done", 0 ] );
980 Irssi::pidwait_add($child_pid);
981 } elsif ( defined $child_pid ) { # child
990 foreach ( keys %twits ) {
991 $error++ unless &do_updates( $fh, $_, $twits{$_}, \%context_cache );
993 if ( $id_map{__fixreplies}{$_} ) {
994 my @frusers = sort keys %{ $id_map{__fixreplies}{$_} };
997 unless &get_timeline( $fh, $frusers[ $fix_replies_index{$_} ],
998 $_, $twits{$_}, \%context_cache );
1000 $fix_replies_index{$_}++;
1001 $fix_replies_index{$_} = 0
1002 if $fix_replies_index{$_} >= @frusers;
1003 print $fh "id:$fix_replies_index{$_} ",
1004 "account:$_ type:fix_replies_index\n";
1008 print $fh "__friends__\n";
1010 time - $last_friends_poll >
1011 Irssi::settings_get_int('twitter_friends_poll') )
1013 print $fh "__updated ", time, "\n";
1014 my ( $added, $removed ) = &load_friends($fh);
1015 if ( $added + $removed ) {
1016 print $fh "type:debug %R***%n Friends list updated: ",
1018 sprintf( "%d added", $added ),
1019 sprintf( "%d removed", $removed ) ),
1024 foreach ( sort keys %friends ) {
1025 print $fh "$_ $friends{$_}\n";
1029 print $fh "type:debug Update encountered errors. Aborted\n";
1030 print $fh "-- $last_poll";
1032 print $fh "-- $new_poll";
1035 rename $filename, "$filename.done";
1038 &ccrap("Failed to fork for updating: $!");
1040 print scalar localtime, " - get_updates ends" if &debug;
1044 my ( $fh, $username, $obj, $cache ) = @_;
1046 my $rate_limit = $obj->rate_limit_status();
1047 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
1048 ¬ice("Rate limit exceeded for $username");
1052 print scalar localtime, " - Polling for updates for $username" if &debug;
1054 my $new_poll_id = 0;
1056 if ( $id_map{__last_id}{$username}{timeline} )
1058 $tweets = $obj->home_timeline( { count => 100 } );
1060 $tweets = $obj->home_timeline();
1065 print $fh "type:debug Error during home_timeline call: Aborted.\n";
1066 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1070 unless ( ref $tweets ) {
1071 if ( $obj->can("get_error") ) {
1072 my $error = "Unknown error";
1073 eval { $error = JSON::Any->jsonToObj( $obj->get_error() ) };
1074 unless ($@) { $error = $obj->get_error() }
1076 "type:debug API Error during home_timeline call: Aborted\n";
1077 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($error);
1081 "type:debug API Error during home_timeline call. Aborted.\n";
1086 foreach my $t ( reverse @$tweets ) {
1087 my $text = &get_text( $t, $obj );
1088 my $reply = "tweet";
1089 if ( Irssi::settings_get_bool("show_reply_context")
1090 and $t->{in_reply_to_screen_name} ne $username
1091 and $t->{in_reply_to_screen_name}
1092 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1094 $nicks{ $t->{in_reply_to_screen_name} } = time;
1096 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1098 $cache->{ $t->{in_reply_to_status_id} } =
1099 $obj->show_status( $t->{in_reply_to_status_id} );
1103 $context = $cache->{ $t->{in_reply_to_status_id} };
1106 my $ctext = &get_text( $context, $obj );
1107 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1108 $context->{id}, $username,
1109 $context->{user}{screen_name}, $ctext;
1114 if $t->{user}{screen_name} eq $username
1115 and not Irssi::settings_get_bool("show_own_tweets");
1116 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1117 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1118 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1120 printf $fh "id:%s account:%s type:last_id timeline\n",
1121 $new_poll_id, $username;
1123 print scalar localtime, " - Polling for replies since ",
1124 $id_map{__last_id}{$username}{reply}
1128 if ( $id_map{__last_id}{$username}{reply} )
1130 $tweets = $obj->replies(
1131 { since_id => $id_map{__last_id}{$username}{reply} } )
1134 $tweets = $obj->replies() || [];
1139 print $fh "type:debug Error during replies call. Aborted.\n";
1143 foreach my $t ( reverse @$tweets ) {
1145 if exists $friends{ $t->{user}{screen_name} };
1147 my $text = &get_text( $t, $obj );
1148 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1149 $t->{id}, $username, $t->{user}{screen_name}, $text;
1150 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1152 printf $fh "id:%s account:%s type:last_id reply\n", $new_poll_id, $username;
1154 print scalar localtime, " - Polling for DMs" if &debug;
1157 if ( $id_map{__last_id}{$username}{dm} )
1159 $tweets = $obj->direct_messages(
1160 { since_id => $id_map{__last_id}{$username}{dm} } )
1163 $tweets = $obj->direct_messages() || [];
1168 print $fh "type:debug Error during direct_messages call. Aborted.\n";
1172 foreach my $t ( reverse @$tweets ) {
1173 my $text = decode_entities( $t->{text} );
1174 $text =~ s/[\n\r]/ /g;
1175 printf $fh "id:%s account:%s nick:%s type:dm %s\n",
1176 $t->{id}, $username, $t->{sender_screen_name}, $text;
1177 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1179 printf $fh "id:%s account:%s type:last_id dm\n", $new_poll_id, $username;
1181 print scalar localtime, " - Polling for subscriptions" if &debug;
1182 if ( $obj->can('search') and $id_map{__searches}{$username} ) {
1184 foreach my $topic ( sort keys %{ $id_map{__searches}{$username} } ) {
1185 print $fh "type:debug searching for $topic since ",
1186 "$id_map{__searches}{$username}{$topic}\n";
1188 $search = $obj->search(
1191 since_id => $id_map{__searches}{$username}{$topic}
1198 "type:debug Error during search($topic) call. Aborted.\n";
1202 unless ( $search->{max_id} ) {
1203 print $fh "type:debug Invalid search results when searching",
1204 " for $topic. Aborted.\n";
1208 $id_map{__searches}{$username}{$topic} = $search->{max_id};
1209 printf $fh "id:%s account:%s type:searchid topic:%s\n",
1210 $search->{max_id}, $username, $topic;
1212 foreach my $t ( reverse @{ $search->{results} } ) {
1213 my $text = &get_text( $t, $obj );
1214 printf $fh "id:%s account:%s nick:%s type:search topic:%s %s\n",
1215 $t->{id}, $username, $t->{from_user}, $topic, $text;
1216 $new_poll_id = $t->{id}
1218 or $t->{id} < $new_poll_id;
1223 print scalar localtime, " - Done" if &debug;
1229 my ( $fh, $target, $username, $obj, $cache ) = @_;
1231 my $last_id = $id_map{__last_id}{$username}{$target};
1233 print $fh "type:debug get_timeline("
1234 . "$fix_replies_index{$username}=$target > $last_id) started."
1235 . " username = $username\n";
1237 $tweets = $obj->user_timeline(
1240 ( $last_id ? ( since_id => $last_id ) : () ),
1247 "type:debug Error during user_timeline($target) call: Aborted.\n";
1248 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1254 "type:debug user_timeline($target) call returned undef! Aborted\n";
1258 foreach my $t ( reverse @$tweets ) {
1259 my $text = &get_text( $t, $obj );
1260 my $reply = "tweet";
1261 if ( Irssi::settings_get_bool("show_reply_context")
1262 and $t->{in_reply_to_screen_name} ne $username
1263 and $t->{in_reply_to_screen_name}
1264 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1266 $nicks{ $t->{in_reply_to_screen_name} } = time;
1268 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1270 $cache->{ $t->{in_reply_to_status_id} } =
1271 $obj->show_status( $t->{in_reply_to_status_id} );
1275 $context = $cache->{ $t->{in_reply_to_status_id} };
1278 my $ctext = &get_text( $context, $obj );
1279 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1280 $context->{id}, $username,
1281 $context->{user}{screen_name}, $ctext;
1285 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1286 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1287 $last_id = $t->{id} if $last_id < $t->{id};
1289 printf $fh "id:%s account:%s type:last_id_fixreplies %s\n",
1290 $last_id, $username, $target;
1297 my $filename = $data->[0];
1298 my $attempt = $data->[1];
1300 print scalar localtime, " - checking child log at $filename ($attempt)"
1302 my ($new_last_poll);
1304 # reap any random leftover processes - work around a bug in irssi on gentoo
1305 waitpid( -1, WNOHANG );
1307 # first time we run we don't want to print out *everything*, so we just
1310 if ( open FILE, $filename ) {
1311 binmode FILE, ":utf8";
1315 last if /^__friends__/;
1316 unless (/\n$/) { # skip partial lines
1317 # print "Skipping partial line: $_" if &debug;
1324 foreach my $key (qw/id account nick type topic/) {
1325 if (s/^$key:(\S+)\s*//) {
1330 if ( $meta{type} and $meta{type} eq 'fix_replies_index' ) {
1331 $fix_replies_index{ $meta{account} } = $meta{id};
1332 print "fix_replies_index for $meta{account} set to $meta{id}"
1337 if ( not $meta{type} or $meta{type} !~ /searchid|last_id/ ) {
1338 if ( exists $meta{id} and exists $new_cache{ $meta{id} } ) {
1342 $new_cache{ $meta{id} } = time;
1344 if ( exists $meta{id} and exists $tweet_cache{ $meta{id} } ) {
1350 $meta{account} =~ s/\@(\w+)$//;
1351 $meta{service} = $1;
1353 lc $meta{service} eq
1354 lc Irssi::settings_get_str("twirssi_default_service") )
1356 $account = "$meta{account}: "
1357 if lc "$meta{account}\@$meta{service}" ne lc
1358 "$user\@$defservice";
1360 $account = "$meta{account}\@$meta{service}: ";
1364 if ( $meta{type} ne 'dm'
1365 and Irssi::settings_get_bool("twirssi_track_replies")
1369 $marker = ( $id_map{__indexes}{ $meta{nick} } + 1 ) % 100;
1370 $id_map{ lc $meta{nick} }[$marker] = $meta{id};
1371 $id_map{__indexes}{ $meta{nick} } = $marker;
1372 $id_map{__tweets}{ lc $meta{nick} }[$marker] = $_;
1373 $marker = ":$marker";
1377 $irssi_to_mirc_colors{ Irssi::settings_get_str("hilight_color") };
1378 my $nick = "\@$meta{account}";
1379 if ( $_ =~ /\Q$nick\E(?:\W|$)/i
1380 and Irssi::settings_get_bool("twirssi_hilights") )
1382 $meta{nick} = "\cC$hilight_color$meta{nick}\cO";
1383 $hilight = MSGLEVEL_HILIGHT;
1386 if ( $meta{type} =~ /tweet|reply/ ) {
1389 ( MSGLEVEL_PUBLIC | $hilight ),
1390 $meta{type}, $account, $meta{nick}, $marker, $_
1392 } elsif ( $meta{type} eq 'search' ) {
1395 ( MSGLEVEL_PUBLIC | $hilight ),
1396 $meta{type}, $account, $meta{topic},
1397 $meta{nick}, $marker, $_
1400 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1402 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1404 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1407 } elsif ( $meta{type} eq 'dm' ) {
1410 ( MSGLEVEL_MSGS | $hilight ),
1411 $meta{type}, $account, $meta{nick}, $_
1413 } elsif ( $meta{type} eq 'searchid' ) {
1414 print "Search '$meta{topic}' returned id $meta{id}" if &debug;
1417 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1419 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1421 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1424 print "Search '$meta{topic}' returned invalid id $meta{id}";
1426 } elsif ( $meta{type} eq 'last_id' ) {
1427 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1429 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1431 } elsif ( $meta{type} eq 'last_id_fixreplies' ) {
1432 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1434 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1436 } elsif ( $meta{type} eq 'error' ) {
1437 push @lines, [ MSGLEVEL_MSGS, $_ ];
1438 } elsif ( $meta{type} eq 'debug' ) {
1439 print "$_" if &debug,;
1441 print "Unknown line type $meta{type}: $_" if &debug,;
1447 if (/^__updated (\d+)$/) {
1448 $last_friends_poll = $1;
1449 print "Friend list updated" if &debug;
1454 $new_last_poll = $1;
1455 if ( $new_last_poll >= $last_poll ) {
1458 print "Impossible! ",
1459 "new_last_poll=$new_last_poll < last_poll=$last_poll!"
1461 undef $new_last_poll;
1465 my ( $f, $t ) = split ' ', $_;
1466 $nicks{$f} = $friends{$f} = $t;
1469 if ($new_last_poll) {
1470 print "new last_poll = $new_last_poll" if &debug;
1471 print "new last_poll_id = ", Dumper( $id_map{__last_id} ) if &debug;
1473 print "First call, not printing updates" if &debug;
1475 foreach my $line (@lines) {
1476 $window->printformat(
1478 "twirssi_" . $line->[1],
1479 @$line[ 2 .. $#$line - 1 ],
1480 &hilight( $line->[-1] )
1487 or warn "Failed to remove $filename: $!"
1490 # commit the pending cache lines to the actual cache, now that
1491 # we've printed our output
1492 %tweet_cache = ( %tweet_cache, %new_cache );
1494 # keep enough cached tweets, to make sure we don't show duplicates.
1495 foreach ( keys %tweet_cache ) {
1496 next if $tweet_cache{$_} >= $last_poll - 3600;
1497 delete $tweet_cache{$_};
1499 $last_poll = $new_last_poll;
1501 # make sure the pid is removed from the waitpid list
1502 Irssi::pidwait_remove($child_pid);
1504 # and that we don't leave any zombies behind, somehow
1510 Irssi::settings_get_str("twirssi_replies_store") )
1512 if ( open JSON, ">$file" ) {
1513 print JSON JSON::Any->objToJson( \%id_map );
1516 &ccrap("Failed to write replies to $file: $!");
1527 if ( $attempt < 24 ) {
1528 Irssi::timeout_add_once( 5000, 'monitor_child',
1529 [ $filename, $attempt + 1 ] );
1531 print "Giving up on polling $filename" if &debug;
1532 Irssi::pidwait_remove($child_pid);
1534 unlink $filename unless &debug;
1536 return unless Irssi::settings_get_bool("twirssi_notify_timeouts");
1539 my @time = localtime($last_poll);
1540 if ( time - $last_poll < 24 * 60 * 60 ) {
1541 $since = sprintf( "%d:%02d", @time[ 2, 1 ] );
1543 $since = scalar localtime($last_poll);
1546 if ( not $failwhale and time - $last_poll > 60 * 60 ) {
1551 q{ .--./ / | _.---.| },
1563 if ( time - $last_poll < 600 ) {
1564 &ccrap("Haven't been able to get updated tweets since $since");
1570 return Irssi::settings_get_bool("twirssi_debug");
1574 $window->print( "%R***%n @_", MSGLEVEL_PUBLIC );
1578 $window->print( "%R***%n @_", MSGLEVEL_CLIENTCRAP );
1584 if ( Irssi::settings_get_bool("tweet_to_away")
1586 and $data !~ /^[dD] / )
1589 Irssi::server_find_tag( Irssi::settings_get_str("bitlbee_server") );
1591 $server->send_raw("away :$data");
1594 &ccrap( "Can't find bitlbee server.",
1595 "Update bitlbee_server or disable tweet_to_away" );
1605 my $noalert = shift;
1607 if ( length $data > 140 ) {
1608 ¬ice( "Tweet too long (" . length($data) . " characters) - aborted" )
1616 sub valid_username {
1617 my $username = shift;
1619 $username = &normalize_username($username);
1621 unless ( exists $twits{$username} ) {
1622 ¬ice("Unknown username $username");
1632 ¬ice("Not logged in! Use /twitter_login username pass!");
1640 my ( $complist, $window, $word, $linestart, $want_space ) = @_;
1643 $linestart =~ /^\/(?:retweet|twitter_reply)(?:_as)?\s*$/
1644 or ( Irssi::settings_get_bool("twirssi_use_reply_aliases")
1645 and $linestart =~ /^\/reply(?:_as)?\s*$/ )
1647 { # /twitter_reply gets a nick:num
1649 @$complist = map { "$_:$id_map{__indexes}{$_}" }
1650 sort { $nicks{$b} <=> $nicks{$a} }
1652 keys %{ $id_map{__indexes} };
1656 /^\/(twitter_unfriend|twitter_add_follow_extra|twitter_del_follow_extra)\s*$/
1658 { # /twitter_unfriend gets a nick
1660 push @$complist, grep /^\Q$word/i,
1661 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1664 # /tweet, /tweet_as, /dm, /dm_as - complete @nicks (and nicks as the first
1666 if ( $linestart =~ /^\/(?:tweet|dm)/ ) {
1667 my $prefix = $word =~ s/^@//;
1668 $prefix = 0 if $linestart eq '/dm' or $linestart eq '/dm_as';
1669 push @$complist, grep /^\Q$word/i,
1670 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1671 @$complist = map { "\@$_" } @$complist if $prefix;
1675 sub event_send_text {
1676 my ( $line, $server, $win ) = @_;
1677 my $awin = Irssi::active_win();
1679 # if the window where we got our text was the twitter window, and the user
1680 # wants to be lazy, tweet away!
1681 if ( ( $awin->get_active_name() eq $window->{name} )
1682 and Irssi::settings_get_bool("tweet_window_input") )
1684 &cmd_tweet( $line, $server, $win );
1689 my $poll = Irssi::settings_get_int("twitter_poll_interval");
1690 return $poll if $poll >= 60;
1697 if ( Irssi::settings_get_str("twirssi_nick_color") ) {
1698 my $c = Irssi::settings_get_str("twirssi_nick_color");
1699 $c = $irssi_to_mirc_colors{$c};
1700 $text =~ s/(^|\W)\@(\w+)/$1\cC$c\@$2\cO/g if $c;
1702 if ( Irssi::settings_get_str("twirssi_topic_color") ) {
1703 my $c = Irssi::settings_get_str("twirssi_topic_color");
1704 $c = $irssi_to_mirc_colors{$c};
1705 $text =~ s/(^|\W)(\#|\!)([-\w]+)/$1\cC$c$2$3\cO/g if $c;
1707 $text =~ s/[\n\r]/ /g;
1715 my $provider = Irssi::settings_get_str("short_url_provider");
1718 Irssi::settings_get_bool("twirssi_always_shorten")
1719 or &too_long( $data, 1 )
1725 if ( $provider eq 'Bitly' ) {
1726 @args[ 1, 2 ] = split ',',
1727 Irssi::settings_get_str("short_url_args"), 2;
1728 unless ( @args == 3 ) {
1730 "WWW::Shorten::Bitly requires a username and API key.",
1731 "Set short_url_args to username,API_key or change your",
1732 "short_url_provider."
1734 return decode "utf8", $data;
1738 foreach my $url ( $data =~ /(https?:\/\/\S+[\w\/])/g ) {
1741 my $short = makeashorterlink(@args);
1743 $data =~ s/\Q$url/$short/g;
1745 ¬ice("Failed to shorten $url!");
1751 return decode "utf8", $data;
1754 sub normalize_username {
1757 my ( $username, $service ) = split /\@/, $user, 2;
1759 $service = ucfirst lc $service;
1762 ucfirst lc Irssi::settings_get_str("twirssi_default_service");
1763 unless ( exists $twits{"$username\@$service"} ) {
1765 foreach my $t ( sort keys %twits ) {
1766 next unless $t =~ /^\Q$username\E\@(Twitter|Identica)/;
1772 ¬ice("Can't find a logged in user '$user'");
1777 return "$username\@$service";
1783 my $text = decode_entities( $tweet->{text} );
1784 if ( $tweet->{truncated} ) {
1785 if ( exists $tweet->{retweeted_status} ) {
1786 $text = "RT \@$tweet->{retweeted_status}{user}{screen_name}: "
1787 . "$tweet->{retweeted_status}{text}";
1788 } elsif ( $object->isa('Net::Twitter') ) {
1789 $text .= " -- http://twitter.com/$tweet->{user}{screen_name}"
1790 . "/status/$tweet->{id}";
1794 $text =~ s/[\n\r]/ /g;
1799 Irssi::signal_add( "send text", "event_send_text" );
1801 Irssi::theme_register(
1803 'twirssi_tweet', '[$0%B@$1%n$2] $3',
1804 'twirssi_search', '[$0%r$1%n:%B@$2%n$3] $4',
1805 'twirssi_reply', '[$0\--> %B@$1%n$2] $3',
1806 'twirssi_dm', '[$0%r@$1%n (%WDM%n)] $2',
1807 'twirssi_error', 'ERROR: $0',
1811 Irssi::settings_add_int( "twirssi", "twitter_poll_interval", 300 );
1812 Irssi::settings_add_str( "twirssi", "twitter_window", "twitter" );
1813 Irssi::settings_add_str( "twirssi", "bitlbee_server", "bitlbee" );
1814 Irssi::settings_add_str( "twirssi", "short_url_provider", "TinyURL" );
1815 Irssi::settings_add_str( "twirssi", "short_url_args", undef );
1816 Irssi::settings_add_str( "twirssi", "twitter_usernames", undef );
1817 Irssi::settings_add_str( "twirssi", "twitter_passwords", undef );
1818 Irssi::settings_add_str( "twirssi", "twirssi_default_service", "Twitter" );
1819 Irssi::settings_add_str( "twirssi", "twirssi_nick_color", "%B" );
1820 Irssi::settings_add_str( "twirssi", "twirssi_topic_color", "%r" );
1821 Irssi::settings_add_str( "twirssi", "twirssi_retweet_format",
1822 'RT $n: "$t" ${-- $c$}' );
1823 Irssi::settings_add_str( "twirssi", "twirssi_location",
1824 "$ENV{HOME}/.irssi/scripts/twirssi.pl" );
1825 Irssi::settings_add_str( "twirssi", "twirssi_replies_store",
1826 "$ENV{HOME}/.irssi/scripts/twirssi.json" );
1827 Irssi::settings_add_str( "twirssi", "twirssi_oauth_store",
1828 "$ENV{HOME}/.irssi/scripts/twirssi.oauth" );
1830 Irssi::settings_add_int( "twirssi", "twitter_friends_poll", 600 );
1831 Irssi::settings_add_int( "twirssi", "twitter_timeout", 30 );
1833 Irssi::settings_add_bool( "twirssi", "twirssi_upgrade_beta", 0 );
1834 Irssi::settings_add_bool( "twirssi", "tweet_to_away", 0 );
1835 Irssi::settings_add_bool( "twirssi", "show_reply_context", 0 );
1836 Irssi::settings_add_bool( "twirssi", "show_own_tweets", 1 );
1837 Irssi::settings_add_bool( "twirssi", "twirssi_debug", 0 );
1838 Irssi::settings_add_bool( "twirssi", "twirssi_first_run", 1 );
1839 Irssi::settings_add_bool( "twirssi", "twirssi_track_replies", 1 );
1840 Irssi::settings_add_bool( "twirssi", "twirssi_replies_autonick", 1 );
1841 Irssi::settings_add_bool( "twirssi", "twirssi_use_reply_aliases", 0 );
1842 Irssi::settings_add_bool( "twirssi", "twirssi_notify_timeouts", 1 );
1843 Irssi::settings_add_bool( "twirssi", "twirssi_hilights", 1 );
1844 Irssi::settings_add_bool( "twirssi", "twirssi_always_shorten", 0 );
1845 Irssi::settings_add_bool( "twirssi", "tweet_window_input", 0 );
1846 Irssi::settings_add_bool( "twirssi", "twirssi_avoid_ssl", 0 );
1847 Irssi::settings_add_bool( "twirssi", "twirssi_use_oauth", 1 );
1849 $last_poll = time - &get_poll_time;
1850 $window = Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
1853 ->print( "Couldn't find a window named '"
1854 . Irssi::settings_get_str('twitter_window')
1855 . "', trying to create it." );
1857 Irssi::Windowitem::window_create(
1858 Irssi::settings_get_str('twitter_window'), 1 );
1859 $window->set_name( Irssi::settings_get_str('twitter_window') );
1863 Irssi::command_bind( "dm", "cmd_direct" );
1864 Irssi::command_bind( "dm_as", "cmd_direct_as" );
1865 Irssi::command_bind( "tweet", "cmd_tweet" );
1866 Irssi::command_bind( "tweet_as", "cmd_tweet_as" );
1867 Irssi::command_bind( "retweet", "cmd_retweet" );
1868 Irssi::command_bind( "retweet_as", "cmd_retweet_as" );
1869 Irssi::command_bind( "twitter_reply", "cmd_reply" );
1870 Irssi::command_bind( "twitter_reply_as", "cmd_reply_as" );
1871 Irssi::command_bind( "twitter_login", "cmd_login" );
1872 Irssi::command_bind( "twitter_logout", "cmd_logout" );
1873 Irssi::command_bind( "twitter_switch", "cmd_switch" );
1874 Irssi::command_bind( "twitter_subscribe", "cmd_add_search" );
1875 Irssi::command_bind( "twitter_unsubscribe", "cmd_del_search" );
1876 Irssi::command_bind( "twitter_list_subscriptions", "cmd_list_search" );
1877 Irssi::command_bind( "twirssi_upgrade", "cmd_upgrade" );
1878 Irssi::command_bind( "twirssi_oauth", "cmd_oauth" );
1879 Irssi::command_bind( "twitter_updates", "get_updates" );
1880 Irssi::command_bind( "twitter_add_follow_extra", "cmd_add_follow" );
1881 Irssi::command_bind( "twitter_del_follow_extra", "cmd_del_follow" );
1882 Irssi::command_bind( "twitter_list_follow_extra", "cmd_list_follow" );
1883 Irssi::command_bind( "bitlbee_away", "update_away" );
1884 if ( Irssi::settings_get_bool("twirssi_use_reply_aliases") ) {
1885 Irssi::command_bind( "reply", "cmd_reply" );
1886 Irssi::command_bind( "reply_as", "cmd_reply_as" );
1888 Irssi::command_bind(
1891 print "twits: ", join ", ",
1892 map { "u: $_->{username}\@" . ref($_) } values %twits;
1893 print "selected: $user\@$defservice";
1894 print "friends: ", join ", ", sort keys %friends;
1895 print "nicks: ", join ", ", sort keys %nicks;
1896 print "searches: ", Dumper \%{ $id_map{__searches} };
1897 print "last poll: $last_poll";
1898 if ( open DUMP, ">/tmp/twirssi.cache.txt" ) {
1899 print DUMP Dumper \%tweet_cache;
1901 print "cache written out to /tmp/twirssi.cache.txt";
1905 Irssi::command_bind(
1909 "Twirssi v$VERSION; "
1911 $Net::Twitter::VERSION
1912 ? "Net::Twitter v$Net::Twitter::VERSION. "
1916 $Net::Identica::VERSION
1917 ? "Net::Identica v$Net::Identica::VERSION. "
1921 . JSON::Any::handler()
1922 . ". See details at http://twirssi.com/"
1926 Irssi::command_bind(
1929 "/twitter_follow <username>",
1931 sub { ¬ice("Following $_[0]"); $nicks{ $_[0] } = time; }
1934 Irssi::command_bind(
1937 "/twitter_unfriend <username>",
1939 sub { ¬ice("Stopped following $_[0]"); delete $nicks{ $_[0] }; }
1942 Irssi::command_bind(
1943 "twitter_device_updates",
1945 "/twitter_device_updates none|im|sms",
1946 "update_delivery_device",
1947 sub { ¬ice("Device updated to $_[0]"); }
1950 Irssi::command_bind(
1953 "/twitter_block <username>",
1955 sub { ¬ice("Blocked $_[0]"); }
1958 Irssi::command_bind(
1961 "/twitter_unblock <username>",
1963 sub { ¬ice("Unblock $_[0]"); }
1966 Irssi::signal_add_last( 'complete word' => \&sig_complete );
1968 ¬ice(" %Y<%C(%B^%C)%N TWIRSSI v%R$VERSION%N");
1969 ¬ice(" %C(_(\\%N http://twirssi.com/ for full docs");
1971 " %Y||%C `%N Log in with /twitter_login, send updates with /tweet");
1973 my $file = Irssi::settings_get_str("twirssi_replies_store");
1974 if ( $file and -r $file ) {
1975 if ( open( JSON, $file ) ) {
1980 my $ref = JSON::Any->jsonToObj($json);
1982 my $num = keys %{ $id_map{__indexes} };
1983 ¬ice( sprintf "Loaded old replies from %d contact%s.",
1984 $num, ( $num == 1 ? "" : "s" ) );
1989 ¬ice("Failed to load old replies from $file: $!");
1993 if ( my $provider = Irssi::settings_get_str("short_url_provider") ) {
1994 ¬ice("Loading WWW::Shorten::$provider...");
1995 eval "use WWW::Shorten::$provider;";
1999 "Failed to load WWW::Shorten::$provider - either clear",
2000 "short_url_provider or install the CPAN module"
2005 if ( my $autouser = Irssi::settings_get_str("twitter_usernames")
2006 and my $autopass = Irssi::settings_get_str("twitter_passwords") )
2014 ->print( "Create a window named "
2015 . Irssi::settings_get_str('twitter_window')
2016 . " or change the value of twitter_window. Then, reload twirssi." );
2019 # vim: set sts=4 expandtab: