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; };
558 "ERROR: Failed to get OAuth authorization_url. Try again later."
563 ¬ice("Twirssi not autorized to access $service for $user.");
565 "Please authorize at the following url, then enter the pin "
567 ¬ice("supplied with /twirssi_oauth $user\@$service <pin>");
570 $oauth{pending}{"$user\@$service"} = $twit;
575 $twit = Net::Twitter->new(
576 $service eq 'Identica' ? ( identica => 1 ) : (),
580 ssl => Irssi::settings_get_bool("twirssi_avoid_ssl") ? 0 : 1,
585 ¬ice("Failed to create object! Aborting.");
589 return &verify_twitter_object( $server, $win, $user, $service, $twit );
593 my ( $data, $server, $win ) = @_;
594 my ( $key, $pin ) = split ' ', $data;
595 my ( $user, $service );
596 $key = &normalize_username($key);
597 if ( $key =~ /^(.*)@(Twitter|Identica)$/ ) {
598 ( $user, $service ) = ( $1, $2 );
601 print "Applying pin to $key" if &debug;
603 unless ( exists $oauth{pending}{$key} ) {
604 ¬ice("There isn't a pending oauth request for $key. "
605 . "Try /twitter_login first" );
609 my $twit = $oauth{pending}{$key};
610 my ( $access_token, $access_token_secret );
612 ( $access_token, $access_token_secret ) =
613 $twit->request_access_token( verifier => $pin );
617 ¬ice("Invalid pin, try again.");
621 delete $oauth{pending}{$key};
623 my $store_file = Irssi::settings_get_str("twirssi_oauth_store");
626 if ( open( OAUTH, $store_file ) ) {
636 push @store, "$key $access_token $access_token_secret";
638 if ( open( OAUTH, ">$store_file.new" ) ) {
639 print OAUTH "$_\n" foreach @store;
641 rename "$store_file.new", $store_file
642 or ¬ice("Failed to rename $store_file.new: $!");
644 ¬ice("Failed to write $store_file.new: $!");
647 ¬ice("No persistant storage set for OAuth. "
648 . "Please /set twirssi_oauth_store to a writable filename." );
651 return &verify_twitter_object( $server, $win, $user, $service, $twit );
654 sub verify_twitter_object {
655 my ( $server, $win, $user, $service, $twit ) = @_;
657 if ( my $timeout = Irssi::settings_get_int("twitter_timeout")
658 and $twit->can('ua') )
660 $twit->ua->timeout($timeout);
661 ¬ice("Twitter timeout set to $timeout");
664 unless ( $twit->verify_credentials() ) {
665 ¬ice("Login as $user\@$service failed");
667 if ( not Irssi::settings_get_bool("twirssi_avoid_ssl") ) {
669 "It's possible you're missing one of the modules required for "
670 . "SSL logins. Try setting twirssi_avoid_ssl to on. See "
671 . "http://cpansearch.perl.org/src/GAAS/libwww-perl-5.831/README.SSL "
672 . "for the detailed requirements." );
677 &cmd_switch( ( keys %twits )[0], $server, $win );
682 my $rate_limit = $twit->rate_limit_status();
683 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
685 "Rate limit exceeded, try again after $rate_limit->{reset_time}");
690 print "saving object for $user\@$service" if &debug;
691 $twits{"$user\@$service"} = $twit;
692 Irssi::timeout_remove($poll) if $poll;
693 $poll = Irssi::timeout_add( &get_poll_time * 1000, \&get_updates, "" );
694 ¬ice("Logged in as $user\@$service, loading friends list...");
696 ¬ice( "loaded friends: ", scalar keys %friends );
697 if ( Irssi::settings_get_bool("twirssi_first_run") ) {
698 Irssi::settings_set_bool( "twirssi_first_run", 0 );
706 my ( $data, $server, $win ) = @_;
709 ¬ice("Usage: /twitter_add_follow_extra <username>");
713 $data =~ s/^\s+|\s+$//;
717 if ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
718 ¬ice("Already following all replies by \@$data");
722 $id_map{__fixreplies}{"$user\@$defservice"}{$data} = 1;
723 ¬ice("Will now follow all replies by \@$data");
727 my ( $data, $server, $win ) = @_;
730 ¬ice("Usage: /twitter_del_follow_extra <username>");
734 $data =~ s/^\s+|\s+$//;
738 unless ( exists $id_map{__fixreplies}{"$user\@$defservice"}{$data} ) {
739 ¬ice("Wasn't following all replies by \@$data");
743 delete $id_map{__fixreplies}{"$user\@$defservice"}{$data};
744 ¬ice("Will no longer follow all replies by \@$data");
747 sub cmd_list_follow {
748 my ( $data, $server, $win ) = @_;
751 foreach my $suser ( sort keys %{ $id_map{__fixreplies} } ) {
753 foreach my $fruser ( sort keys %{ $id_map{__fixreplies}{$suser} } ) {
754 $frusers = $frusers ? "$frusers, $fruser" : $fruser;
758 ¬ice("Following all replies as \@$suser: $frusers");
763 ¬ice("Not following all replies by anyone");
768 my ( $data, $server, $win ) = @_;
770 unless ( $twit and $twit->can('search') ) {
771 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
772 . "doesn't support searches." );
776 $data =~ s/^\s+|\s+$//;
780 ¬ice("Usage: /twitter_subscribe <topic>");
784 if ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
785 ¬ice("Already had a subscription for '$data'");
789 $id_map{__searches}{"$user\@$defservice"}{$data} = 1;
790 ¬ice("Added subscription for '$data'");
794 my ( $data, $server, $win ) = @_;
796 unless ( $twit and $twit->can('search') ) {
797 ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
798 . "doesn't support searches." );
801 $data =~ s/^\s+|\s+$//;
805 ¬ice("Usage: /twitter_unsubscribe <topic>");
809 unless ( exists $id_map{__searches}{"$user\@$defservice"}{$data} ) {
810 ¬ice("No subscription found for '$data'");
814 delete $id_map{__searches}{"$user\@$defservice"}{$data};
815 ¬ice("Removed subscription for '$data'");
818 sub cmd_list_search {
819 my ( $data, $server, $win ) = @_;
822 foreach my $suser ( sort keys %{ $id_map{__searches} } ) {
824 foreach my $topic ( sort keys %{ $id_map{__searches}{$suser} } ) {
825 $topics = $topics ? "$topics, $topic" : $topic;
829 ¬ice("Search subscriptions for \@$suser: $topics");
834 ¬ice("No search subscriptions set up");
839 my ( $data, $server, $win ) = @_;
841 my $loc = Irssi::settings_get_str("twirssi_location");
843 ¬ice("$loc isn't writable, can't upgrade."
844 . " Perhaps you need to /set twirssi_location?" );
849 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
850 eval { use Digest::MD5; };
853 ¬ice("Failed to load Digest::MD5."
854 . " Try '/twirssi_upgrade nomd5' to skip MD5 verification" );
858 $md5 = get("http://twirssi.com/md5sum");
862 ¬ice("Failed to download md5sum from peeron! Aborting.");
866 unless ( open( CUR, $loc ) ) {
867 ¬ice("Failed to read $loc."
868 . " Check that /set twirssi_location is set to the correct location."
873 my $cur_md5 = Digest::MD5::md5_hex(<CUR>);
876 if ( $cur_md5 eq $md5 ) {
877 ¬ice("Current twirssi seems to be up to date.");
883 Irssi::settings_get_bool("twirssi_upgrade_beta")
884 ? "http://github.com/zigdon/twirssi/raw/master/twirssi.pl"
885 : "http://twirssi.com/twirssi.pl";
886 ¬ice("Downloading twirssi from $URL");
887 LWP::Simple::getstore( $URL, "$loc.upgrade" );
889 unless ( -s "$loc.upgrade" ) {
890 ¬ice("Failed to save $loc.upgrade."
891 . " Check that /set twirssi_location is set to the correct location."
896 unless ( $data or Irssi::settings_get_bool("twirssi_upgrade_beta") ) {
897 unless ( open( NEW, "$loc.upgrade" ) ) {
898 ¬ice("Failed to read $loc.upgrade."
899 . " Check that /set twirssi_location is set to the correct location."
904 my $new_md5 = Digest::MD5::md5_hex(<NEW>);
907 if ( $new_md5 ne $md5 ) {
908 ¬ice("MD5 verification failed. expected $md5, got $new_md5");
913 rename $loc, "$loc.backup"
914 or ¬ice("Failed to back up $loc: $!. Aborting")
916 rename "$loc.upgrade", $loc
917 or ¬ice("Failed to rename $loc.upgrade: $!. Aborting")
920 my ( $dir, $file ) = ( $loc =~ m{(.*)/([^/]+)$} );
921 if ( -e "$dir/autorun/$file" ) {
922 ¬ice("Updating $dir/autorun/$file");
923 unlink "$dir/autorun/$file"
924 or ¬ice("Failed to remove old $file from autorun: $!");
925 symlink "../$file", "$dir/autorun/$file"
926 or ¬ice("Failed to create symlink in autorun directory: $!");
929 ¬ice("Download complete. Reload twirssi with /script load $file");
938 while ( $page < 11 and $cursor ne "0" )
940 print $fh "type:debug Loading friends page $page...\n"
941 if ( $fh and &debug );
943 if ( ref $twit =~ /^Net::Twitter/ ) {
944 $friends = $twit->friends( { cursor => $cursor } );
945 last unless $friends;
946 $cursor = $friends->{next_cursor};
947 $friends = $friends->{users};
949 $friends = $twit->friends( { page => $page } );
950 last unless $friends;
952 $new_friends{ $_->{screen_name} } = time foreach @$friends;
958 print $fh "type:debug Error during friends list update. Aborted.\n"
963 my ( $added, $removed ) = ( 0, 0 );
964 print $fh "type:debug Scanning for new friends...\n" if ( $fh and &debug );
965 foreach ( keys %new_friends ) {
966 next if exists $friends{$_};
971 print $fh "type:debug Scanning for removed friends...\n"
972 if ( $fh and &debug );
973 foreach ( keys %friends ) {
974 next if exists $new_friends{$_};
979 return ( $added, $removed );
983 print scalar localtime, " - get_updates starting" if &debug;
986 Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
989 ->print( "Can't find a window named '"
990 . Irssi::settings_get_str('twitter_window')
991 . "'. Create it or change the value of twitter_window" );
994 return unless &logged_in($twit);
996 my ( $fh, $filename ) = File::Temp::tempfile();
997 binmode( $fh, ":utf8" );
1000 if ($child_pid) { # parent
1001 Irssi::timeout_add_once( 5000, 'monitor_child',
1002 [ "$filename.done", 0 ] );
1003 Irssi::pidwait_add($child_pid);
1004 } elsif ( defined $child_pid ) { # child
1009 my $new_poll = time;
1013 foreach ( keys %twits ) {
1014 $error++ unless &do_updates( $fh, $_, $twits{$_}, \%context_cache );
1016 if ( $id_map{__fixreplies}{$_} ) {
1017 my @frusers = sort keys %{ $id_map{__fixreplies}{$_} };
1020 unless &get_timeline( $fh, $frusers[ $fix_replies_index{$_} ],
1021 $_, $twits{$_}, \%context_cache );
1023 $fix_replies_index{$_}++;
1024 $fix_replies_index{$_} = 0
1025 if $fix_replies_index{$_} >= @frusers;
1026 print $fh "id:$fix_replies_index{$_} ",
1027 "account:$_ type:fix_replies_index\n";
1031 print $fh "__friends__\n";
1033 time - $last_friends_poll >
1034 Irssi::settings_get_int('twitter_friends_poll') )
1036 print $fh "__updated ", time, "\n";
1037 my ( $added, $removed ) = &load_friends($fh);
1038 if ( $added + $removed ) {
1039 print $fh "type:debug %R***%n Friends list updated: ",
1041 sprintf( "%d added", $added ),
1042 sprintf( "%d removed", $removed ) ),
1047 foreach ( sort keys %friends ) {
1048 print $fh "$_ $friends{$_}\n";
1052 print $fh "type:debug Update encountered errors. Aborted\n";
1053 print $fh "-- $last_poll";
1055 print $fh "-- $new_poll";
1058 rename $filename, "$filename.done";
1061 &ccrap("Failed to fork for updating: $!");
1063 print scalar localtime, " - get_updates ends" if &debug;
1067 my ( $fh, $username, $obj, $cache ) = @_;
1070 my $rate_limit = $obj->rate_limit_status();
1071 if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
1072 ¬ice("Rate limit exceeded for $username");
1077 print scalar localtime, " - Polling for updates for $username" if &debug;
1079 my $new_poll_id = 0;
1081 if ( $id_map{__last_id}{$username}{timeline} )
1083 $tweets = $obj->home_timeline( { count => 100 } );
1085 $tweets = $obj->home_timeline();
1090 print $fh "type:debug Error during home_timeline call: Aborted.\n";
1091 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1095 unless ( ref $tweets ) {
1096 if ( $obj->can("get_error") ) {
1097 my $error = "Unknown error";
1098 eval { $error = JSON::Any->jsonToObj( $obj->get_error() ) };
1099 unless ($@) { $error = $obj->get_error() }
1101 "type:debug API Error during home_timeline call: Aborted\n";
1102 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($error);
1106 "type:debug API Error during home_timeline call. Aborted.\n";
1111 foreach my $t ( reverse @$tweets ) {
1112 my $text = &get_text( $t, $obj );
1113 my $reply = "tweet";
1114 if ( Irssi::settings_get_bool("show_reply_context")
1115 and $t->{in_reply_to_screen_name} ne $username
1116 and $t->{in_reply_to_screen_name}
1117 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1119 $nicks{ $t->{in_reply_to_screen_name} } = time;
1121 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1123 $cache->{ $t->{in_reply_to_status_id} } =
1124 $obj->show_status( $t->{in_reply_to_status_id} );
1128 $context = $cache->{ $t->{in_reply_to_status_id} };
1131 my $ctext = &get_text( $context, $obj );
1132 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1133 $context->{id}, $username,
1134 $context->{user}{screen_name}, $ctext;
1139 if $t->{user}{screen_name} eq $username
1140 and not Irssi::settings_get_bool("show_own_tweets");
1141 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1142 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1143 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1145 printf $fh "id:%s account:%s type:last_id timeline\n",
1146 $new_poll_id, $username;
1148 print scalar localtime, " - Polling for replies since ",
1149 $id_map{__last_id}{$username}{reply}
1153 if ( $id_map{__last_id}{$username}{reply} )
1155 $tweets = $obj->replies(
1156 { since_id => $id_map{__last_id}{$username}{reply} } )
1159 $tweets = $obj->replies() || [];
1164 print $fh "type:debug Error during replies call. Aborted.\n";
1168 foreach my $t ( reverse @$tweets ) {
1170 if exists $friends{ $t->{user}{screen_name} };
1172 my $text = &get_text( $t, $obj );
1173 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1174 $t->{id}, $username, $t->{user}{screen_name}, $text;
1175 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1177 printf $fh "id:%s account:%s type:last_id reply\n", $new_poll_id, $username;
1179 print scalar localtime, " - Polling for DMs" if &debug;
1182 if ( $id_map{__last_id}{$username}{dm} )
1184 $tweets = $obj->direct_messages(
1185 { since_id => $id_map{__last_id}{$username}{dm} } )
1188 $tweets = $obj->direct_messages() || [];
1193 print $fh "type:debug Error during direct_messages call. Aborted.\n";
1197 foreach my $t ( reverse @$tweets ) {
1198 my $text = decode_entities( $t->{text} );
1199 $text =~ s/[\n\r]/ /g;
1200 printf $fh "id:%s account:%s nick:%s type:dm %s\n",
1201 $t->{id}, $username, $t->{sender_screen_name}, $text;
1202 $new_poll_id = $t->{id} if $new_poll_id < $t->{id};
1204 printf $fh "id:%s account:%s type:last_id dm\n", $new_poll_id, $username;
1206 print scalar localtime, " - Polling for subscriptions" if &debug;
1207 if ( $obj->can('search') and $id_map{__searches}{$username} ) {
1209 foreach my $topic ( sort keys %{ $id_map{__searches}{$username} } ) {
1210 print $fh "type:debug searching for $topic since ",
1211 "$id_map{__searches}{$username}{$topic}\n";
1213 $search = $obj->search(
1216 since_id => $id_map{__searches}{$username}{$topic}
1223 "type:debug Error during search($topic) call. Aborted.\n";
1227 unless ( $search->{max_id} ) {
1228 print $fh "type:debug Invalid search results when searching",
1229 " for $topic. Aborted.\n";
1233 $id_map{__searches}{$username}{$topic} = $search->{max_id};
1234 printf $fh "id:%s account:%s type:searchid topic:%s\n",
1235 $search->{max_id}, $username, $topic;
1237 foreach my $t ( reverse @{ $search->{results} } ) {
1238 my $text = &get_text( $t, $obj );
1239 printf $fh "id:%s account:%s nick:%s type:search topic:%s %s\n",
1240 $t->{id}, $username, $t->{from_user}, $topic, $text;
1241 $new_poll_id = $t->{id}
1243 or $t->{id} < $new_poll_id;
1248 print scalar localtime, " - Done" if &debug;
1254 my ( $fh, $target, $username, $obj, $cache ) = @_;
1256 my $last_id = $id_map{__last_id}{$username}{$target};
1258 print $fh "type:debug get_timeline("
1259 . "$fix_replies_index{$username}=$target > $last_id) started."
1260 . " username = $username\n";
1262 $tweets = $obj->user_timeline(
1265 ( $last_id ? ( since_id => $last_id ) : () ),
1272 "type:debug Error during user_timeline($target) call: Aborted.\n";
1273 print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
1279 "type:debug user_timeline($target) call returned undef! Aborted\n";
1283 foreach my $t ( reverse @$tweets ) {
1284 my $text = &get_text( $t, $obj );
1285 my $reply = "tweet";
1286 if ( Irssi::settings_get_bool("show_reply_context")
1287 and $t->{in_reply_to_screen_name} ne $username
1288 and $t->{in_reply_to_screen_name}
1289 and not exists $friends{ $t->{in_reply_to_screen_name} } )
1291 $nicks{ $t->{in_reply_to_screen_name} } = time;
1293 unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
1295 $cache->{ $t->{in_reply_to_status_id} } =
1296 $obj->show_status( $t->{in_reply_to_status_id} );
1300 $context = $cache->{ $t->{in_reply_to_status_id} };
1303 my $ctext = &get_text( $context, $obj );
1304 printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
1305 $context->{id}, $username,
1306 $context->{user}{screen_name}, $ctext;
1310 printf $fh "id:%s account:%s nick:%s type:%s %s\n",
1311 $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
1312 $last_id = $t->{id} if $last_id < $t->{id};
1314 printf $fh "id:%s account:%s type:last_id_fixreplies %s\n",
1315 $last_id, $username, $target;
1322 my $filename = $data->[0];
1323 my $attempt = $data->[1];
1325 print scalar localtime, " - checking child log at $filename ($attempt)"
1327 my ($new_last_poll);
1329 # reap any random leftover processes - work around a bug in irssi on gentoo
1330 waitpid( -1, WNOHANG );
1332 # first time we run we don't want to print out *everything*, so we just
1335 if ( open FILE, $filename ) {
1336 binmode FILE, ":utf8";
1340 last if /^__friends__/;
1341 unless (/\n$/) { # skip partial lines
1342 # print "Skipping partial line: $_" if &debug;
1349 foreach my $key (qw/id account nick type topic/) {
1350 if (s/^$key:(\S+)\s*//) {
1355 if ( $meta{type} and $meta{type} eq 'fix_replies_index' ) {
1356 $fix_replies_index{ $meta{account} } = $meta{id};
1357 print "fix_replies_index for $meta{account} set to $meta{id}"
1362 if ( not $meta{type} or $meta{type} !~ /searchid|last_id/ ) {
1363 if ( exists $meta{id} and exists $new_cache{ $meta{id} } ) {
1367 $new_cache{ $meta{id} } = time;
1369 if ( exists $meta{id} and exists $tweet_cache{ $meta{id} } ) {
1375 $meta{account} =~ s/\@(\w+)$//;
1376 $meta{service} = $1;
1378 lc $meta{service} eq
1379 lc Irssi::settings_get_str("twirssi_default_service") )
1381 $account = "$meta{account}: "
1382 if lc "$meta{account}\@$meta{service}" ne lc
1383 "$user\@$defservice";
1385 $account = "$meta{account}\@$meta{service}: ";
1389 if ( $meta{type} ne 'dm'
1390 and Irssi::settings_get_bool("twirssi_track_replies")
1394 $marker = ( $id_map{__indexes}{ $meta{nick} } + 1 ) % 100;
1395 $id_map{ lc $meta{nick} }[$marker] = $meta{id};
1396 $id_map{__indexes}{ $meta{nick} } = $marker;
1397 $id_map{__tweets}{ lc $meta{nick} }[$marker] = $_;
1398 $marker = ":$marker";
1402 $irssi_to_mirc_colors{ Irssi::settings_get_str("hilight_color") };
1403 my $nick = "\@$meta{account}";
1404 if ( $_ =~ /\Q$nick\E(?:\W|$)/i
1405 and Irssi::settings_get_bool("twirssi_hilights") )
1407 $meta{nick} = "\cC$hilight_color$meta{nick}\cO";
1408 $hilight = MSGLEVEL_HILIGHT;
1411 if ( $meta{type} =~ /tweet|reply/ ) {
1414 ( MSGLEVEL_PUBLIC | $hilight ),
1415 $meta{type}, $account, $meta{nick}, $marker, $_
1417 } elsif ( $meta{type} eq 'search' ) {
1420 ( MSGLEVEL_PUBLIC | $hilight ),
1421 $meta{type}, $account, $meta{topic},
1422 $meta{nick}, $marker, $_
1425 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1427 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1429 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1432 } elsif ( $meta{type} eq 'dm' ) {
1435 ( MSGLEVEL_MSGS | $hilight ),
1436 $meta{type}, $account, $meta{nick}, $_
1438 } elsif ( $meta{type} eq 'searchid' ) {
1439 print "Search '$meta{topic}' returned id $meta{id}" if &debug;
1442 exists $id_map{__searches}{ $meta{account} }{ $meta{topic} }
1444 $id_map{__searches}{ $meta{account} }{ $meta{topic} } )
1446 $id_map{__searches}{ $meta{account} }{ $meta{topic} } =
1449 print "Search '$meta{topic}' returned invalid id $meta{id}";
1451 } elsif ( $meta{type} eq 'last_id' ) {
1452 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1454 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1456 } elsif ( $meta{type} eq 'last_id_fixreplies' ) {
1457 $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} =
1459 if $id_map{__last_id}{"$meta{account}\@$meta{service}"}{$_} <
1461 } elsif ( $meta{type} eq 'error' ) {
1462 push @lines, [ MSGLEVEL_MSGS, $_ ];
1463 } elsif ( $meta{type} eq 'debug' ) {
1464 print "$_" if &debug,;
1466 print "Unknown line type $meta{type}: $_" if &debug,;
1472 if (/^__updated (\d+)$/) {
1473 $last_friends_poll = $1;
1474 print "Friend list updated" if &debug;
1479 $new_last_poll = $1;
1480 if ( $new_last_poll >= $last_poll ) {
1483 print "Impossible! ",
1484 "new_last_poll=$new_last_poll < last_poll=$last_poll!"
1486 undef $new_last_poll;
1490 my ( $f, $t ) = split ' ', $_;
1491 $nicks{$f} = $friends{$f} = $t;
1494 if ($new_last_poll) {
1495 print "new last_poll = $new_last_poll" if &debug;
1496 print "new last_poll_id = ", Dumper( $id_map{__last_id} ) if &debug;
1498 print "First call, not printing updates" if &debug;
1500 foreach my $line (@lines) {
1501 $window->printformat(
1503 "twirssi_" . $line->[1],
1504 @$line[ 2 .. $#$line - 1 ],
1505 &hilight( $line->[-1] )
1512 or warn "Failed to remove $filename: $!"
1515 # commit the pending cache lines to the actual cache, now that
1516 # we've printed our output
1517 %tweet_cache = ( %tweet_cache, %new_cache );
1519 # keep enough cached tweets, to make sure we don't show duplicates.
1520 foreach ( keys %tweet_cache ) {
1521 next if $tweet_cache{$_} >= $last_poll - 3600;
1522 delete $tweet_cache{$_};
1524 $last_poll = $new_last_poll;
1526 # make sure the pid is removed from the waitpid list
1527 Irssi::pidwait_remove($child_pid);
1529 # and that we don't leave any zombies behind, somehow
1535 Irssi::settings_get_str("twirssi_replies_store") )
1537 if ( open JSON, ">$file" ) {
1538 print JSON JSON::Any->objToJson( \%id_map );
1541 &ccrap("Failed to write replies to $file: $!");
1552 if ( $attempt < 24 ) {
1553 Irssi::timeout_add_once( 5000, 'monitor_child',
1554 [ $filename, $attempt + 1 ] );
1556 print "Giving up on polling $filename" if &debug;
1557 Irssi::pidwait_remove($child_pid);
1559 unlink $filename unless &debug;
1561 return unless Irssi::settings_get_bool("twirssi_notify_timeouts");
1564 my @time = localtime($last_poll);
1565 if ( time - $last_poll < 24 * 60 * 60 ) {
1566 $since = sprintf( "%d:%02d", @time[ 2, 1 ] );
1568 $since = scalar localtime($last_poll);
1571 if ( not $failwhale and time - $last_poll > 60 * 60 ) {
1576 q{ .--./ / | _.---.| },
1588 if ( time - $last_poll < 600 ) {
1589 &ccrap("Haven't been able to get updated tweets since $since");
1595 return Irssi::settings_get_bool("twirssi_debug");
1599 $window->print( "%R***%n @_", MSGLEVEL_PUBLIC );
1603 $window->print( "%R***%n @_", MSGLEVEL_CLIENTCRAP );
1609 if ( Irssi::settings_get_bool("tweet_to_away")
1611 and $data !~ /^[dD] / )
1614 Irssi::server_find_tag( Irssi::settings_get_str("bitlbee_server") );
1616 $server->send_raw("away :$data");
1619 &ccrap( "Can't find bitlbee server.",
1620 "Update bitlbee_server or disable tweet_to_away" );
1630 my $noalert = shift;
1632 if ( length $data > 140 ) {
1633 ¬ice( "Tweet too long (" . length($data) . " characters) - aborted" )
1641 sub valid_username {
1642 my $username = shift;
1644 $username = &normalize_username($username);
1646 unless ( exists $twits{$username} ) {
1647 ¬ice("Unknown username $username");
1657 ¬ice("Not logged in! Use /twitter_login username pass!");
1665 my ( $complist, $window, $word, $linestart, $want_space ) = @_;
1668 $linestart =~ /^\/(?:retweet|twitter_reply)(?:_as)?\s*$/
1669 or ( Irssi::settings_get_bool("twirssi_use_reply_aliases")
1670 and $linestart =~ /^\/reply(?:_as)?\s*$/ )
1672 { # /twitter_reply gets a nick:num
1674 @$complist = map { "$_:$id_map{__indexes}{$_}" }
1675 sort { $nicks{$b} <=> $nicks{$a} }
1677 keys %{ $id_map{__indexes} };
1681 /^\/(twitter_unfriend|twitter_add_follow_extra|twitter_del_follow_extra)\s*$/
1683 { # /twitter_unfriend gets a nick
1685 push @$complist, grep /^\Q$word/i,
1686 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1689 # /tweet, /tweet_as, /dm, /dm_as - complete @nicks (and nicks as the first
1691 if ( $linestart =~ /^\/(?:tweet|dm)/ ) {
1692 my $prefix = $word =~ s/^@//;
1693 $prefix = 0 if $linestart eq '/dm' or $linestart eq '/dm_as';
1694 push @$complist, grep /^\Q$word/i,
1695 sort { $nicks{$b} <=> $nicks{$a} } keys %nicks;
1696 @$complist = map { "\@$_" } @$complist if $prefix;
1700 sub event_send_text {
1701 my ( $line, $server, $win ) = @_;
1702 my $awin = Irssi::active_win();
1704 # if the window where we got our text was the twitter window, and the user
1705 # wants to be lazy, tweet away!
1706 if ( ( $awin->get_active_name() eq $window->{name} )
1707 and Irssi::settings_get_bool("tweet_window_input") )
1709 &cmd_tweet( $line, $server, $win );
1714 my $poll = Irssi::settings_get_int("twitter_poll_interval");
1715 return $poll if $poll >= 60;
1722 if ( Irssi::settings_get_str("twirssi_nick_color") ) {
1723 my $c = Irssi::settings_get_str("twirssi_nick_color");
1724 $c = $irssi_to_mirc_colors{$c};
1725 $text =~ s/(^|\W)\@(\w+)/$1\cC$c\@$2\cO/g if $c;
1727 if ( Irssi::settings_get_str("twirssi_topic_color") ) {
1728 my $c = Irssi::settings_get_str("twirssi_topic_color");
1729 $c = $irssi_to_mirc_colors{$c};
1730 $text =~ s/(^|\W)(\#|\!)([-\w]+)/$1\cC$c$2$3\cO/g if $c;
1732 $text =~ s/[\n\r]/ /g;
1740 my $provider = Irssi::settings_get_str("short_url_provider");
1743 Irssi::settings_get_bool("twirssi_always_shorten")
1744 or &too_long( $data, 1 )
1750 if ( $provider eq 'Bitly' ) {
1751 @args[ 1, 2 ] = split ',',
1752 Irssi::settings_get_str("short_url_args"), 2;
1753 unless ( @args == 3 ) {
1755 "WWW::Shorten::Bitly requires a username and API key.",
1756 "Set short_url_args to username,API_key or change your",
1757 "short_url_provider."
1759 return decode "utf8", $data;
1763 foreach my $url ( $data =~ /(https?:\/\/\S+[\w\/])/g ) {
1766 my $short = makeashorterlink(@args);
1768 $data =~ s/\Q$url/$short/g;
1770 ¬ice("Failed to shorten $url!");
1776 return decode "utf8", $data;
1779 sub normalize_username {
1782 my ( $username, $service ) = split /\@/, $user, 2;
1784 $service = ucfirst lc $service;
1787 ucfirst lc Irssi::settings_get_str("twirssi_default_service");
1788 unless ( exists $twits{"$username\@$service"} ) {
1790 foreach my $t ( sort keys %twits ) {
1791 next unless $t =~ /^\Q$username\E\@(Twitter|Identica)/;
1797 ¬ice("Can't find a logged in user '$user'");
1802 return "$username\@$service";
1808 my $text = decode_entities( $tweet->{text} );
1809 if ( $tweet->{truncated} ) {
1810 if ( exists $tweet->{retweeted_status} ) {
1811 $text = "RT \@$tweet->{retweeted_status}{user}{screen_name}: "
1812 . "$tweet->{retweeted_status}{text}";
1813 } elsif ( $object->isa('Net::Twitter') ) {
1814 $text .= " -- http://twitter.com/$tweet->{user}{screen_name}"
1815 . "/status/$tweet->{id}";
1819 $text =~ s/[\n\r]/ /g;
1824 Irssi::signal_add( "send text", "event_send_text" );
1826 Irssi::theme_register(
1828 'twirssi_tweet', '[$0%B@$1%n$2] $3',
1829 'twirssi_search', '[$0%r$1%n:%B@$2%n$3] $4',
1830 'twirssi_reply', '[$0\--> %B@$1%n$2] $3',
1831 'twirssi_dm', '[$0%r@$1%n (%WDM%n)] $2',
1832 'twirssi_error', 'ERROR: $0',
1836 Irssi::settings_add_int( "twirssi", "twitter_poll_interval", 300 );
1837 Irssi::settings_add_str( "twirssi", "twitter_window", "twitter" );
1838 Irssi::settings_add_str( "twirssi", "bitlbee_server", "bitlbee" );
1839 Irssi::settings_add_str( "twirssi", "short_url_provider", "TinyURL" );
1840 Irssi::settings_add_str( "twirssi", "short_url_args", undef );
1841 Irssi::settings_add_str( "twirssi", "twitter_usernames", undef );
1842 Irssi::settings_add_str( "twirssi", "twitter_passwords", undef );
1843 Irssi::settings_add_str( "twirssi", "twirssi_default_service", "Twitter" );
1844 Irssi::settings_add_str( "twirssi", "twirssi_nick_color", "%B" );
1845 Irssi::settings_add_str( "twirssi", "twirssi_topic_color", "%r" );
1846 Irssi::settings_add_str( "twirssi", "twirssi_retweet_format",
1847 'RT $n: "$t" ${-- $c$}' );
1848 Irssi::settings_add_str( "twirssi", "twirssi_location",
1849 Irssi::get_irssi_dir . "/.irssi/scripts/twirssi.pl" );
1850 Irssi::settings_add_str( "twirssi", "twirssi_replies_store",
1851 Irssi::get_irssi_dir . "/.irssi/scripts/twirssi.json" );
1852 Irssi::settings_add_str( "twirssi", "twirssi_oauth_store",
1853 Irssi::get_irssi_dir . "/.irssi/scripts/twirssi.oauth" );
1855 Irssi::settings_add_int( "twirssi", "twitter_friends_poll", 600 );
1856 Irssi::settings_add_int( "twirssi", "twitter_timeout", 30 );
1858 Irssi::settings_add_bool( "twirssi", "twirssi_upgrade_beta", 0 );
1859 Irssi::settings_add_bool( "twirssi", "tweet_to_away", 0 );
1860 Irssi::settings_add_bool( "twirssi", "show_reply_context", 0 );
1861 Irssi::settings_add_bool( "twirssi", "show_own_tweets", 1 );
1862 Irssi::settings_add_bool( "twirssi", "twirssi_debug", 0 );
1863 Irssi::settings_add_bool( "twirssi", "twirssi_first_run", 1 );
1864 Irssi::settings_add_bool( "twirssi", "twirssi_track_replies", 1 );
1865 Irssi::settings_add_bool( "twirssi", "twirssi_replies_autonick", 1 );
1866 Irssi::settings_add_bool( "twirssi", "twirssi_use_reply_aliases", 0 );
1867 Irssi::settings_add_bool( "twirssi", "twirssi_notify_timeouts", 1 );
1868 Irssi::settings_add_bool( "twirssi", "twirssi_hilights", 1 );
1869 Irssi::settings_add_bool( "twirssi", "twirssi_always_shorten", 0 );
1870 Irssi::settings_add_bool( "twirssi", "tweet_window_input", 0 );
1871 Irssi::settings_add_bool( "twirssi", "twirssi_avoid_ssl", 0 );
1872 Irssi::settings_add_bool( "twirssi", "twirssi_use_oauth", 1 );
1874 $last_poll = time - &get_poll_time;
1875 $window = Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
1878 ->print( "Couldn't find a window named '"
1879 . Irssi::settings_get_str('twitter_window')
1880 . "', trying to create it." );
1882 Irssi::Windowitem::window_create(
1883 Irssi::settings_get_str('twitter_window'), 1 );
1884 $window->set_name( Irssi::settings_get_str('twitter_window') );
1888 Irssi::command_bind( "dm", "cmd_direct" );
1889 Irssi::command_bind( "dm_as", "cmd_direct_as" );
1890 Irssi::command_bind( "tweet", "cmd_tweet" );
1891 Irssi::command_bind( "tweet_as", "cmd_tweet_as" );
1892 Irssi::command_bind( "retweet", "cmd_retweet" );
1893 Irssi::command_bind( "retweet_as", "cmd_retweet_as" );
1894 Irssi::command_bind( "twitter_reply", "cmd_reply" );
1895 Irssi::command_bind( "twitter_reply_as", "cmd_reply_as" );
1896 Irssi::command_bind( "twitter_login", "cmd_login" );
1897 Irssi::command_bind( "twitter_logout", "cmd_logout" );
1898 Irssi::command_bind( "twitter_switch", "cmd_switch" );
1899 Irssi::command_bind( "twitter_subscribe", "cmd_add_search" );
1900 Irssi::command_bind( "twitter_unsubscribe", "cmd_del_search" );
1901 Irssi::command_bind( "twitter_list_subscriptions", "cmd_list_search" );
1902 Irssi::command_bind( "twirssi_upgrade", "cmd_upgrade" );
1903 Irssi::command_bind( "twirssi_oauth", "cmd_oauth" );
1904 Irssi::command_bind( "twitter_updates", "get_updates" );
1905 Irssi::command_bind( "twitter_add_follow_extra", "cmd_add_follow" );
1906 Irssi::command_bind( "twitter_del_follow_extra", "cmd_del_follow" );
1907 Irssi::command_bind( "twitter_list_follow_extra", "cmd_list_follow" );
1908 Irssi::command_bind( "bitlbee_away", "update_away" );
1909 if ( Irssi::settings_get_bool("twirssi_use_reply_aliases") ) {
1910 Irssi::command_bind( "reply", "cmd_reply" );
1911 Irssi::command_bind( "reply_as", "cmd_reply_as" );
1913 Irssi::command_bind(
1916 print "twits: ", join ", ",
1917 map { "u: $_->{username}\@" . ref($_) } values %twits;
1918 print "selected: $user\@$defservice";
1919 print "friends: ", join ", ", sort keys %friends;
1920 print "nicks: ", join ", ", sort keys %nicks;
1921 print "searches: ", Dumper \%{ $id_map{__searches} };
1922 print "last poll: $last_poll";
1923 if ( open DUMP, ">/tmp/twirssi.cache.txt" ) {
1924 print DUMP Dumper \%tweet_cache;
1926 print "cache written out to /tmp/twirssi.cache.txt";
1930 Irssi::command_bind(
1934 "Twirssi v$VERSION; "
1936 $Net::Twitter::VERSION
1937 ? "Net::Twitter v$Net::Twitter::VERSION. "
1941 $Net::Identica::VERSION
1942 ? "Net::Identica v$Net::Identica::VERSION. "
1946 . JSON::Any::handler()
1947 . ". See details at http://twirssi.com/"
1951 Irssi::command_bind(
1954 "/twitter_follow <username>",
1956 sub { ¬ice("Following $_[0]"); $nicks{ $_[0] } = time; }
1959 Irssi::command_bind(
1962 "/twitter_unfriend <username>",
1964 sub { ¬ice("Stopped following $_[0]"); delete $nicks{ $_[0] }; }
1967 Irssi::command_bind(
1968 "twitter_device_updates",
1970 "/twitter_device_updates none|im|sms",
1971 "update_delivery_device",
1972 sub { ¬ice("Device updated to $_[0]"); }
1975 Irssi::command_bind(
1978 "/twitter_block <username>",
1980 sub { ¬ice("Blocked $_[0]"); }
1983 Irssi::command_bind(
1986 "/twitter_unblock <username>",
1988 sub { ¬ice("Unblock $_[0]"); }
1991 Irssi::signal_add_last( 'complete word' => \&sig_complete );
1993 ¬ice(" %Y<%C(%B^%C)%N TWIRSSI v%R$VERSION%N");
1994 ¬ice(" %C(_(\\%N http://twirssi.com/ for full docs");
1996 " %Y||%C `%N Log in with /twitter_login, send updates with /tweet");
1998 my $file = Irssi::settings_get_str("twirssi_replies_store");
1999 if ( $file and -r $file ) {
2000 if ( open( JSON, $file ) ) {
2005 my $ref = JSON::Any->jsonToObj($json);
2007 my $num = keys %{ $id_map{__indexes} };
2008 ¬ice( sprintf "Loaded old replies from %d contact%s.",
2009 $num, ( $num == 1 ? "" : "s" ) );
2014 ¬ice("Failed to load old replies from $file: $!");
2018 if ( my $provider = Irssi::settings_get_str("short_url_provider") ) {
2019 ¬ice("Loading WWW::Shorten::$provider...");
2020 eval "use WWW::Shorten::$provider;";
2024 "Failed to load WWW::Shorten::$provider - either clear",
2025 "short_url_provider or install the CPAN module"
2030 if ( my $autouser = Irssi::settings_get_str("twitter_usernames") ) {
2037 ->print( "Create a window named "
2038 . Irssi::settings_get_str('twitter_window')
2039 . " or change the value of twitter_window. Then, reload twirssi." );
2042 # vim: set sts=4 expandtab: