X-Git-Url: https://git.sommitrealweird.co.uk/twirssi-net-twitter-lite.git/blobdiff_plain/c8726ad2993d45e82b37ae846310181d4200e5ed..b8bd67a04b4277e70e18510ab4e055925e1775b3:/twirssi.pl diff --git a/twirssi.pl b/twirssi.pl index 0c433cd..4f4ef64 100644 --- a/twirssi.pl +++ b/twirssi.pl @@ -431,9 +431,7 @@ sub cmd_logout { return unless $data = &valid_username($data); ¬ice("Logging out $data..."); - eval { - $twits{$data}->end_session(); - }; + eval { $twits{$data}->end_session(); }; delete $twits{$data}; undef $twit; if ( keys %twits ) { @@ -451,14 +449,15 @@ sub cmd_login { if ($data) { print "manual data login" if &debug; ( $user, $pass ) = split ' ', $data, 2; - unless (Irssi::settings_get_bool("twirssi_use_oauth") or $pass) { + unless ( Irssi::settings_get_bool("twirssi_use_oauth") or $pass ) { ¬ice("usage: /twitter_login [\@] "); return; } - } elsif ( Irssi::settings_get_bool("twirssi_use_oauth") and - my $autouser = Irssi::settings_get_str("twitter_usernames") ) { + } elsif ( Irssi::settings_get_bool("twirssi_use_oauth") + and my $autouser = Irssi::settings_get_str("twitter_usernames") ) + { print "oauth autouser login" if &debug; - foreach my $user (split /,/, $autouser) { + foreach my $user ( split /,/, $autouser ) { &cmd_login($user); } return; @@ -496,7 +495,7 @@ sub cmd_login { ¬ice("/twitter_login requires either a username/password " . "or twitter_usernames and twitter_passwords to be set. " . "Note that if twirssi_use_oauth is true, passwords are " - . "not required"); + . "not required" ); return; } @@ -510,26 +509,39 @@ sub cmd_login { } $defservice = $service = ucfirst lc $service; - if ( $service eq 'Twitter' and - Irssi::settings_get_bool("twirssi_use_oauth") ) { + if ( $service eq 'Twitter' + and Irssi::settings_get_bool("twirssi_use_oauth") ) + { print "Attempting OAuth for $user\@$service" if &debug; eval { - $twit = Net::Twitter->new( - $service eq 'Identica' ? ( identica => 1 ) : (), - traits => [ 'API::REST', 'OAuth' ], - consumer_key => 'BZVAvBma4GxdiRwXIvbnw', - consumer_secret => '0T5kahwLyb34vciGZsgkA9lsjtGCQ05vxVE2APXM', - source => "twirssi", - ssl => Irssi::settings_get_bool("twirssi_avoid_ssl") ? 0 : 1, - ); + if ( $service eq 'Identica' ) + { + $twit = Net::Twitter->new( + identica => 1, + traits => [ 'API::REST', 'API::Search' ], + source => "twirssi", + ssl => !Irssi::settings_get_bool("twirssi_avoid_ssl"), + ); + } else { + $twit = Net::Twitter->new( + traits => [ 'API::REST', 'OAuth', 'API::Search' ], + consumer_key => 'BZVAvBma4GxdiRwXIvbnw', + consumer_secret => + '0T5kahwLyb34vciGZsgkA9lsjtGCQ05vxVE2APXM', + source => "twirssi", + ssl => !Irssi::settings_get_bool("twirssi_avoid_ssl"), + ); + } }; - if ( $twit ) { - if (open( OAUTH, Irssi::settings_get_str("twirssi_oauth_store") ) ) { + if ($twit) { + if ( open( OAUTH, Irssi::settings_get_str("twirssi_oauth_store") ) ) + { while () { chomp; next unless m/$user\@$service (\S+) (\S+)/i; - print "Trying cached oauth creds for $user\@$service" if &debug; + print "Trying cached oauth creds for $user\@$service" + if &debug; $twit->access_token($1); $twit->access_token_secret($2); last; @@ -539,17 +551,19 @@ sub cmd_login { unless ( $twit->authorized ) { my $url; - eval { - $url = $twit->get_authorization_url; - }; + eval { $url = $twit->get_authorization_url; }; if ($@) { - ¬ice("ERROR: Failed to get OAuth authorization_url. Try again later."); + ¬ice( +"ERROR: Failed to get OAuth authorization_url. Try again later." + ); return; } ¬ice("Twirssi not autorized to access $service for $user."); - ¬ice("Please authorize at the following url, then enter the pin "); + ¬ice( + "Please authorize at the following url, then enter the pin " + ); ¬ice("supplied with /twirssi_oauth $user\@$service "); ¬ice($url); @@ -557,7 +571,7 @@ sub cmd_login { return; } } - } else { + } else { $twit = Net::Twitter->new( $service eq 'Identica' ? ( identica => 1 ) : (), username => $user, @@ -572,13 +586,13 @@ sub cmd_login { return; } - return &verify_twitter_object($server, $win, $user, $service, $twit); + return &verify_twitter_object( $server, $win, $user, $service, $twit ); } sub cmd_oauth { - my ($data, $server, $win) = @_; + my ( $data, $server, $win ) = @_; my ( $key, $pin ) = split ' ', $data; - my ($user, $service); + my ( $user, $service ); $key = &normalize_username($key); if ( $key =~ /^(.*)@(Twitter|Identica)$/ ) { ( $user, $service ) = ( $1, $2 ); @@ -634,11 +648,11 @@ sub cmd_oauth { . "Please /set twirssi_oauth_store to a writable filename." ); } - return &verify_twitter_object($server, $win, $user, $service, $twit); + return &verify_twitter_object( $server, $win, $user, $service, $twit ); } sub verify_twitter_object { - my ($server, $win, $user, $service, $twit) = @_; + my ( $server, $win, $user, $service, $twit ) = @_; if ( my $timeout = Irssi::settings_get_int("twitter_timeout") and $twit->can('ua') ) @@ -668,7 +682,7 @@ sub verify_twitter_object { my $rate_limit = $twit->rate_limit_status(); if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) { ¬ice( - "Rate limit exceeded, try again after $rate_limit->{reset_time}" ); + "Rate limit exceeded, try again after $rate_limit->{reset_time}"); $twit = undef; return; } @@ -941,7 +955,8 @@ sub load_friends { }; if ($@) { - print $fh "type:debug Error during friends list update. Aborted.\n"; + print $fh "type:debug Error during friends list update. Aborted.\n" + if $fh; return; } @@ -1831,11 +1846,11 @@ Irssi::settings_add_str( "twirssi", "twirssi_topic_color", "%r" ); Irssi::settings_add_str( "twirssi", "twirssi_retweet_format", 'RT $n: "$t" ${-- $c$}' ); Irssi::settings_add_str( "twirssi", "twirssi_location", - "$ENV{HOME}/.irssi/scripts/twirssi.pl" ); + Irssi::get_irssi_dir . "/scripts/twirssi.pl" ); Irssi::settings_add_str( "twirssi", "twirssi_replies_store", - "$ENV{HOME}/.irssi/scripts/twirssi.json" ); + Irssi::get_irssi_dir . "/scripts/twirssi.json" ); Irssi::settings_add_str( "twirssi", "twirssi_oauth_store", - "$ENV{HOME}/.irssi/scripts/twirssi.oauth" ); + Irssi::get_irssi_dir . "/scripts/twirssi.oauth" ); Irssi::settings_add_int( "twirssi", "twitter_friends_poll", 600 ); Irssi::settings_add_int( "twirssi", "twitter_timeout", 30 );