10 use POSIX qw/:sys_wait_h/;
11 use Net::Twitter::Lite
12 $Data::Dumper::Indent = 1;
14 use vars qw($VERSION %IRSSI);
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 return unless &logged_in($twit);
136 $data =~ s/^\s+|\s+$//;
137 my ( $username, $id, $data ) = split ' ', $data, 3;
140 ¬ice("Usage: /retweet_as <username> <nick[:num]> [comment]");
144 return unless $username = &valid_username($username);
147 $id =~ s/[^\w\d\-:]+//g;
148 ( $nick, $id ) = split /:/, $id;
149 unless ( exists $id_map{ lc $nick } ) {
150 ¬ice("Can't find a tweet from $nick to retweet!");
154 $id = $id_map{__indexes}{$nick} unless $id;
155 unless ( $id_map{ lc $nick }[$id] ) {
156 ¬ice("Can't find a tweet numbered $id from $nick to retweet!");
160 unless ( $id_map{__tweets}{ lc $nick }[$id] ) {
161 ¬ice("The text of this tweet isn't saved, sorry!");
165 # Irssi::settings_add_str( "twirssi", "twirssi_retweet_format", 'RT $n: $t ${-- $c$}' );
166 my $text = Irssi::settings_get_str("twirssi_retweet_format");
167 $text =~ s/\$n/\@$nick/g;
169 $text =~ s/\${|\$}//g;
170 $text =~ s/\$c/$data/;
172 $text =~ s/\${.*?\$}//;
174 $text =~ s/\$t/$id_map{__tweets}{ lc $nick }[$id]/;
176 my $modified = $data;
177 $data = &shorten($text);
179 return if $modified and &too_long($data);
185 $success = $twits{$username}->update(
189 # in_reply_to_status_id => $id_map{ lc $nick }[$id]
194 $twits{$username}->retweet( { id => $id_map{ lc $nick }[$id] } );
195 $success = $success->{id} if ref $success;
197 ¬ice("Update failed") unless $success;
199 return unless $success;
202 ¬ice("Update caused an error: $@. Aborted");
206 foreach ( $data =~ /@([-\w]+)/ ) {
210 ¬ice("Retweet sent");
214 my ( $data, $server, $win ) = @_;
216 return unless &logged_in($twit);
218 $data =~ s/^\s+|\s+$//;
220 ¬ice("Usage: /tweet <update>");
224 &cmd_tweet_as( "$user\@$defservice $data", $server, $win );
228 my ( $data, $server, $win ) = @_;
230 return unless &logged_in($twit);
232 $data =~ s/^\s+|\s+$//;
233 $data =~ s/\s\s+/ /g;
234 my ( $username, $data ) = split ' ', $data, 2;
236 unless ( $username and $data ) {
237 ¬ice("Usage: /tweet_as <username> <update>");
241 return unless $username = &valid_username($username);
243 $data = &shorten($data);
245 return if &too_long($data);
249 unless ( $twits{$username}->update($data) )
251 ¬ice("Update failed");
255 return unless $success;
258 ¬ice("Update caused an error: $@. Aborted.");
262 foreach ( $data =~ /@([-\w]+)/ ) {
266 my $away = &update_away($data);
268 ¬ice( "Update sent" . ( $away ? " (and away msg set)" : "" ) );
272 my ( $data, $server, $win ) = @_;
274 return unless &logged_in($twit);
276 $data =~ s/^\s+|\s+$//;
278 ¬ice("Usage: /reply <nick[:num]> <update>");
282 my ( $id, $data ) = split ' ', $data, 2;
283 unless ( $id and $data ) {
284 ¬ice("Usage: /reply <nick[:num]> <update>");
288 &cmd_reply_as( "$user $id $data", $server, $win );
292 my ( $data, $server, $win ) = @_;
294 return unless &logged_in($twit);
296 $data =~ s/^\s+|\s+$//;
297 my ( $username, $id, $data ) = split ' ', $data, 3;
299 unless ( $username and $data ) {
300 ¬ice("Usage: /reply_as <username> <nick[:num]> <update>");
304 return unless $username = &valid_username($username);
307 $id =~ s/[^\w\d\-:]+//g;
308 ( $nick, $id ) = split /:/, $id;
309 unless ( exists $id_map{ lc $nick } ) {
310 ¬ice("Can't find a tweet from $nick to reply to!");
314 $id = $id_map{__indexes}{$nick} unless $id;
315 unless ( $id_map{ lc $nick }[$id] ) {
316 ¬ice("Can't find a tweet numbered $id from $nick to reply to!");
320 if ( Irssi::settings_get_bool("twirssi_replies_autonick") ) {
322 # remove any @nick at the beginning of the reply, as we'll add it anyway
323 $data =~ s/^\s*\@?$nick\s*//;
324 $data = "\@$nick " . $data;
327 $data = &shorten($data);
329 return if &too_long($data);
334 $twits{$username}->update(
337 in_reply_to_status_id => $id_map{ lc $nick }[$id]
342 ¬ice("Update failed");
346 return unless $success;
349 ¬ice("Update caused an error: $@. Aborted");
353 foreach ( $data =~ /@([-\w]+)/ ) {
357 my $away = &update_away($data);
359 ¬ice( "Update sent" . ( $away ? " (and away msg set)" : "" ) );
363 my ( $usage_str, $api_name, $post_ref ) = @_;
366 my ( $data, $server, $win ) = @_;
368 return unless &logged_in($twit);
370 $data =~ s/^\s+|\s+$//;
372 ¬ice("Usage: $usage_str");
378 unless ( $twit->$api_name($data) )
380 ¬ice("$api_name failed");
384 return unless $success;
387 ¬ice("$api_name caused an error. Aborted.");
391 &$post_ref($data) if $post_ref;
396 my ( $data, $server, $win ) = @_;
398 $data =~ s/^\s+|\s+$//g;
399 $data = &normalize_username($data);
400 if ( exists $twits{$data} ) {
401 ¬ice("Switching to $data");
402 $twit = $twits{$data};
403 if ( $data =~ /(.*)\@(.*)/ ) {
407 ¬ice("Couldn't figure out what service '$data' is on");
410 ¬ice("Unknown user $data");
415 my ( $data, $server, $win ) = @_;
417 $data =~ s/^\s+|\s+$//g;
418 $data = $user unless $data;
419 return unless $data = &valid_username($data);
421 ¬ice("Logging out $data...");
422 eval { $twits{$data}->end_session(); };
423 delete $twits{$data};
426 &cmd_switch( ( keys %twits )[0], $server, $win );
428 Irssi::timeout_remove($poll) if $poll;
434 my ( $data, $server, $win ) = @_;
436 print "logging in: $data" if &debug;
438 print "manual data login" if &debug;
439 ( $user, $pass ) = split ' ', $data, 2;
440 unless ( Irssi::settings_get_bool("twirssi_use_oauth") or $pass ) {
441 ¬ice("usage: /twitter_login <username>[\@<service>] <password>");
444 } elsif ( Irssi::settings_get_bool("twirssi_use_oauth")
445 and my $autouser = Irssi::settings_get_str("twitter_usernames") )
447 print "oauth autouser login" if &debug;
448 foreach my $user ( split /,/, $autouser ) {
452 } elsif ( my $autouser = Irssi::settings_get_str("twitter_usernames")
453 and my $autopass = Irssi::settings_get_str("twitter_passwords") )
455 print "autouser login" if &debug;
456 my @user = split /\s*,\s*/, $autouser;
457 my @pass = split /\s*,\s*/, $autopass;
459 # if a password ends with a '\', it was meant to escape the comma, and
460 # it should be concatinated with the next one
464 while ( $p =~ /\\$/ and @pass ) {
465 $p .= "," . shift @pass;
470 if ( @user != @unescaped ) {
471 ¬ice("Number of usernames doesn't match "
472 . "the number of passwords - auto-login failed" );
475 while ( @user and @unescaped ) {
477 $p = shift @unescaped;
483 ¬ice("/twitter_login requires either a username/password "
484 . "or twitter_usernames and twitter_passwords to be set. "
485 . "Note that if twirssi_use_oauth is true, passwords are "
490 %friends = %nicks = ();
493 if ( $user =~ /^(.*)@(twitter|identica)$/ ) {
494 ( $user, $service ) = ( $1, $2 );
496 $service = Irssi::settings_get_str("twirssi_default_service");
498 $defservice = $service = ucfirst lc $service;
500 $twit = Net::Twitter::Lite->new(
505 ¬ice("Failed to create object! Aborting.");
509 return &verify_twitter_object( $server, $win, $user, $service, $twit );
513 my ( $data, $server, $win ) = @_;
514 my ( $key, $pin ) = split ' ', $data;
515 my ( $user, $service );
516 $key = &normalize_username($key);
517 if ( $key =~ /^(.*)@(Twitter|Identica)$/ ) {
518 ( $user, $service ) = ( $1, $2 );
521 print "Applying pin to $key" if &debug;
523 unless ( exists $oauth{pending}{$key} ) {
524 ¬ice("There isn't a pending oauth request for $key. "
525 . "Try /twitter_login first" );
529 my $twit = $oauth{pending}{$key};
530 my ( $access_token, $access_token_secret );
532 ( $access_token, $access_token_secret ) =
533 $twit->request_access_token( verifier => $pin );
537 ¬ice("Invalid pin, try again.");
541 delete $oauth{pending}{$key};
543 my $store_file = Irssi::settings_get_str("twirssi_oauth_store");
546 if ( open( OAUTH, $store_file ) ) {
556 push @store, "$key $access_token $access_token_secret";
558 if ( open( OAUTH, ">$store_file.new" ) ) {
559 print OAUTH "$_\n" foreach @store;
561 rename "$store_file.new", $store_file
562 or ¬ice("Failed to rename $store_file.new: $!");
564 ¬ice("Failed to write $store_file.new: $!");
567 ¬ice("No persistant storage set for OAuth. "
568 . "Please /set twirssi_oauth_store to a writable filename." );
571 return &verify_twitter_object( $server, $win, $user, $service, $twit );
574 sub verify_twitter_object {
575 my ( $server, $win, $user, $service, $twit ) = @_;
577 if ( my $timeout = Irssi::settings_get_int("twitter_timeout")
578 and $twit->can('ua') )
580 $twit->ua->timeout($timeout);
581 ¬ice("Twitter timeout set to $timeout");
584 unless ( $twit->verify_credentials() ) {
585 ¬ice("Login as $user\@$service failed");
587 if ( not Irssi::settings_get_bool("twirssi_avoid_ssl") ) {
589 "It's possible you're missing one of the modules required for "
590 . "SSL logins. Try setting twirssi_avoid_ssl to on. See "
591 . "http://cpansearch.perl.org/src/GAAS/libwww-perl-5.831/README.SSL "
592 . "for the detailed requirements." );
597 &cmd_switch( ( keys %twits )[0], $server, $win );
602 my $rate_limit = $twit->rate_limit_status();
603 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
605 "Rate limit exceeded, try again after $rate_limit->{reset_time}");
610 print "saving object for $user\@$service" if &debug;
611 $twits{"$user\@$service"} = $twit;
612 Irssi::timeout_remove($poll) if $poll;
613 $poll = Irssi::timeout_add( &get_poll_time * 1000, \&get_updates, "" );
614 ¬ice("Logged in as $user\@$service, loading friends list...");
616 ¬ice( "loaded friends: " . scalar keys %friends );
617 if ( Irssi::settings_get_bool("twirssi_first_run") ) {
618 Irssi::settings_set_bool( "twirssi_first_run", 0 );
626 my ( $data, $server, $win ) = @_;
629 ¬ice("Usage: /twitter_add_follow_extra <username>");
633 $data =~ s/^\s+|\s+$//;
637 if ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
638 ¬ice("Already following all replies by \@$data");
642 $id_map{__fixreplies}{"$user\@$defservice"}{$data} = 1;
643 ¬ice("Will now follow all replies by \@$data");
647 my ( $data, $server, $win ) = @_;
650 ¬ice("Usage: /twitter_del_follow_extra <username>");
654 $data =~ s/^\s+|\s+$//;
658 unless ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
659 ¬ice("Wasn't following all replies by \@$data");
663 delete $id_map{__fixreplies}{"$user\@$defservice"}{$data};
664 ¬ice("Will no longer follow all replies by \@$data");
667 sub cmd_list_follow {
668 my ( $data, $server, $win ) = @_;
671 foreach my $suser ( sort keys %{ $id_map{__fixreplies} } ) {
673 foreach my $fruser ( sort keys %{ $id_map{__fixreplies}{$suser} } ) {
674 $frusers = $frusers ? "$frusers, $fruser" : $fruser;
678 ¬ice("Following all replies as \@$suser: $frusers");
683 ¬ice("Not following all replies by anyone");
688 my ( $data, $server, $win ) = @_;
690 unless ( $twit and $twit->can('search') ) {
691 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
692 . "doesn't support searches." );
696 $data =~ s/^\s+|\s+$//;
700 ¬ice("Usage: /twitter_subscribe <topic>");
704 if ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
705 ¬ice("Already had a subscription for '$data'");
709 $id_map{__searches}{"$user\@$defservice"}{$data} = 1;
710 ¬ice("Added subscription for '$data'");
714 my ( $data, $server, $win ) = @_;
716 unless ( $twit and $twit->can('search') ) {
717 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
718 . "doesn't support searches." );
721 $data =~ s/^\s+|\s+$//;
725 ¬ice("Usage: /twitter_unsubscribe <topic>");
729 unless ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
730 ¬ice("No subscription found for '$data'");
734 delete $id_map{__searches}{"$user\@$defservice"}{$data};
735 ¬ice("Removed subscription for '$data'");
738 sub cmd_list_search {
739 my ( $data, $server, $win ) = @_;
742 foreach my $suser ( sort keys %{ $id_map{__searches} } ) {
744 foreach my $topic ( sort keys %{ $id_map{__searches}{$suser} } ) {
745 $topics = $topics ? "$topics, $topic" : $topic;
749 ¬ice("Search subscriptions for \@$suser: $topics");
754 ¬ice("No search subscriptions set up");
759 my ( $data, $server, $win ) = @_;
761 my $loc = Irssi::settings_get_str("twirssi_location");
763 ¬ice("$loc isn't writable, can't upgrade."
764 . " Perhaps you need to /set twirssi_location?" );
769 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
770 eval { use Digest::MD5; };
773 ¬ice("Failed to load Digest::MD5."
774 . " Try '/twirssi_upgrade nomd5' to skip MD5 verification" );
778 $md5 = get("http://twirssi.com/md5sum");
782 ¬ice("Failed to download md5sum from peeron! Aborting.");
786 unless ( open( CUR, $loc ) ) {
787 ¬ice("Failed to read $loc."
788 . " Check that /set twirssi_location is set to the correct location."
793 my $cur_md5 = Digest::MD5::md5_hex(<CUR>);
796 if ( $cur_md5 eq $md5 ) {
797 ¬ice("Current twirssi seems to be up to date.");
803 Irssi::settings_get_bool("twirssi_upgrade_beta")
804 ? "http://github.com/zigdon/twirssi/raw/master/twirssi.pl"
805 : "http://twirssi.com/twirssi.pl";
806 ¬ice("Downloading twirssi from $URL");
807 LWP::Simple::getstore( $URL, "$loc.upgrade" );
809 unless ( -s "$loc.upgrade" ) {
810 ¬ice("Failed to save $loc.upgrade."
811 . " Check that /set twirssi_location is set to the correct location."
816 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
817 unless ( open( NEW, "$loc.upgrade" ) ) {
818 ¬ice("Failed to read $loc.upgrade."
819 . " Check that /set twirssi_location is set to the correct location."
824 my $new_md5 = Digest::MD5::md5_hex(<NEW>);
827 if ( $new_md5 ne $md5 ) {
828 ¬ice("MD5 verification failed. expected $md5, got $new_md5");
833 rename $loc, "$loc.backup"
834 or ¬ice("Failed to back up $loc: $!. Aborting")
836 rename "$loc.upgrade", $loc
837 or ¬ice("Failed to rename $loc.upgrade: $!. Aborting")
840 my ( $dir, $file ) = ( $loc =~ m{(.*)/([^/]+)$} );
841 if ( -e "$dir/autorun/$file" ) {
842 ¬ice("Updating $dir/autorun/$file");
843 unlink "$dir/autorun/$file"
844 or ¬ice("Failed to remove old $file from autorun: $!");
845 symlink "../$file", "$dir/autorun/$file"
846 or ¬ice("Failed to create symlink in autorun directory: $!");
849 ¬ice("Download complete. Reload twirssi with /script load $file");
858 while ( $page < 11 and $cursor ne "0" )
860 print $fh "type:debug Loading friends page $page...\n"
861 if ( $fh and &debug );
863 if ( ref $twit =~ /^Net::Twitter/ ) {
864 $friends = $twit->friends( { cursor => $cursor } );
865 last unless $friends;
866 $cursor = $friends->{next_cursor};
867 $friends = $friends->{users};
869 $friends = $twit->friends( { page => $page } );
870 last unless $friends;
872 $new_friends{ $_->{screen_name} } = time foreach @$friends;
878 print $fh "type:debug Error during friends list update. Aborted.\n"
883 my ( $added, $removed ) = ( 0, 0 );
884 print $fh "type:debug Scanning for new friends...\n" if ( $fh and &debug );
885 foreach ( keys %new_friends ) {
886 next if exists $friends{$_};
891 print $fh "type:debug Scanning for removed friends...\n"
892 if ( $fh and &debug );
893 foreach ( keys %friends ) {
894 next if exists $new_friends{$_};
899 return ( $added, $removed );
903 print scalar localtime, " - get_updates starting" if &debug;
906 Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
909 ->print( "Can't find a window named '"
910 . Irssi::settings_get_str('twitter_window')
911 . "'. Create it or change the value of twitter_window" );
914 return unless &logged_in($twit);
916 my ( $fh, $filename ) = File::Temp::tempfile();
917 binmode( $fh, ":" . &get_charset );
920 if ($child_pid) { # parent
921 Irssi::timeout_add_once( 5000, 'monitor_child',
922 [ "$filename.done", 0 ] );
923 Irssi::pidwait_add($child_pid);
924 } elsif ( defined $child_pid ) { # child
933 foreach ( keys %twits ) {
934 $error++ unless &do_updates( $fh, $_, $twits{$_}, \%context_cache );
936 if ( $id_map{__fixreplies}{$_} ) {
937 my @frusers = sort keys %{ $id_map{__fixreplies}{$_} };
940 unless &get_timeline( $fh, $frusers[ $fix_replies_index{$_} ],
941 $_, $twits{$_}, \%context_cache );
943 $fix_replies_index{$_}++;
944 $fix_replies_index{$_} = 0
945 if $fix_replies_index{$_} >= @frusers;
946 print $fh "id:$fix_replies_index{$_} ",
947 "account:$_ type:fix_replies_index\n";
951 print $fh "__friends__\n";
953 time - $last_friends_poll >
954 Irssi::settings_get_int('twitter_friends_poll') )
956 print $fh "__updated ", time, "\n";
957 my ( $added, $removed ) = &load_friends($fh);
958 if ( $added + $removed ) {
959 print $fh "type:debug %R***%n Friends list updated: ",
961 sprintf( "%d added", $added ),
962 sprintf( "%d removed", $removed ) ),
967 foreach ( sort keys %friends ) {
968 print $fh "$_ $friends{$_}\n";
972 print $fh "type:debug Update encountered errors. Aborted\n";
973 print $fh "-- $last_poll";
975 print $fh "-- $new_poll";
978 rename $filename, "$filename.done";
981 &ccrap("Failed to fork for updating: $!");
983 print scalar localtime, " - get_updates ends" if &debug;
987 my ( $fh, $username, $obj, $cache ) = @_;
990 my $rate_limit = $obj->rate_limit_status();
991 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
992 ¬ice("Rate limit exceeded for $username");
997 print scalar localtime, " - Polling for updates for $username" if &debug;
1001 if ( $id_map{__last_id}{$username}{timeline} )
1003 $tweets = $obj->home_timeline( { count => 100 } );
1005 $tweets = $obj->home_timeline();
1010 print $fh "type:debug Error during home_timeline call: Aborted.\n";
1011 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1015 unless ( ref $tweets ) {
1016 if ( $obj->can("get_error") ) {
1017 my $error = "Unknown error";
1018 eval { $error = JSON::Any->jsonToObj( $obj->get_error() ) };
1019 unless ($@) { $error = $obj->get_error() }
1021 "type:debug API Error during home_timeline call: Aborted\n";
1022 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($error);
1026 "type:debug API Error during home_timeline call. Aborted.\n";
1032 Irssi::settings_get_str("twirssi_ignored_tags")
1033 ? split /\s*,\s*/, Irssi::settings_get_str("twirssi_ignored_tags")
1036 Irssi::settings_get_str("twirssi_stripped_tags")
1037 ? split /\s*,\s*/, Irssi::settings_get_str("twirssi_stripped_tags")
1039 foreach my $t ( reverse @$tweets ) {
1040 my $text = &get_text( $t, $obj );
1041 my $reply = "tweet";
1044 foreach my $tag (@ignore_tags) {
1045 next unless $text =~ /\b\Q$tag\E\b/i;
1047 $text = "(ignored: $tag) $text" if &debug;
1050 next if not &debug and $match;
1052 foreach my $tag (@strip_tags) {
1053 $text =~ s/\b\Q$tag\E\b//gi;
1056 if ( Irssi::settings_get_bool("show_reply_context")
1057 and $t->{in_reply_to_screen_name} ne $username
1058 and $t->{in_reply_to_screen_name}
1059 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1061 $nicks{ $t->{in_reply_to_screen_name} } = time;
1063 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1065 $cache->{ $t->{in_reply_to_status_id} } =
1066 $obj->show_status( $t->{in_reply_to_status_id} );
1070 $context = $cache->{ $t->{in_reply_to_status_id} };
1073 my $ctext = &get_text( $context, $obj );
1074 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1075 $context->{id}, $username,
1076 $context->{user}{screen_name}, $ctext;
1081 if $t->{user}{screen_name} eq $username
1082 and not Irssi::settings_get_bool("show_own_tweets");
1083 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1084 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1085 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1087 printf $fh "id:%s account:%s type:last_id timeline\n",
1088 $new_poll_id, $username;
1090 print scalar localtime, " - Polling for replies since ",
1091 $id_map{__last_id}{$username}{reply}
1095 if ( $id_map{__last_id}{$username}{reply} )
1097 $tweets = $obj->replies(
1098 { since_id => $id_map{__last_id}{$username}{reply} } )
1101 $tweets = $obj->replies() || [];
1106 print $fh "type:debug Error during replies call. Aborted.\n";
1110 foreach my $t ( reverse @$tweets ) {
1112 if exists $friends{ $t->{user}{screen_name} };
1114 my $text = &get_text( $t, $obj );
1115 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1116 $t->{id}, $username, $t->{user}{screen_name}, $text;
1117 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1119 printf $fh "id:%s account:%s type:last_id reply\n", $new_poll_id, $username;
1121 print scalar localtime, " - Polling for DMs" if &debug;
1124 if ( $id_map{__last_id}{$username}{dm} )
1126 $tweets = $obj->direct_messages(
1127 { since_id => $id_map{__last_id}{$username}{dm} } )
1130 $tweets = $obj->direct_messages() || [];
1135 print $fh "type:debug Error during direct_messages call. Aborted.\n";
1139 foreach my $t ( reverse @$tweets ) {
1140 my $text = decode_entities( $t->{text} );
1141 $text =~ s/[\n\r]/ /g;
1142 printf $fh "id:%s account:%s nick:%s type:dm %s\n",
1143 $t->{id}, $username, $t->{sender_screen_name}, $text;
1144 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1146 printf $fh "id:%s account:%s type:last_id dm\n", $new_poll_id, $username;
1148 print scalar localtime, " - Polling for subscriptions" if &debug;
1149 if ( $obj->can('search') and $id_map{__searches}{$username} ) {
1151 foreach my $topic ( sort keys %{ $id_map{__searches}{$username} } ) {
1152 print $fh "type:debug searching for $topic since ",
1153 "$id_map{__searches}{$username}{$topic}\n";
1155 $search = $obj->search(
1158 since_id => $id_map{__searches}{$username}{$topic}
1165 "type:debug Error during search($topic) call. Aborted.\n";
1169 unless ( $search->{max_id} ) {
1170 print $fh "type:debug Invalid search results when searching",
1171 " for $topic. Aborted.\n";
1175 $id_map{__searches}{$username}{$topic} = $search->{max_id};
1176 $topic =~ s/ /%20/g;
1177 printf $fh "id:%s account:%s type:searchid topic:%s\n",
1178 $search->{max_id}, $username, $topic;
1180 foreach my $t ( reverse @{ $search->{results} } ) {
1181 my $text = &get_text( $t, $obj );
1182 printf $fh "id:%s account:%s nick:%s type:search topic:%s %s\n",
1183 $t->{id}, $username, $t->{from_user}, $topic, $text;
1184 $new_poll_id = $t->{id}
1186 or $t->{id} < $new_poll_id;
1191 print scalar localtime, " - Done" if &debug;
1197 my ( $fh, $target, $username, $obj, $cache ) = @_;
1199 my $last_id = $id_map{__last_id}{$username}{$target};
1201 print $fh "type:debug get_timeline("
1202 . "$fix_replies_index{$username}=$target > $last_id) started."
1203 . " username = $username\n";
1205 $tweets = $obj->user_timeline(
1208 ( $last_id ? ( since_id => $last_id ) : () ),
1215 "type:debug Error during user_timeline($target) call: Aborted.\n";
1216 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1222 "type:debug user_timeline($target) call returned undef! Aborted\n";
1226 foreach my $t ( reverse @$tweets ) {
1227 my $text = &get_text( $t, $obj );
1228 my $reply = "tweet";
1229 if ( Irssi::settings_get_bool("show_reply_context")
1230 and $t->{in_reply_to_screen_name} ne $username
1231 and $t->{in_reply_to_screen_name}
1232 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1234 $nicks{ $t->{in_reply_to_screen_name} } = time;
1236 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1238 $cache->{ $t->{in_reply_to_status_id} } =
1239 $obj->show_status( $t->{in_reply_to_status_id} );
1243 $context = $cache->{ $t->{in_reply_to_status_id} };
1246 my $ctext = &get_text( $context, $obj );
1247 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1248 $context->{id}, $username,
1249 $context->{user}{screen_name}, $ctext;
1253 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1254 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1255 $last_id = $t->{id} if $last_id < $t->{id};
1257 printf $fh "id:%s account:%s type:last_id_fixreplies %s\n",
1258 $last_id, $username, $target;
1265 my $filename = $data->[0];
1266 my $attempt = $data->[1];
1268 print scalar localtime, " - checking child log at $filename ($attempt)"
1270 my ($new_last_poll);
1272 # reap any random leftover processes - work around a bug in irssi on gentoo
1273 waitpid( -1, WNOHANG );
1275 # first time we run we don't want to print out *everything*, so we just
1278 if ( open FILE, $filename ) {
1279 binmode FILE, ":" . &get_charset;
1283 last if /^__friends__/;
1284 unless (/\n$/) { # skip partial lines
1285 # print "Skipping partial line: $_" if &debug;
1292 foreach my $key (qw/id account nick type topic/) {
1293 if (s/^$key:((?:\S|\\ )+)\s*//) {
1295 $meta{$key} =~ s/%20/ /g;
1299 if ( $meta{type} and $meta{type} eq 'fix_replies_index' ) {
1300 $fix_replies_index{ $meta{account} } = $meta{id};
1301 print "fix_replies_index for $meta{account} set to $meta{id}"
1306 if ( not $meta{type} or $meta{type} !~ /searchid|last_id/ ) {
1307 if ( exists $meta{id} and exists $new_cache{ $meta{id} } ) {
1311 $new_cache{ $meta{id} } = time;
1313 if ( exists $meta{id} and exists $tweet_cache{ $meta{id} } ) {
1319 $meta{account} =~ s/\@(\w+)$//;
1320 $meta{service} = $1;
1322 lc $meta{service} eq
1323 lc Irssi::settings_get_str("twirssi_default_service") )
1325 $account = "$meta{account}: "
1326 if lc "$meta{account}\@$meta{service}" ne lc
1327 "$user\@$defservice";
1329 $account = "$meta{account}\@$meta{service}: ";
1333 if ( $meta{type} ne 'dm' and $meta{nick} and $meta{id} ) {
1334 $marker = ( $id_map{__indexes}{ $meta{nick} } + 1 ) % 100;
1335 $id_map{ lc $meta{nick} }[$marker] = $meta{id};
1336 $id_map{__indexes}{ $meta{nick} } = $marker;
1337 $id_map{__tweets}{ lc $meta{nick} }[$marker] = $_;
1338 $marker = ":$marker";
1342 $irssi_to_mirc_colors{ Irssi::settings_get_str("hilight_color") };
1343 my $nick = "\@$meta{account}";
1344 if ( $_ =~ /\Q$nick\E(?:\W|$)/i
1345 and Irssi::settings_get_bool("twirssi_hilights") )
1347 $meta{nick} = "\cC$hilight_color$meta{nick}\cO";
1348 $hilight = MSGLEVEL_HILIGHT;
1351 if ( $meta{type} =~ /tweet|reply/ ) {
1354 ( MSGLEVEL_PUBLIC | $hilight ),
1355 $meta{type}, $account, $meta{nick}, $marker, $_
1357 } elsif ( $meta{type} eq 'search' ) {
1360 ( MSGLEVEL_PUBLIC | $hilight ),
1361 $meta{type}, $account, $meta{topic},
1362 $meta{nick}, $marker, $_
1365 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1367 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1369 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1372 } elsif ( $meta{type} eq 'dm' ) {
1375 ( MSGLEVEL_MSGS | $hilight ),
1376 $meta{type}, $account, $meta{nick}, $_
1378 } elsif ( $meta{type} eq 'searchid' ) {
1379 print "Search '$meta{topic}' returned id $meta{id}" if &debug;
1382 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1384 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1386 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1389 print "Search '$meta{topic}' returned invalid id $meta{id}";
1391 } elsif ( $meta{type} eq 'last_id' ) {
1392 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1394 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1396 } elsif ( $meta{type} eq 'last_id_fixreplies' ) {
1397 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1399 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1401 } elsif ( $meta{type} eq 'error' ) {
1402 push @lines, [ MSGLEVEL_MSGS, $_ ];
1403 } elsif ( $meta{type} eq 'debug' ) {
1404 print "$_" if &debug,;
1406 print "Unknown line type $meta{type}: $_" if &debug,;
1412 if (/^__updated (\d+)$/) {
1413 $last_friends_poll = $1;
1414 print "Friend list updated" if &debug;
1419 $new_last_poll = $1;
1420 if ( $new_last_poll >= $last_poll ) {
1423 print "Impossible! ",
1424 "new_last_poll=$new_last_poll < last_poll=$last_poll!"
1426 undef $new_last_poll;
1430 my ( $f, $t ) = split ' ', $_;
1431 $nicks{$f} = $friends{$f} = $t;
1434 if ($new_last_poll) {
1435 print "new last_poll = $new_last_poll" if &debug;
1436 print "new last_poll_id = ", Dumper( $id_map{__last_id} ) if &debug;
1438 print "First call, not printing updates" if &debug;
1440 foreach my $line (@lines) {
1441 $window->printformat(
1443 "twirssi_" . $line->[1],
1444 @$line[ 2 .. $#$line - 1 ],
1445 &hilight( $line->[-1] )
1452 or warn "Failed to remove $filename: $!"
1455 # commit the pending cache lines to the actual cache, now that
1456 # we've printed our output
1457 %tweet_cache = ( %tweet_cache, %new_cache );
1459 # keep enough cached tweets, to make sure we don't show duplicates.
1460 foreach ( keys %tweet_cache ) {
1461 next if $tweet_cache{$_} >= $last_poll - 3600;
1462 delete $tweet_cache{$_};
1464 $last_poll = $new_last_poll;
1466 # make sure the pid is removed from the waitpid list
1467 Irssi::pidwait_remove($child_pid);
1469 # and that we don't leave any zombies behind, somehow
1470 waitpid( -1, WNOHANG );
1475 Irssi::settings_get_str("twirssi_replies_store") )
1477 if ( open JSON, ">$file" ) {
1478 print JSON JSON::Any->objToJson( \%id_map );
1481 &ccrap("Failed to write replies to $file: $!");
1492 if ( $attempt < 24 ) {
1493 Irssi::timeout_add_once( 5000, 'monitor_child',
1494 [ $filename, $attempt + 1 ] );
1496 print "Giving up on polling $filename" if &debug;
1497 Irssi::pidwait_remove($child_pid);
1498 waitpid( -1, WNOHANG );
1499 unlink $filename unless &debug;
1501 return unless Irssi::settings_get_bool("twirssi_notify_timeouts");
1504 my @time = localtime($last_poll);
1505 if ( time - $last_poll < 24 * 60 * 60 ) {
1506 $since = sprintf( "%d:%02d", @time[ 2, 1 ] );
1508 $since = scalar localtime($last_poll);
1511 if ( not $failwhale and time - $last_poll > 60 * 60 ) {
1516 q{ .--./ / | _.---.| },
1525 if ( time - $last_poll < 600 ) {
1526 &ccrap("Haven't been able to get updated tweets since $since");
1532 return Irssi::settings_get_bool("twirssi_debug");
1536 foreach my $msg (@_) {
1537 $window->print( "%R***%n $msg", MSGLEVEL_PUBLIC );
1542 foreach my $msg (@_) {
1543 $window->print( "%R***%n $msg", MSGLEVEL_CLIENTCRAP );
1550 if ( Irssi::settings_get_bool("tweet_to_away")
1552 and $data !~ /^[dD] / )
1555 Irssi::server_find_tag( Irssi::settings_get_str("bitlbee_server") );
1557 $server->send_raw("away :$data");
1560 &ccrap( "Can't find bitlbee server.",
1561 "Update bitlbee_server or disable tweet_to_away" );
1571 my $noalert = shift;
1573 if ( length $data > 140 ) {
1574 ¬ice( "Tweet too long (" . length($data) . " characters) - aborted" )
1582 sub valid_username {
1583 my $username = shift;
1585 $username = &normalize_username($username);
1587 unless ( exists $twits{$username} ) {
1588 ¬ice("Unknown username $username");
1598 ¬ice("Not logged in! Use /twitter_login username pass!");
1606 my ( $complist, $window, $word, $linestart, $want_space ) = @_;
1609 $linestart =~ /^\/(?:retweet|twitter_reply)(?:_as)?\s*$/
1610 or ( Irssi::settings_get_bool("twirssi_use_reply_aliases")
1611 and $linestart =~ /^\/reply(?:_as)?\s*$/ )
1613 { # /twitter_reply gets a nick:num
1615 @$complist = map { "$_:$id_map{__indexes}{$_}" }
1616 sort { $nicks{$b} <=> $nicks{$a} }
1618 keys %{ $id_map{__indexes} };
1622 /^\/(twitter_unfriend|twitter_add_follow_extra|twitter_del_follow_extra)\s*$/
1624 { # /twitter_unfriend gets a nick
1626 push @$complist, grep /^\Q$word/i,
1627 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1630 # /tweet, /tweet_as, /dm, /dm_as - complete @nicks (and nicks as the first
1632 if ( $linestart =~ /^\/(?:tweet|dm)/ ) {
1633 my $prefix = $word =~ s/^@//;
1634 $prefix = 0 if $linestart eq '/dm' or $linestart eq '/dm_as';
1635 push @$complist, grep /^\Q$word/i,
1636 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1637 @$complist = map { "\@$_" } @$complist if $prefix;
1641 sub event_send_text {
1642 my ( $line, $server, $win ) = @_;
1643 my $awin = Irssi::active_win();
1645 # if the window where we got our text was the twitter window, and the user
1646 # wants to be lazy, tweet away!
1647 if ( ( $awin->get_active_name() eq $window->{name} )
1648 and Irssi::settings_get_bool("tweet_window_input") )
1650 &cmd_tweet( $line, $server, $win );
1655 my $poll = Irssi::settings_get_int("twitter_poll_interval");
1656 return $poll if $poll >= 60;
1661 my $charset = Irssi::settings_get_str("twirssi_charset");
1662 return "utf8" if $charset =~ /^\s*$/;
1669 if ( Irssi::settings_get_str("twirssi_nick_color") ) {
1670 my $c = Irssi::settings_get_str("twirssi_nick_color");
1671 $c = $irssi_to_mirc_colors{$c};
1672 $text =~ s/(^|\W)\@(\w+)/$1\cC$c\@$2\cO/g if $c;
1674 if ( Irssi::settings_get_str("twirssi_topic_color") ) {
1675 my $c = Irssi::settings_get_str("twirssi_topic_color");
1676 $c = $irssi_to_mirc_colors{$c};
1677 $text =~ s/(^|\W)(\#|\!)([-\w]+)/$1\cC$c$2$3\cO/g if $c;
1679 $text =~ s/[\n\r]/ /g;
1687 my $provider = Irssi::settings_get_str("short_url_provider");
1690 Irssi::settings_get_bool("twirssi_always_shorten")
1691 or &too_long( $data, 1 )
1697 if ( $provider eq 'Bitly' ) {
1698 @args[ 1, 2 ] = split ',',
1699 Irssi::settings_get_str("short_url_args"), 2;
1700 unless ( @args == 3 ) {
1702 "WWW::Shorten::Bitly requires a username and API key.",
1703 "Set short_url_args to username,API_key or change your",
1704 "short_url_provider."
1706 return decode &get_charset, $data;
1710 foreach my $url ( $data =~ /(https?:\/\/\S+[\w\/])/g ) {
1713 my $short = makeashorterlink(@args);
1715 $data =~ s/\Q$url/$short/g;
1717 ¬ice("Failed to shorten $url!");
1723 return decode &get_charset, $data;
1726 sub normalize_username {
1729 my ( $username, $service ) = split /\@/, $user, 2;
1731 $service = ucfirst lc $service;
1734 ucfirst lc Irssi::settings_get_str("twirssi_default_service");
1735 unless ( exists $twits{"$username\@$service"} ) {
1737 foreach my $t ( sort keys %twits ) {
1738 next unless $t =~ /^\Q$username\E\@(Twitter|Identica)/;
1744 ¬ice("Can't find a logged in user '$user'");
1749 return "$username\@$service";
1755 my $text = decode_entities( $tweet->{text} );
1756 if ( $tweet->{truncated} ) {
1757 if ( exists $tweet->{retweeted_status} ) {
1758 $text = "RT \@$tweet->{retweeted_status}{user}{screen_name}: "
1759 . "$tweet->{retweeted_status}{text}";
1760 } elsif ( $object->isa('Net::Twitter::Lite') ) {
1761 $text .= " -- http://twitter.com/$tweet->{user}{screen_name}"
1762 . "/status/$tweet->{id}";
1766 $text =~ s/[\n\r]/ /g;
1771 Irssi::signal_add( "send text", "event_send_text" );
1773 Irssi::theme_register(
1775 'twirssi_tweet', '[$0%B@$1%n$2] $3',
1776 'twirssi_search', '[$0%r$1%n:%B@$2%n$3] $4',
1777 'twirssi_reply', '[$0\--> %B@$1%n$2] $3',
1778 'twirssi_dm', '[$0%r@$1%n (%WDM%n)] $2',
1779 'twirssi_error', 'ERROR: $0',
1783 Irssi::settings_add_int( "twirssi", "twitter_poll_interval", 300 );
1784 Irssi::settings_add_str( "twirssi", "twirssi_charset", "utf8" );
1785 Irssi::settings_add_str( "twirssi", "twitter_window", "twitter" );
1786 Irssi::settings_add_str( "twirssi", "bitlbee_server", "bitlbee" );
1787 Irssi::settings_add_str( "twirssi", "short_url_provider", "TinyURL" );
1788 Irssi::settings_add_str( "twirssi", "short_url_args", undef );
1789 Irssi::settings_add_str( "twirssi", "twitter_usernames", undef );
1790 Irssi::settings_add_str( "twirssi", "twitter_passwords", undef );
1791 Irssi::settings_add_str( "twirssi", "twirssi_default_service", "Twitter" );
1792 Irssi::settings_add_str( "twirssi", "twirssi_nick_color", "%B" );
1793 Irssi::settings_add_str( "twirssi", "twirssi_topic_color", "%r" );
1794 Irssi::settings_add_str( "twirssi", "twirssi_ignored_tags", "" );
1795 Irssi::settings_add_str( "twirssi", "twirssi_stripped_tags", "" );
1796 Irssi::settings_add_str( "twirssi", "twirssi_retweet_format",
1797 'RT $n: "$t" ${-- $c$}' );
1798 Irssi::settings_add_str( "twirssi", "twirssi_location",
1799 Irssi::get_irssi_dir . "/scripts/twirssi.pl" );
1800 Irssi::settings_add_str( "twirssi", "twirssi_replies_store",
1801 Irssi::get_irssi_dir . "/scripts/twirssi.json" );
1802 Irssi::settings_add_str( "twirssi", "twirssi_oauth_store",
1803 Irssi::get_irssi_dir . "/scripts/twirssi.oauth" );
1805 Irssi::settings_add_int( "twirssi", "twitter_friends_poll", 600 );
1806 Irssi::settings_add_int( "twirssi", "twitter_timeout", 30 );
1808 Irssi::settings_add_bool( "twirssi", "twirssi_upgrade_beta", 0 );
1809 Irssi::settings_add_bool( "twirssi", "tweet_to_away", 0 );
1810 Irssi::settings_add_bool( "twirssi", "show_reply_context", 0 );
1811 Irssi::settings_add_bool( "twirssi", "show_own_tweets", 1 );
1812 Irssi::settings_add_bool( "twirssi", "twirssi_debug", 0 );
1813 Irssi::settings_add_bool( "twirssi", "twirssi_first_run", 1 );
1814 Irssi::settings_add_bool( "twirssi", "twirssi_replies_autonick", 1 );
1815 Irssi::settings_add_bool( "twirssi", "twirssi_use_reply_aliases", 0 );
1816 Irssi::settings_add_bool( "twirssi", "twirssi_notify_timeouts", 1 );
1817 Irssi::settings_add_bool( "twirssi", "twirssi_hilights", 1 );
1818 Irssi::settings_add_bool( "twirssi", "twirssi_always_shorten", 0 );
1819 Irssi::settings_add_bool( "twirssi", "tweet_window_input", 0 );
1820 Irssi::settings_add_bool( "twirssi", "twirssi_avoid_ssl", 0 );
1821 Irssi::settings_add_bool( "twirssi", "twirssi_use_oauth", 1 );
1823 $last_poll = time - &get_poll_time;
1824 $window = Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
1827 ->print( "Couldn't find a window named '"
1828 . Irssi::settings_get_str('twitter_window')
1829 . "', trying to create it." );
1831 Irssi::Windowitem::window_create(
1832 Irssi::settings_get_str('twitter_window'), 1 );
1833 $window->set_name( Irssi::settings_get_str('twitter_window') );
1837 Irssi::command_bind( "dm", "cmd_direct" );
1838 Irssi::command_bind( "dm_as", "cmd_direct_as" );
1839 Irssi::command_bind( "tweet", "cmd_tweet" );
1840 Irssi::command_bind( "tweet_as", "cmd_tweet_as" );
1841 Irssi::command_bind( "retweet", "cmd_retweet" );
1842 Irssi::command_bind( "retweet_as", "cmd_retweet_as" );
1843 Irssi::command_bind( "twitter_reply", "cmd_reply" );
1844 Irssi::command_bind( "twitter_reply_as", "cmd_reply_as" );
1845 Irssi::command_bind( "twitter_login", "cmd_login" );
1846 Irssi::command_bind( "twitter_logout", "cmd_logout" );
1847 Irssi::command_bind( "twitter_switch", "cmd_switch" );
1848 Irssi::command_bind( "twitter_subscribe", "cmd_add_search" );
1849 Irssi::command_bind( "twitter_unsubscribe", "cmd_del_search" );
1850 Irssi::command_bind( "twitter_list_subscriptions", "cmd_list_search" );
1851 Irssi::command_bind( "twirssi_upgrade", "cmd_upgrade" );
1852 Irssi::command_bind( "twirssi_oauth", "cmd_oauth" );
1853 Irssi::command_bind( "twitter_updates", "get_updates" );
1854 Irssi::command_bind( "twitter_add_follow_extra", "cmd_add_follow" );
1855 Irssi::command_bind( "twitter_del_follow_extra", "cmd_del_follow" );
1856 Irssi::command_bind( "twitter_list_follow_extra", "cmd_list_follow" );
1857 Irssi::command_bind( "bitlbee_away", "update_away" );
1858 if ( Irssi::settings_get_bool("twirssi_use_reply_aliases") ) {
1859 Irssi::command_bind( "reply", "cmd_reply" );
1860 Irssi::command_bind( "reply_as", "cmd_reply_as" );
1862 Irssi::command_bind(
1865 print "twits: ", join ", ",
1866 map { "u: $_->{username}\@" . ref($_) } values %twits;
1867 print "selected: $user\@$defservice";
1868 print "friends: ", join ", ", sort keys %friends;
1869 print "nicks: ", join ", ", sort keys %nicks;
1870 print "searches: ", Dumper \%{ $id_map{__searches} };
1871 print "last poll: $last_poll";
1872 if ( open DUMP, ">/tmp/twirssi.cache.txt" ) {
1873 print DUMP Dumper \%tweet_cache;
1875 print "cache written out to /tmp/twirssi.cache.txt";
1879 Irssi::command_bind(
1883 "Twirssi v$VERSION; "
1885 $Net::Twitter::Lite::VERSION
1886 ? "Net::Twitter v$Net::Twitter::Lite::VERSION. "
1890 $Net::Identica::VERSION
1891 ? "Net::Identica v$Net::Identica::VERSION. "
1895 . JSON::Any::handler()
1896 . ". See details at http://twirssi.com/"
1900 Irssi::command_bind(
1903 "/twitter_follow <username>",
1905 sub { ¬ice("Following $_[0]"); $nicks{ $_[0] } = time; }
1908 Irssi::command_bind(
1911 "/twitter_unfriend <username>",
1913 sub { ¬ice("Stopped following $_[0]"); delete $nicks{ $_[0] }; }
1916 Irssi::command_bind(
1917 "twitter_device_updates",
1919 "/twitter_device_updates none|im|sms",
1920 "update_delivery_device",
1921 sub { ¬ice("Device updated to $_[0]"); }
1924 Irssi::command_bind(
1927 "/twitter_block <username>",
1929 sub { ¬ice("Blocked $_[0]"); }
1932 Irssi::command_bind(
1935 "/twitter_unblock <username>",
1937 sub { ¬ice("Unblock $_[0]"); }
1940 Irssi::signal_add_last( 'complete word' => \&sig_complete );
1943 " %Y<%C(%B^%C)%N TWIRSSI v%R$VERSION%N",
1944 " %C(_(\\%N http://twirssi.com/ for full docs",
1945 " %Y||%C `%N Log in with /twitter_login, send updates with /tweet"
1948 my $file = Irssi::settings_get_str("twirssi_replies_store");
1949 if ( $file and -r $file ) {
1950 if ( open( JSON, $file ) ) {
1955 my $ref = JSON::Any->jsonToObj($json);
1957 my $num = keys %{ $id_map{__indexes} };
1958 ¬ice( sprintf "Loaded old replies from %d contact%s.",
1959 $num, ( $num == 1 ? "" : "s" ) );
1964 ¬ice("Failed to load old replies from $file: $!");
1968 if ( my $provider = Irssi::settings_get_str("short_url_provider") ) {
1969 ¬ice("Loading WWW::Shorten::$provider...");
1970 eval "use WWW::Shorten::$provider;";
1974 "Failed to load WWW::Shorten::$provider - either clear",
1975 "short_url_provider or install the CPAN module"
1980 if ( my $autouser = Irssi::settings_get_str("twitter_usernames") ) {
1987 ->print( "Create a window named "
1988 . Irssi::settings_get_str('twitter_window')
1989 . " or change the value of twitter_window. Then, reload twirssi." );
1992 # vim: set sts=4 expandtab: