10 use POSIX qw/:sys_wait_h/;
11 use Net::Twitter qw/3.05/;
12 $Data::Dumper::Indent = 1;
14 use vars qw($VERSION %IRSSI);
16 $VERSION = "2.4.1beta";
18 authors => 'Dan Boger',
19 contact => 'zigdon@gmail.com',
21 description => 'Send twitter updates using /tweet. '
22 . 'Can optionally set your bitlbee /away message to same',
23 license => 'GNU GPL v2',
24 url => 'http://twirssi.com',
25 changed => 'Fri Jan 22 14:40:48 PST 2010',
36 my $last_friends_poll = 0;
44 my %fix_replies_index;
46 my %irssi_to_mirc_colors = (
66 my ( $data, $server, $win ) = @_;
68 return unless &logged_in($twit);
70 my ( $target, $text ) = split ' ', $data, 2;
71 unless ( $target and $text ) {
72 ¬ice("Usage: /dm <nick> <message>");
76 &cmd_direct_as( "$user $data", $server, $win );
80 my ( $data, $server, $win ) = @_;
82 return unless &logged_in($twit);
84 my ( $username, $target, $text ) = split ' ', $data, 3;
85 unless ( $username and $target and $text ) {
86 ¬ice("Usage: /dm_as <username> <nick> <message>");
90 return unless $username = &valid_username($username);
93 if ( $twits{$username}
94 ->new_direct_message( { user => $target, text => $text } ) )
96 ¬ice("DM sent to $target: $text");
97 $nicks{$target} = time;
101 $error = JSON::Any->jsonToObj( $twits{$username}->get_error() );
102 $error = $error->{error};
104 die $error if $error;
105 ¬ice("DM to $target failed");
110 ¬ice("DM caused an error: $@");
116 my ( $data, $server, $win ) = @_;
118 return unless &logged_in($twit);
120 $data =~ s/^\s+|\s+$//;
122 ¬ice("Usage: /retweet <nick[:num]> [comment]");
126 my ( $id, $data ) = split ' ', $data, 2;
128 &cmd_retweet_as( "$user $id $data", $server, $win );
132 my ( $data, $server, $win ) = @_;
134 unless ( Irssi::settings_get_bool("twirssi_track_replies") ) {
135 ¬ice("twirssi_track_replies is required in order to reteet.");
139 return unless &logged_in($twit);
141 $data =~ s/^\s+|\s+$//;
142 my ( $username, $id, $data ) = split ' ', $data, 3;
145 ¬ice("Usage: /retweet_as <username> <nick[:num]> [comment]");
149 return unless $username = &valid_username($username);
152 $id =~ s/[^\w\d\-:]+//g;
153 ( $nick, $id ) = split /:/, $id;
154 unless ( exists $id_map{ lc $nick } ) {
155 ¬ice("Can't find a tweet from $nick to retweet!");
159 $id = $id_map{__indexes}{$nick} unless $id;
160 unless ( $id_map{ lc $nick }[$id] ) {
161 ¬ice("Can't find a tweet numbered $id from $nick to retweet!");
165 unless ( $id_map{__tweets}{ lc $nick }[$id] ) {
166 ¬ice("The text of this tweet isn't saved, sorry!");
170 # Irssi::settings_add_str( "twirssi", "twirssi_retweet_format", 'RT $n: $t ${-- $c$}' );
171 my $text = Irssi::settings_get_str("twirssi_retweet_format");
172 $text =~ s/\$n/\@$nick/g;
174 $text =~ s/\${|\$}//g;
175 $text =~ s/\$c/$data/;
177 $text =~ s/\${.*?\$}//;
179 $text =~ s/\$t/$id_map{__tweets}{ lc $nick }[$id]/;
181 my $modified = $data;
182 $data = &shorten($text);
184 return if $modified and &too_long($data);
190 $success = $twits{$username}->update(
194 # in_reply_to_status_id => $id_map{ lc $nick }[$id]
199 $twits{$username}->retweet( { id => $id_map{ lc $nick }[$id] } );
200 $success = $success->{id} if ref $success;
202 ¬ice("Update failed") unless $success;
204 return unless $success;
207 ¬ice("Update caused an error: $@. Aborted");
211 foreach ( $data =~ /@([-\w]+)/ ) {
215 ¬ice("Retweet sent");
219 my ( $data, $server, $win ) = @_;
221 return unless &logged_in($twit);
223 $data =~ s/^\s+|\s+$//;
225 ¬ice("Usage: /tweet <update>");
229 &cmd_tweet_as( "$user\@$defservice $data", $server, $win );
233 my ( $data, $server, $win ) = @_;
235 return unless &logged_in($twit);
237 $data =~ s/^\s+|\s+$//;
238 $data =~ s/\s\s+/ /g;
239 my ( $username, $data ) = split ' ', $data, 2;
241 unless ( $username and $data ) {
242 ¬ice("Usage: /tweet_as <username> <update>");
246 return unless $username = &valid_username($username);
248 $data = &shorten($data);
250 return if &too_long($data);
254 unless ( $twits{$username}->update($data) )
256 ¬ice("Update failed");
260 return unless $success;
263 ¬ice("Update caused an error: $@. Aborted.");
267 foreach ( $data =~ /@([-\w]+)/ ) {
271 my $away = &update_away($data);
273 ¬ice( "Update sent" . ( $away ? " (and away msg set)" : "" ) );
277 my ( $data, $server, $win ) = @_;
279 return unless &logged_in($twit);
281 $data =~ s/^\s+|\s+$//;
283 ¬ice("Usage: /reply <nick[:num]> <update>");
287 my ( $id, $data ) = split ' ', $data, 2;
288 unless ( $id and $data ) {
289 ¬ice("Usage: /reply <nick[:num]> <update>");
293 &cmd_reply_as( "$user $id $data", $server, $win );
297 my ( $data, $server, $win ) = @_;
299 unless ( Irssi::settings_get_bool("twirssi_track_replies") ) {
300 ¬ice("twirssi_track_replies is required in order to reply to "
301 . "specific tweets. Either enable it, or just use /tweet "
302 . "\@username <text>." );
306 return unless &logged_in($twit);
308 $data =~ s/^\s+|\s+$//;
309 my ( $username, $id, $data ) = split ' ', $data, 3;
311 unless ( $username and $data ) {
312 ¬ice("Usage: /reply_as <username> <nick[:num]> <update>");
316 return unless $username = &valid_username($username);
319 $id =~ s/[^\w\d\-:]+//g;
320 ( $nick, $id ) = split /:/, $id;
321 unless ( exists $id_map{ lc $nick } ) {
322 ¬ice("Can't find a tweet from $nick to reply to!");
326 $id = $id_map{__indexes}{$nick} unless $id;
327 unless ( $id_map{ lc $nick }[$id] ) {
328 ¬ice("Can't find a tweet numbered $id from $nick to reply to!");
332 if ( Irssi::settings_get_bool("twirssi_replies_autonick") ) {
334 # remove any @nick at the beginning of the reply, as we'll add it anyway
335 $data =~ s/^\s*\@?$nick\s*//;
336 $data = "\@$nick " . $data;
339 $data = &shorten($data);
341 return if &too_long($data);
346 $twits{$username}->update(
349 in_reply_to_status_id => $id_map{ lc $nick }[$id]
354 ¬ice("Update failed");
358 return unless $success;
361 ¬ice("Update caused an error: $@. Aborted");
365 foreach ( $data =~ /@([-\w]+)/ ) {
369 my $away = &update_away($data);
371 ¬ice( "Update sent" . ( $away ? " (and away msg set)" : "" ) );
375 my ( $usage_str, $api_name, $post_ref ) = @_;
378 my ( $data, $server, $win ) = @_;
380 return unless &logged_in($twit);
382 $data =~ s/^\s+|\s+$//;
384 ¬ice("Usage: $usage_str");
390 unless ( $twit->$api_name($data) )
392 ¬ice("$api_name failed");
396 return unless $success;
399 ¬ice("$api_name caused an error. Aborted.");
403 &$post_ref($data) if $post_ref;
408 my ( $data, $server, $win ) = @_;
410 $data =~ s/^\s+|\s+$//g;
411 $data = &normalize_username($data);
412 if ( exists $twits{$data} ) {
413 ¬ice("Switching to $data");
414 $twit = $twits{$data};
415 if ( $data =~ /(.*)\@(.*)/ ) {
419 ¬ice("Couldn't figure out what service '$data' is on");
422 ¬ice("Unknown user $data");
427 my ( $data, $server, $win ) = @_;
429 $data =~ s/^\s+|\s+$//g;
430 $data = $user unless $data;
431 return unless $data = &valid_username($data);
433 ¬ice("Logging out $data...");
434 eval { $twits{$data}->end_session(); };
435 delete $twits{$data};
438 &cmd_switch( ( keys %twits )[0], $server, $win );
440 Irssi::timeout_remove($poll) if $poll;
446 my ( $data, $server, $win ) = @_;
448 print "logging in: $data" if &debug;
450 print "manual data login" if &debug;
451 ( $user, $pass ) = split ' ', $data, 2;
452 unless ( Irssi::settings_get_bool("twirssi_use_oauth") or $pass ) {
453 ¬ice("usage: /twitter_login <username>[\@<service>] <password>");
456 } elsif ( Irssi::settings_get_bool("twirssi_use_oauth")
457 and my $autouser = Irssi::settings_get_str("twitter_usernames") )
459 print "oauth autouser login" if &debug;
460 foreach my $user ( split /,/, $autouser ) {
464 } elsif ( my $autouser = Irssi::settings_get_str("twitter_usernames")
465 and my $autopass = Irssi::settings_get_str("twitter_passwords") )
467 print "autouser login" if &debug;
468 my @user = split /\s*,\s*/, $autouser;
469 my @pass = split /\s*,\s*/, $autopass;
471 # if a password ends with a '\', it was meant to escape the comma, and
472 # it should be concatinated with the next one
476 while ( $p =~ /\\$/ and @pass ) {
477 $p .= "," . shift @pass;
482 if ( @user != @unescaped ) {
483 ¬ice("Number of usernames doesn't match "
484 . "the number of passwords - auto-login failed" );
487 while ( @user and @unescaped ) {
489 $p = shift @unescaped;
495 ¬ice("/twitter_login requires either a username/password "
496 . "or twitter_usernames and twitter_passwords to be set. "
497 . "Note that if twirssi_use_oauth is true, passwords are "
502 %friends = %nicks = ();
505 if ( $user =~ /^(.*)@(twitter|identica)$/ ) {
506 ( $user, $service ) = ( $1, $2 );
508 $service = Irssi::settings_get_str("twirssi_default_service");
510 $defservice = $service = ucfirst lc $service;
512 if ( $service eq 'Twitter'
513 and Irssi::settings_get_bool("twirssi_use_oauth") )
515 print "Attempting OAuth for $user\@$service" if &debug;
517 if ( $service eq 'Identica' )
519 $twit = Net::Twitter->new(
521 traits => [ 'API::REST', 'API::Search' ],
523 ssl => !Irssi::settings_get_bool("twirssi_avoid_ssl"),
526 $twit = Net::Twitter->new(
527 traits => [ 'API::REST', 'OAuth', 'API::Search' ],
528 consumer_key => 'BZVAvBma4GxdiRwXIvbnw',
530 '0T5kahwLyb34vciGZsgkA9lsjtGCQ05vxVE2APXM',
532 ssl => !Irssi::settings_get_bool("twirssi_avoid_ssl"),
538 if ( open( OAUTH, Irssi::settings_get_str("twirssi_oauth_store") ) )
542 next unless m/$user\@$service (\S+) (\S+)/i;
543 print "Trying cached oauth creds for $user\@$service"
545 $twit->access_token($1);
546 $twit->access_token_secret($2);
552 unless ( $twit->authorized ) {
554 eval { $url = $twit->get_authorization_url; };
557 ¬ice( "ERROR: Failed to get OAuth authorization_url. " .
561 ¬ice( "Twirssi not autorized to access $service for $user.",
562 "Please authorize at the following url, then enter the pin",
563 "supplied with /twirssi_oauth $user\@$service <pin>",
567 $oauth{pending}{"$user\@$service"} = $twit;
572 $twit = Net::Twitter->new(
573 $service eq 'Identica' ? ( identica => 1 ) : (),
577 ssl => Irssi::settings_get_bool("twirssi_avoid_ssl") ? 0 : 1,
582 ¬ice("Failed to create object! Aborting.");
586 return &verify_twitter_object( $server, $win, $user, $service, $twit );
590 my ( $data, $server, $win ) = @_;
591 my ( $key, $pin ) = split ' ', $data;
592 my ( $user, $service );
593 $key = &normalize_username($key);
594 if ( $key =~ /^(.*)@(Twitter|Identica)$/ ) {
595 ( $user, $service ) = ( $1, $2 );
598 print "Applying pin to $key" if &debug;
600 unless ( exists $oauth{pending}{$key} ) {
601 ¬ice("There isn't a pending oauth request for $key. "
602 . "Try /twitter_login first" );
606 my $twit = $oauth{pending}{$key};
607 my ( $access_token, $access_token_secret );
609 ( $access_token, $access_token_secret ) =
610 $twit->request_access_token( verifier => $pin );
614 ¬ice("Invalid pin, try again.");
618 delete $oauth{pending}{$key};
620 my $store_file = Irssi::settings_get_str("twirssi_oauth_store");
623 if ( open( OAUTH, $store_file ) ) {
633 push @store, "$key $access_token $access_token_secret";
635 if ( open( OAUTH, ">$store_file.new" ) ) {
636 print OAUTH "$_\n" foreach @store;
638 rename "$store_file.new", $store_file
639 or ¬ice("Failed to rename $store_file.new: $!");
641 ¬ice("Failed to write $store_file.new: $!");
644 ¬ice("No persistant storage set for OAuth. "
645 . "Please /set twirssi_oauth_store to a writable filename." );
648 return &verify_twitter_object( $server, $win, $user, $service, $twit );
651 sub verify_twitter_object {
652 my ( $server, $win, $user, $service, $twit ) = @_;
654 if ( my $timeout = Irssi::settings_get_int("twitter_timeout")
655 and $twit->can('ua') )
657 $twit->ua->timeout($timeout);
658 ¬ice("Twitter timeout set to $timeout");
661 unless ( $twit->verify_credentials() ) {
662 ¬ice("Login as $user\@$service failed");
664 if ( not Irssi::settings_get_bool("twirssi_avoid_ssl") ) {
666 "It's possible you're missing one of the modules required for "
667 . "SSL logins. Try setting twirssi_avoid_ssl to on. See "
668 . "http://cpansearch.perl.org/src/GAAS/libwww-perl-5.831/README.SSL "
669 . "for the detailed requirements." );
674 &cmd_switch( ( keys %twits )[0], $server, $win );
679 my $rate_limit = $twit->rate_limit_status();
680 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
682 "Rate limit exceeded, try again after $rate_limit->{reset_time}");
687 print "saving object for $user\@$service" if &debug;
688 $twits{"$user\@$service"} = $twit;
689 Irssi::timeout_remove($poll) if $poll;
690 $poll = Irssi::timeout_add( &get_poll_time * 1000, \&get_updates, "" );
691 ¬ice("Logged in as $user\@$service, loading friends list...");
693 ¬ice( "loaded friends: ". scalar keys %friends );
694 if ( Irssi::settings_get_bool("twirssi_first_run") ) {
695 Irssi::settings_set_bool( "twirssi_first_run", 0 );
703 my ( $data, $server, $win ) = @_;
706 ¬ice("Usage: /twitter_add_follow_extra <username>");
710 $data =~ s/^\s+|\s+$//;
714 if ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
715 ¬ice("Already following all replies by \@$data");
719 $id_map{__fixreplies}{"$user\@$defservice"}{$data} = 1;
720 ¬ice("Will now follow all replies by \@$data");
724 my ( $data, $server, $win ) = @_;
727 ¬ice("Usage: /twitter_del_follow_extra <username>");
731 $data =~ s/^\s+|\s+$//;
735 unless ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
736 ¬ice("Wasn't following all replies by \@$data");
740 delete $id_map{__fixreplies}{"$user\@$defservice"}{$data};
741 ¬ice("Will no longer follow all replies by \@$data");
744 sub cmd_list_follow {
745 my ( $data, $server, $win ) = @_;
748 foreach my $suser ( sort keys %{ $id_map{__fixreplies} } ) {
750 foreach my $fruser ( sort keys %{ $id_map{__fixreplies}{$suser} } ) {
751 $frusers = $frusers ? "$frusers, $fruser" : $fruser;
755 ¬ice("Following all replies as \@$suser: $frusers");
760 ¬ice("Not following all replies by anyone");
765 my ( $data, $server, $win ) = @_;
767 unless ( $twit and $twit->can('search') ) {
768 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
769 . "doesn't support searches." );
773 $data =~ s/^\s+|\s+$//;
777 ¬ice("Usage: /twitter_subscribe <topic>");
781 if ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
782 ¬ice("Already had a subscription for '$data'");
786 $id_map{__searches}{"$user\@$defservice"}{$data} = 1;
787 ¬ice("Added subscription for '$data'");
791 my ( $data, $server, $win ) = @_;
793 unless ( $twit and $twit->can('search') ) {
794 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
795 . "doesn't support searches." );
798 $data =~ s/^\s+|\s+$//;
802 ¬ice("Usage: /twitter_unsubscribe <topic>");
806 unless ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
807 ¬ice("No subscription found for '$data'");
811 delete $id_map{__searches}{"$user\@$defservice"}{$data};
812 ¬ice("Removed subscription for '$data'");
815 sub cmd_list_search {
816 my ( $data, $server, $win ) = @_;
819 foreach my $suser ( sort keys %{ $id_map{__searches} } ) {
821 foreach my $topic ( sort keys %{ $id_map{__searches}{$suser} } ) {
822 $topics = $topics ? "$topics, $topic" : $topic;
826 ¬ice("Search subscriptions for \@$suser: $topics");
831 ¬ice("No search subscriptions set up");
836 my ( $data, $server, $win ) = @_;
838 my $loc = Irssi::settings_get_str("twirssi_location");
840 ¬ice("$loc isn't writable, can't upgrade."
841 . " Perhaps you need to /set twirssi_location?" );
846 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
847 eval { use Digest::MD5; };
850 ¬ice("Failed to load Digest::MD5."
851 . " Try '/twirssi_upgrade nomd5' to skip MD5 verification" );
855 $md5 = get("http://twirssi.com/md5sum");
859 ¬ice("Failed to download md5sum from peeron! Aborting.");
863 unless ( open( CUR, $loc ) ) {
864 ¬ice("Failed to read $loc."
865 . " Check that /set twirssi_location is set to the correct location."
870 my $cur_md5 = Digest::MD5::md5_hex(<CUR>);
873 if ( $cur_md5 eq $md5 ) {
874 ¬ice("Current twirssi seems to be up to date.");
880 Irssi::settings_get_bool("twirssi_upgrade_beta")
881 ? "http://github.com/zigdon/twirssi/raw/master/twirssi.pl"
882 : "http://twirssi.com/twirssi.pl";
883 ¬ice("Downloading twirssi from $URL");
884 LWP::Simple::getstore( $URL, "$loc.upgrade" );
886 unless ( -s "$loc.upgrade" ) {
887 ¬ice("Failed to save $loc.upgrade."
888 . " Check that /set twirssi_location is set to the correct location."
893 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
894 unless ( open( NEW, "$loc.upgrade" ) ) {
895 ¬ice("Failed to read $loc.upgrade."
896 . " Check that /set twirssi_location is set to the correct location."
901 my $new_md5 = Digest::MD5::md5_hex(<NEW>);
904 if ( $new_md5 ne $md5 ) {
905 ¬ice("MD5 verification failed. expected $md5, got $new_md5");
910 rename $loc, "$loc.backup"
911 or ¬ice("Failed to back up $loc: $!. Aborting")
913 rename "$loc.upgrade", $loc
914 or ¬ice("Failed to rename $loc.upgrade: $!. Aborting")
917 my ( $dir, $file ) = ( $loc =~ m{(.*)/([^/]+)$} );
918 if ( -e "$dir/autorun/$file" ) {
919 ¬ice("Updating $dir/autorun/$file");
920 unlink "$dir/autorun/$file"
921 or ¬ice("Failed to remove old $file from autorun: $!");
922 symlink "../$file", "$dir/autorun/$file"
923 or ¬ice("Failed to create symlink in autorun directory: $!");
926 ¬ice("Download complete. Reload twirssi with /script load $file");
935 while ( $page < 11 and $cursor ne "0" )
937 print $fh "type:debug Loading friends page $page...\n"
938 if ( $fh and &debug );
940 if ( ref $twit =~ /^Net::Twitter/ ) {
941 $friends = $twit->friends( { cursor => $cursor } );
942 last unless $friends;
943 $cursor = $friends->{next_cursor};
944 $friends = $friends->{users};
946 $friends = $twit->friends( { page => $page } );
947 last unless $friends;
949 $new_friends{ $_->{screen_name} } = time foreach @$friends;
955 print $fh "type:debug Error during friends list update. Aborted.\n"
960 my ( $added, $removed ) = ( 0, 0 );
961 print $fh "type:debug Scanning for new friends...\n" if ( $fh and &debug );
962 foreach ( keys %new_friends ) {
963 next if exists $friends{$_};
968 print $fh "type:debug Scanning for removed friends...\n"
969 if ( $fh and &debug );
970 foreach ( keys %friends ) {
971 next if exists $new_friends{$_};
976 return ( $added, $removed );
980 print scalar localtime, " - get_updates starting" if &debug;
983 Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
986 ->print( "Can't find a window named '"
987 . Irssi::settings_get_str('twitter_window')
988 . "'. Create it or change the value of twitter_window" );
991 return unless &logged_in($twit);
993 my ( $fh, $filename ) = File::Temp::tempfile();
994 binmode( $fh, ":utf8" );
997 if ($child_pid) { # parent
998 Irssi::timeout_add_once( 5000, 'monitor_child',
999 [ "$filename.done", 0 ] );
1000 Irssi::pidwait_add($child_pid);
1001 } elsif ( defined $child_pid ) { # child
1006 my $new_poll = time;
1010 foreach ( keys %twits ) {
1011 $error++ unless &do_updates( $fh, $_, $twits{$_}, \%context_cache );
1013 if ( $id_map{__fixreplies}{$_} ) {
1014 my @frusers = sort keys %{ $id_map{__fixreplies}{$_} };
1017 unless &get_timeline( $fh, $frusers[ $fix_replies_index{$_} ],
1018 $_, $twits{$_}, \%context_cache );
1020 $fix_replies_index{$_}++;
1021 $fix_replies_index{$_} = 0
1022 if $fix_replies_index{$_} >= @frusers;
1023 print $fh "id:$fix_replies_index{$_} ",
1024 "account:$_ type:fix_replies_index\n";
1028 print $fh "__friends__\n";
1030 time - $last_friends_poll >
1031 Irssi::settings_get_int('twitter_friends_poll') )
1033 print $fh "__updated ", time, "\n";
1034 my ( $added, $removed ) = &load_friends($fh);
1035 if ( $added + $removed ) {
1036 print $fh "type:debug %R***%n Friends list updated: ",
1038 sprintf( "%d added", $added ),
1039 sprintf( "%d removed", $removed ) ),
1044 foreach ( sort keys %friends ) {
1045 print $fh "$_ $friends{$_}\n";
1049 print $fh "type:debug Update encountered errors. Aborted\n";
1050 print $fh "-- $last_poll";
1052 print $fh "-- $new_poll";
1055 rename $filename, "$filename.done";
1058 &ccrap("Failed to fork for updating: $!");
1060 print scalar localtime, " - get_updates ends" if &debug;
1064 my ( $fh, $username, $obj, $cache ) = @_;
1067 my $rate_limit = $obj->rate_limit_status();
1068 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
1069 ¬ice("Rate limit exceeded for $username");
1074 print scalar localtime, " - Polling for updates for $username" if &debug;
1076 my $new_poll_id = 0;
1078 if ( $id_map{__last_id}{$username}{timeline} )
1080 $tweets = $obj->home_timeline( { count => 100 } );
1082 $tweets = $obj->home_timeline();
1087 print $fh "type:debug Error during home_timeline call: Aborted.\n";
1088 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1092 unless ( ref $tweets ) {
1093 if ( $obj->can("get_error") ) {
1094 my $error = "Unknown error";
1095 eval { $error = JSON::Any->jsonToObj( $obj->get_error() ) };
1096 unless ($@) { $error = $obj->get_error() }
1098 "type:debug API Error during home_timeline call: Aborted\n";
1099 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($error);
1103 "type:debug API Error during home_timeline call. Aborted.\n";
1108 foreach my $t ( reverse @$tweets ) {
1109 my $text = &get_text( $t, $obj );
1110 my $reply = "tweet";
1111 if ( Irssi::settings_get_bool("show_reply_context")
1112 and $t->{in_reply_to_screen_name} ne $username
1113 and $t->{in_reply_to_screen_name}
1114 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1116 $nicks{ $t->{in_reply_to_screen_name} } = time;
1118 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1120 $cache->{ $t->{in_reply_to_status_id} } =
1121 $obj->show_status( $t->{in_reply_to_status_id} );
1125 $context = $cache->{ $t->{in_reply_to_status_id} };
1128 my $ctext = &get_text( $context, $obj );
1129 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1130 $context->{id}, $username,
1131 $context->{user}{screen_name}, $ctext;
1136 if $t->{user}{screen_name} eq $username
1137 and not Irssi::settings_get_bool("show_own_tweets");
1138 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1139 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1140 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1142 printf $fh "id:%s account:%s type:last_id timeline\n",
1143 $new_poll_id, $username;
1145 print scalar localtime, " - Polling for replies since ",
1146 $id_map{__last_id}{$username}{reply}
1150 if ( $id_map{__last_id}{$username}{reply} )
1152 $tweets = $obj->replies(
1153 { since_id => $id_map{__last_id}{$username}{reply} } )
1156 $tweets = $obj->replies() || [];
1161 print $fh "type:debug Error during replies call. Aborted.\n";
1165 foreach my $t ( reverse @$tweets ) {
1167 if exists $friends{ $t->{user}{screen_name} };
1169 my $text = &get_text( $t, $obj );
1170 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1171 $t->{id}, $username, $t->{user}{screen_name}, $text;
1172 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1174 printf $fh "id:%s account:%s type:last_id reply\n", $new_poll_id, $username;
1176 print scalar localtime, " - Polling for DMs" if &debug;
1179 if ( $id_map{__last_id}{$username}{dm} )
1181 $tweets = $obj->direct_messages(
1182 { since_id => $id_map{__last_id}{$username}{dm} } )
1185 $tweets = $obj->direct_messages() || [];
1190 print $fh "type:debug Error during direct_messages call. Aborted.\n";
1194 foreach my $t ( reverse @$tweets ) {
1195 my $text = decode_entities( $t->{text} );
1196 $text =~ s/[\n\r]/ /g;
1197 printf $fh "id:%s account:%s nick:%s type:dm %s\n",
1198 $t->{id}, $username, $t->{sender_screen_name}, $text;
1199 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1201 printf $fh "id:%s account:%s type:last_id dm\n", $new_poll_id, $username;
1203 print scalar localtime, " - Polling for subscriptions" if &debug;
1204 if ( $obj->can('search') and $id_map{__searches}{$username} ) {
1206 foreach my $topic ( sort keys %{ $id_map{__searches}{$username} } ) {
1207 print $fh "type:debug searching for $topic since ",
1208 "$id_map{__searches}{$username}{$topic}\n";
1210 $search = $obj->search(
1213 since_id => $id_map{__searches}{$username}{$topic}
1220 "type:debug Error during search($topic) call. Aborted.\n";
1224 unless ( $search->{max_id} ) {
1225 print $fh "type:debug Invalid search results when searching",
1226 " for $topic. Aborted.\n";
1230 $id_map{__searches}{$username}{$topic} = $search->{max_id};
1231 printf $fh "id:%s account:%s type:searchid topic:%s\n",
1232 $search->{max_id}, $username, $topic;
1234 foreach my $t ( reverse @{ $search->{results} } ) {
1235 my $text = &get_text( $t, $obj );
1236 printf $fh "id:%s account:%s nick:%s type:search topic:%s %s\n",
1237 $t->{id}, $username, $t->{from_user}, $topic, $text;
1238 $new_poll_id = $t->{id}
1240 or $t->{id} < $new_poll_id;
1245 print scalar localtime, " - Done" if &debug;
1251 my ( $fh, $target, $username, $obj, $cache ) = @_;
1253 my $last_id = $id_map{__last_id}{$username}{$target};
1255 print $fh "type:debug get_timeline("
1256 . "$fix_replies_index{$username}=$target > $last_id) started."
1257 . " username = $username\n";
1259 $tweets = $obj->user_timeline(
1262 ( $last_id ? ( since_id => $last_id ) : () ),
1269 "type:debug Error during user_timeline($target) call: Aborted.\n";
1270 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1276 "type:debug user_timeline($target) call returned undef! Aborted\n";
1280 foreach my $t ( reverse @$tweets ) {
1281 my $text = &get_text( $t, $obj );
1282 my $reply = "tweet";
1283 if ( Irssi::settings_get_bool("show_reply_context")
1284 and $t->{in_reply_to_screen_name} ne $username
1285 and $t->{in_reply_to_screen_name}
1286 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1288 $nicks{ $t->{in_reply_to_screen_name} } = time;
1290 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1292 $cache->{ $t->{in_reply_to_status_id} } =
1293 $obj->show_status( $t->{in_reply_to_status_id} );
1297 $context = $cache->{ $t->{in_reply_to_status_id} };
1300 my $ctext = &get_text( $context, $obj );
1301 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1302 $context->{id}, $username,
1303 $context->{user}{screen_name}, $ctext;
1307 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1308 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1309 $last_id = $t->{id} if $last_id < $t->{id};
1311 printf $fh "id:%s account:%s type:last_id_fixreplies %s\n",
1312 $last_id, $username, $target;
1319 my $filename = $data->[0];
1320 my $attempt = $data->[1];
1322 print scalar localtime, " - checking child log at $filename ($attempt)"
1324 my ($new_last_poll);
1326 # reap any random leftover processes - work around a bug in irssi on gentoo
1327 waitpid( -1, WNOHANG );
1329 # first time we run we don't want to print out *everything*, so we just
1332 if ( open FILE, $filename ) {
1333 binmode FILE, ":utf8";
1337 last if /^__friends__/;
1338 unless (/\n$/) { # skip partial lines
1339 # print "Skipping partial line: $_" if &debug;
1346 foreach my $key (qw/id account nick type topic/) {
1347 if (s/^$key:(\S+)\s*//) {
1352 if ( $meta{type} and $meta{type} eq 'fix_replies_index' ) {
1353 $fix_replies_index{ $meta{account} } = $meta{id};
1354 print "fix_replies_index for $meta{account} set to $meta{id}"
1359 if ( not $meta{type} or $meta{type} !~ /searchid|last_id/ ) {
1360 if ( exists $meta{id} and exists $new_cache{ $meta{id} } ) {
1364 $new_cache{ $meta{id} } = time;
1366 if ( exists $meta{id} and exists $tweet_cache{ $meta{id} } ) {
1372 $meta{account} =~ s/\@(\w+)$//;
1373 $meta{service} = $1;
1375 lc $meta{service} eq
1376 lc Irssi::settings_get_str("twirssi_default_service") )
1378 $account = "$meta{account}: "
1379 if lc "$meta{account}\@$meta{service}" ne lc
1380 "$user\@$defservice";
1382 $account = "$meta{account}\@$meta{service}: ";
1386 if ( $meta{type} ne 'dm'
1387 and Irssi::settings_get_bool("twirssi_track_replies")
1391 $marker = ( $id_map{__indexes}{ $meta{nick} } + 1 ) % 100;
1392 $id_map{ lc $meta{nick} }[$marker] = $meta{id};
1393 $id_map{__indexes}{ $meta{nick} } = $marker;
1394 $id_map{__tweets}{ lc $meta{nick} }[$marker] = $_;
1395 $marker = ":$marker";
1399 $irssi_to_mirc_colors{ Irssi::settings_get_str("hilight_color") };
1400 my $nick = "\@$meta{account}";
1401 if ( $_ =~ /\Q$nick\E(?:\W|$)/i
1402 and Irssi::settings_get_bool("twirssi_hilights") )
1404 $meta{nick} = "\cC$hilight_color$meta{nick}\cO";
1405 $hilight = MSGLEVEL_HILIGHT;
1408 if ( $meta{type} =~ /tweet|reply/ ) {
1411 ( MSGLEVEL_PUBLIC | $hilight ),
1412 $meta{type}, $account, $meta{nick}, $marker, $_
1414 } elsif ( $meta{type} eq 'search' ) {
1417 ( MSGLEVEL_PUBLIC | $hilight ),
1418 $meta{type}, $account, $meta{topic},
1419 $meta{nick}, $marker, $_
1422 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1424 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1426 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1429 } elsif ( $meta{type} eq 'dm' ) {
1432 ( MSGLEVEL_MSGS | $hilight ),
1433 $meta{type}, $account, $meta{nick}, $_
1435 } elsif ( $meta{type} eq 'searchid' ) {
1436 print "Search '$meta{topic}' returned id $meta{id}" if &debug;
1439 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1441 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1443 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1446 print "Search '$meta{topic}' returned invalid id $meta{id}";
1448 } elsif ( $meta{type} eq 'last_id' ) {
1449 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1451 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1453 } elsif ( $meta{type} eq 'last_id_fixreplies' ) {
1454 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1456 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1458 } elsif ( $meta{type} eq 'error' ) {
1459 push @lines, [ MSGLEVEL_MSGS, $_ ];
1460 } elsif ( $meta{type} eq 'debug' ) {
1461 print "$_" if &debug,;
1463 print "Unknown line type $meta{type}: $_" if &debug,;
1469 if (/^__updated (\d+)$/) {
1470 $last_friends_poll = $1;
1471 print "Friend list updated" if &debug;
1476 $new_last_poll = $1;
1477 if ( $new_last_poll >= $last_poll ) {
1480 print "Impossible! ",
1481 "new_last_poll=$new_last_poll < last_poll=$last_poll!"
1483 undef $new_last_poll;
1487 my ( $f, $t ) = split ' ', $_;
1488 $nicks{$f} = $friends{$f} = $t;
1491 if ($new_last_poll) {
1492 print "new last_poll = $new_last_poll" if &debug;
1493 print "new last_poll_id = ", Dumper( $id_map{__last_id} ) if &debug;
1495 print "First call, not printing updates" if &debug;
1497 foreach my $line (@lines) {
1498 $window->printformat(
1500 "twirssi_" . $line->[1],
1501 @$line[ 2 .. $#$line - 1 ],
1502 &hilight( $line->[-1] )
1509 or warn "Failed to remove $filename: $!"
1512 # commit the pending cache lines to the actual cache, now that
1513 # we've printed our output
1514 %tweet_cache = ( %tweet_cache, %new_cache );
1516 # keep enough cached tweets, to make sure we don't show duplicates.
1517 foreach ( keys %tweet_cache ) {
1518 next if $tweet_cache{$_} >= $last_poll - 3600;
1519 delete $tweet_cache{$_};
1521 $last_poll = $new_last_poll;
1523 # make sure the pid is removed from the waitpid list
1524 Irssi::pidwait_remove($child_pid);
1526 # and that we don't leave any zombies behind, somehow
1532 Irssi::settings_get_str("twirssi_replies_store") )
1534 if ( open JSON, ">$file" ) {
1535 print JSON JSON::Any->objToJson( \%id_map );
1538 &ccrap("Failed to write replies to $file: $!");
1549 if ( $attempt < 24 ) {
1550 Irssi::timeout_add_once( 5000, 'monitor_child',
1551 [ $filename, $attempt + 1 ] );
1553 print "Giving up on polling $filename" if &debug;
1554 Irssi::pidwait_remove($child_pid);
1556 unlink $filename unless &debug;
1558 return unless Irssi::settings_get_bool("twirssi_notify_timeouts");
1561 my @time = localtime($last_poll);
1562 if ( time - $last_poll < 24 * 60 * 60 ) {
1563 $since = sprintf( "%d:%02d", @time[ 2, 1 ] );
1565 $since = scalar localtime($last_poll);
1568 if ( not $failwhale and time - $last_poll > 60 * 60 ) {
1573 q{ .--./ / | _.---.| },
1582 if ( time - $last_poll < 600 ) {
1583 &ccrap("Haven't been able to get updated tweets since $since");
1589 return Irssi::settings_get_bool("twirssi_debug");
1593 foreach my $msg (@_) {
1594 $window->print( "%R***%n $msg", MSGLEVEL_PUBLIC );
1599 foreach my $msg (@_) {
1600 $window->print( "%R***%n $msg", MSGLEVEL_CLIENTCRAP );
1607 if ( Irssi::settings_get_bool("tweet_to_away")
1609 and $data !~ /^[dD] / )
1612 Irssi::server_find_tag( Irssi::settings_get_str("bitlbee_server") );
1614 $server->send_raw("away :$data");
1617 &ccrap( "Can't find bitlbee server.",
1618 "Update bitlbee_server or disable tweet_to_away" );
1628 my $noalert = shift;
1630 if ( length $data > 140 ) {
1631 ¬ice( "Tweet too long (" . length($data) . " characters) - aborted" )
1639 sub valid_username {
1640 my $username = shift;
1642 $username = &normalize_username($username);
1644 unless ( exists $twits{$username} ) {
1645 ¬ice("Unknown username $username");
1655 ¬ice("Not logged in! Use /twitter_login username pass!");
1663 my ( $complist, $window, $word, $linestart, $want_space ) = @_;
1666 $linestart =~ /^\/(?:retweet|twitter_reply)(?:_as)?\s*$/
1667 or ( Irssi::settings_get_bool("twirssi_use_reply_aliases")
1668 and $linestart =~ /^\/reply(?:_as)?\s*$/ )
1670 { # /twitter_reply gets a nick:num
1672 @$complist = map { "$_:$id_map{__indexes}{$_}" }
1673 sort { $nicks{$b} <=> $nicks{$a} }
1675 keys %{ $id_map{__indexes} };
1679 /^\/(twitter_unfriend|twitter_add_follow_extra|twitter_del_follow_extra)\s*$/
1681 { # /twitter_unfriend gets a nick
1683 push @$complist, grep /^\Q$word/i,
1684 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1687 # /tweet, /tweet_as, /dm, /dm_as - complete @nicks (and nicks as the first
1689 if ( $linestart =~ /^\/(?:tweet|dm)/ ) {
1690 my $prefix = $word =~ s/^@//;
1691 $prefix = 0 if $linestart eq '/dm' or $linestart eq '/dm_as';
1692 push @$complist, grep /^\Q$word/i,
1693 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1694 @$complist = map { "\@$_" } @$complist if $prefix;
1698 sub event_send_text {
1699 my ( $line, $server, $win ) = @_;
1700 my $awin = Irssi::active_win();
1702 # if the window where we got our text was the twitter window, and the user
1703 # wants to be lazy, tweet away!
1704 if ( ( $awin->get_active_name() eq $window->{name} )
1705 and Irssi::settings_get_bool("tweet_window_input") )
1707 &cmd_tweet( $line, $server, $win );
1712 my $poll = Irssi::settings_get_int("twitter_poll_interval");
1713 return $poll if $poll >= 60;
1720 if ( Irssi::settings_get_str("twirssi_nick_color") ) {
1721 my $c = Irssi::settings_get_str("twirssi_nick_color");
1722 $c = $irssi_to_mirc_colors{$c};
1723 $text =~ s/(^|\W)\@(\w+)/$1\cC$c\@$2\cO/g if $c;
1725 if ( Irssi::settings_get_str("twirssi_topic_color") ) {
1726 my $c = Irssi::settings_get_str("twirssi_topic_color");
1727 $c = $irssi_to_mirc_colors{$c};
1728 $text =~ s/(^|\W)(\#|\!)([-\w]+)/$1\cC$c$2$3\cO/g if $c;
1730 $text =~ s/[\n\r]/ /g;
1738 my $provider = Irssi::settings_get_str("short_url_provider");
1741 Irssi::settings_get_bool("twirssi_always_shorten")
1742 or &too_long( $data, 1 )
1748 if ( $provider eq 'Bitly' ) {
1749 @args[ 1, 2 ] = split ',',
1750 Irssi::settings_get_str("short_url_args"), 2;
1751 unless ( @args == 3 ) {
1753 "WWW::Shorten::Bitly requires a username and API key.",
1754 "Set short_url_args to username,API_key or change your",
1755 "short_url_provider."
1757 return decode "utf8", $data;
1761 foreach my $url ( $data =~ /(https?:\/\/\S+[\w\/])/g ) {
1764 my $short = makeashorterlink(@args);
1766 $data =~ s/\Q$url/$short/g;
1768 ¬ice("Failed to shorten $url!");
1774 return decode "utf8", $data;
1777 sub normalize_username {
1780 my ( $username, $service ) = split /\@/, $user, 2;
1782 $service = ucfirst lc $service;
1785 ucfirst lc Irssi::settings_get_str("twirssi_default_service");
1786 unless ( exists $twits{"$username\@$service"} ) {
1788 foreach my $t ( sort keys %twits ) {
1789 next unless $t =~ /^\Q$username\E\@(Twitter|Identica)/;
1795 ¬ice("Can't find a logged in user '$user'");
1800 return "$username\@$service";
1806 my $text = decode_entities( $tweet->{text} );
1807 if ( $tweet->{truncated} ) {
1808 if ( exists $tweet->{retweeted_status} ) {
1809 $text = "RT \@$tweet->{retweeted_status}{user}{screen_name}: "
1810 . "$tweet->{retweeted_status}{text}";
1811 } elsif ( $object->isa('Net::Twitter') ) {
1812 $text .= " -- http://twitter.com/$tweet->{user}{screen_name}"
1813 . "/status/$tweet->{id}";
1817 $text =~ s/[\n\r]/ /g;
1822 Irssi::signal_add( "send text", "event_send_text" );
1824 Irssi::theme_register(
1826 'twirssi_tweet', '[$0%B@$1%n$2] $3',
1827 'twirssi_search', '[$0%r$1%n:%B@$2%n$3] $4',
1828 'twirssi_reply', '[$0\--> %B@$1%n$2] $3',
1829 'twirssi_dm', '[$0%r@$1%n (%WDM%n)] $2',
1830 'twirssi_error', 'ERROR: $0',
1834 Irssi::settings_add_int( "twirssi", "twitter_poll_interval", 300 );
1835 Irssi::settings_add_str( "twirssi", "twitter_window", "twitter" );
1836 Irssi::settings_add_str( "twirssi", "bitlbee_server", "bitlbee" );
1837 Irssi::settings_add_str( "twirssi", "short_url_provider", "TinyURL" );
1838 Irssi::settings_add_str( "twirssi", "short_url_args", undef );
1839 Irssi::settings_add_str( "twirssi", "twitter_usernames", undef );
1840 Irssi::settings_add_str( "twirssi", "twitter_passwords", undef );
1841 Irssi::settings_add_str( "twirssi", "twirssi_default_service", "Twitter" );
1842 Irssi::settings_add_str( "twirssi", "twirssi_nick_color", "%B" );
1843 Irssi::settings_add_str( "twirssi", "twirssi_topic_color", "%r" );
1844 Irssi::settings_add_str( "twirssi", "twirssi_retweet_format",
1845 'RT $n: "$t" ${-- $c$}' );
1846 Irssi::settings_add_str( "twirssi", "twirssi_location",
1847 Irssi::get_irssi_dir . "/scripts/twirssi.pl" );
1848 Irssi::settings_add_str( "twirssi", "twirssi_replies_store",
1849 Irssi::get_irssi_dir . "/scripts/twirssi.json" );
1850 Irssi::settings_add_str( "twirssi", "twirssi_oauth_store",
1851 Irssi::get_irssi_dir . "/scripts/twirssi.oauth" );
1853 Irssi::settings_add_int( "twirssi", "twitter_friends_poll", 600 );
1854 Irssi::settings_add_int( "twirssi", "twitter_timeout", 30 );
1856 Irssi::settings_add_bool( "twirssi", "twirssi_upgrade_beta", 0 );
1857 Irssi::settings_add_bool( "twirssi", "tweet_to_away", 0 );
1858 Irssi::settings_add_bool( "twirssi", "show_reply_context", 0 );
1859 Irssi::settings_add_bool( "twirssi", "show_own_tweets", 1 );
1860 Irssi::settings_add_bool( "twirssi", "twirssi_debug", 0 );
1861 Irssi::settings_add_bool( "twirssi", "twirssi_first_run", 1 );
1862 Irssi::settings_add_bool( "twirssi", "twirssi_track_replies", 1 );
1863 Irssi::settings_add_bool( "twirssi", "twirssi_replies_autonick", 1 );
1864 Irssi::settings_add_bool( "twirssi", "twirssi_use_reply_aliases", 0 );
1865 Irssi::settings_add_bool( "twirssi", "twirssi_notify_timeouts", 1 );
1866 Irssi::settings_add_bool( "twirssi", "twirssi_hilights", 1 );
1867 Irssi::settings_add_bool( "twirssi", "twirssi_always_shorten", 0 );
1868 Irssi::settings_add_bool( "twirssi", "tweet_window_input", 0 );
1869 Irssi::settings_add_bool( "twirssi", "twirssi_avoid_ssl", 0 );
1870 Irssi::settings_add_bool( "twirssi", "twirssi_use_oauth", 1 );
1872 $last_poll = time - &get_poll_time;
1873 $window = Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
1876 ->print( "Couldn't find a window named '"
1877 . Irssi::settings_get_str('twitter_window')
1878 . "', trying to create it." );
1880 Irssi::Windowitem::window_create(
1881 Irssi::settings_get_str('twitter_window'), 1 );
1882 $window->set_name( Irssi::settings_get_str('twitter_window') );
1886 Irssi::command_bind( "dm", "cmd_direct" );
1887 Irssi::command_bind( "dm_as", "cmd_direct_as" );
1888 Irssi::command_bind( "tweet", "cmd_tweet" );
1889 Irssi::command_bind( "tweet_as", "cmd_tweet_as" );
1890 Irssi::command_bind( "retweet", "cmd_retweet" );
1891 Irssi::command_bind( "retweet_as", "cmd_retweet_as" );
1892 Irssi::command_bind( "twitter_reply", "cmd_reply" );
1893 Irssi::command_bind( "twitter_reply_as", "cmd_reply_as" );
1894 Irssi::command_bind( "twitter_login", "cmd_login" );
1895 Irssi::command_bind( "twitter_logout", "cmd_logout" );
1896 Irssi::command_bind( "twitter_switch", "cmd_switch" );
1897 Irssi::command_bind( "twitter_subscribe", "cmd_add_search" );
1898 Irssi::command_bind( "twitter_unsubscribe", "cmd_del_search" );
1899 Irssi::command_bind( "twitter_list_subscriptions", "cmd_list_search" );
1900 Irssi::command_bind( "twirssi_upgrade", "cmd_upgrade" );
1901 Irssi::command_bind( "twirssi_oauth", "cmd_oauth" );
1902 Irssi::command_bind( "twitter_updates", "get_updates" );
1903 Irssi::command_bind( "twitter_add_follow_extra", "cmd_add_follow" );
1904 Irssi::command_bind( "twitter_del_follow_extra", "cmd_del_follow" );
1905 Irssi::command_bind( "twitter_list_follow_extra", "cmd_list_follow" );
1906 Irssi::command_bind( "bitlbee_away", "update_away" );
1907 if ( Irssi::settings_get_bool("twirssi_use_reply_aliases") ) {
1908 Irssi::command_bind( "reply", "cmd_reply" );
1909 Irssi::command_bind( "reply_as", "cmd_reply_as" );
1911 Irssi::command_bind(
1914 print "twits: ", join ", ",
1915 map { "u: $_->{username}\@" . ref($_) } values %twits;
1916 print "selected: $user\@$defservice";
1917 print "friends: ", join ", ", sort keys %friends;
1918 print "nicks: ", join ", ", sort keys %nicks;
1919 print "searches: ", Dumper \%{ $id_map{__searches} };
1920 print "last poll: $last_poll";
1921 if ( open DUMP, ">/tmp/twirssi.cache.txt" ) {
1922 print DUMP Dumper \%tweet_cache;
1924 print "cache written out to /tmp/twirssi.cache.txt";
1928 Irssi::command_bind(
1932 "Twirssi v$VERSION; "
1934 $Net::Twitter::VERSION
1935 ? "Net::Twitter v$Net::Twitter::VERSION. "
1939 $Net::Identica::VERSION
1940 ? "Net::Identica v$Net::Identica::VERSION. "
1944 . JSON::Any::handler()
1945 . ". See details at http://twirssi.com/"
1949 Irssi::command_bind(
1952 "/twitter_follow <username>",
1954 sub { ¬ice("Following $_[0]"); $nicks{ $_[0] } = time; }
1957 Irssi::command_bind(
1960 "/twitter_unfriend <username>",
1962 sub { ¬ice("Stopped following $_[0]"); delete $nicks{ $_[0] }; }
1965 Irssi::command_bind(
1966 "twitter_device_updates",
1968 "/twitter_device_updates none|im|sms",
1969 "update_delivery_device",
1970 sub { ¬ice("Device updated to $_[0]"); }
1973 Irssi::command_bind(
1976 "/twitter_block <username>",
1978 sub { ¬ice("Blocked $_[0]"); }
1981 Irssi::command_bind(
1984 "/twitter_unblock <username>",
1986 sub { ¬ice("Unblock $_[0]"); }
1989 Irssi::signal_add_last( 'complete word' => \&sig_complete );
1991 ¬ice(" %Y<%C(%B^%C)%N TWIRSSI v%R$VERSION%N",
1992 " %C(_(\\%N http://twirssi.com/ for full docs",
1993 " %Y||%C `%N Log in with /twitter_login, send updates with /tweet");
1995 my $file = Irssi::settings_get_str("twirssi_replies_store");
1996 if ( $file and -r $file ) {
1997 if ( open( JSON, $file ) ) {
2002 my $ref = JSON::Any->jsonToObj($json);
2004 my $num = keys %{ $id_map{__indexes} };
2005 ¬ice( sprintf "Loaded old replies from %d contact%s.",
2006 $num, ( $num == 1 ? "" : "s" ) );
2011 ¬ice("Failed to load old replies from $file: $!");
2015 if ( my $provider = Irssi::settings_get_str("short_url_provider") ) {
2016 ¬ice("Loading WWW::Shorten::$provider...");
2017 eval "use WWW::Shorten::$provider;";
2021 "Failed to load WWW::Shorten::$provider - either clear",
2022 "short_url_provider or install the CPAN module"
2027 if ( my $autouser = Irssi::settings_get_str("twitter_usernames") ) {
2034 ->print( "Create a window named "
2035 . Irssi::settings_get_str('twitter_window')
2036 . " or change the value of twitter_window. Then, reload twirssi." );
2039 # vim: set sts=4 expandtab: