Improve OAuth error message (patch from kiyose)
[twirssi-net-twitter-lite.git] / twirssi.pl
index b0e31068fd04a20f3b94ed057cf33068c71f81b1..7147981a504f0644a8f0b69480792ac092dcb881 100644 (file)
@@ -518,13 +518,13 @@ sub cmd_login {
             {
                 $twit = Net::Twitter->new(
                     identica => 1,
-                    traits   => [ 'API::REST' ],
+                    traits   => [ 'API::REST', 'API::Search' ],
                     source   => "twirssi",
                     ssl      => !Irssi::settings_get_bool("twirssi_avoid_ssl"),
                 );
             } else {
                 $twit = Net::Twitter->new(
-                    traits       => [ 'API::REST', 'OAuth' ],
+                    traits => [ 'API::REST', 'OAuth', 'API::Search' ],
                     consumer_key => 'BZVAvBma4GxdiRwXIvbnw',
                     consumer_secret =>
                       '0T5kahwLyb34vciGZsgkA9lsjtGCQ05vxVE2APXM',
@@ -554,18 +554,15 @@ sub cmd_login {
                 eval { $url = $twit->get_authorization_url; };
 
                 if ($@) {
-                    &notice(
-"ERROR: Failed to get OAuth authorization_url.  Try again later."
-                    );
+                    &notice( "ERROR: Failed to get OAuth authorization_url. " .
+                             "Try again later.");
                     return;
                 }
-
-                &notice("Twirssi not autorized to access $service for $user.");
-                &notice(
-                    "Please authorize at the following url, then enter the pin "
+                &notice( "Twirssi not autorized to access $service for $user.",
+                         "Please authorize at the following url, then enter the pin",
+                         "supplied with /twirssi_oauth $user\@$service <pin>",
+                         $url
                 );
-                &notice("supplied with /twirssi_oauth $user\@$service <pin>");
-                &notice($url);
 
                 $oauth{pending}{"$user\@$service"} = $twit;
                 return;
@@ -693,7 +690,7 @@ sub verify_twitter_object {
     $poll = Irssi::timeout_add( &get_poll_time * 1000, \&get_updates, "" );
     &notice("Logged in as $user\@$service, loading friends list...");
     &load_friends();
-    &notice( "loaded friends: ", scalar keys %friends );
+    &notice( "loaded friends: ". scalar keys %friends );
     if ( Irssi::settings_get_bool("twirssi_first_run") ) {
         Irssi::settings_set_bool( "twirssi_first_run", 0 );
     }
@@ -955,7 +952,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;
     }
 
@@ -1568,7 +1566,7 @@ sub monitor_child {
         }
 
         if ( not $failwhale and time - $last_poll > 60 * 60 ) {
-            foreach my $whale (
+            &ccrap(
                 q{     v  v        v},
                 q{     |  |  v     |  v},
                 q{     | .-, |     |  |},
@@ -1577,10 +1575,7 @@ sub monitor_child {
                 q{      \\          a    |},
                 q{       ',.__.   ,__.-'/},
                 q{         '--/_.'----'`}
-              )
-            {
-                &ccrap($whale);
-            }
+              );
             $failwhale = 1;
         }
 
@@ -1595,11 +1590,15 @@ sub debug {
 }
 
 sub notice {
-    $window->print( "%R***%n @_", MSGLEVEL_PUBLIC );
+    foreach my $msg (@_) {
+        $window->print( "%R***%n $msg", MSGLEVEL_PUBLIC );
+    }
 }
 
 sub ccrap {
-    $window->print( "%R***%n @_", MSGLEVEL_CLIENTCRAP );
+    foreach my $msg (@_) {
+        $window->print( "%R***%n $msg", MSGLEVEL_CLIENTCRAP );
+    }
 }
 
 sub update_away {
@@ -1845,11 +1844,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 );
@@ -1989,10 +1988,9 @@ if ($window) {
     );
     Irssi::signal_add_last( 'complete word' => \&sig_complete );
 
-    &notice("  %Y<%C(%B^%C)%N                   TWIRSSI v%R$VERSION%N");
-    &notice("   %C(_(\\%N           http://twirssi.com/ for full docs");
-    &notice(
-        "    %Y||%C `%N Log in with /twitter_login, send updates with /tweet");
+    &notice("  %Y<%C(%B^%C)%N                   TWIRSSI v%R$VERSION%N",
+            "   %C(_(\\%N           http://twirssi.com/ for full docs",
+            "    %Y||%C `%N Log in with /twitter_login, send updates with /tweet");
 
     my $file = Irssi::settings_get_str("twirssi_replies_store");
     if ( $file and -r $file ) {