v2.4.0
[twirssi-net-twitter-lite.git] / twirssi.pl
index c5384cfccaaccd50c4edbd47f9bffaed170fdff1..9cbf2ff8df48a14a949fa2d1e4cb0ec4bdcfa36a 100644 (file)
@@ -12,7 +12,7 @@ $Data::Dumper::Indent = 1;
 
 use vars qw($VERSION %IRSSI);
 
-$VERSION = "2.4.0beta";
+$VERSION = "2.4.0";
 %IRSSI   = (
     authors     => 'Dan Boger',
     contact     => 'zigdon@gmail.com',
@@ -21,7 +21,7 @@ $VERSION = "2.4.0beta";
       . 'Can optionally set your bitlbee /away message to same',
     license => 'GNU GPL v2',
     url     => 'http://twirssi.com',
-    changed => '$Date: 2009-08-07 01:24:53 -0700 (Fri, 07 Aug 2009) $',
+    changed => 'Fri Jan 22 14:40:48 PST 2010',
 );
 
 my $window;
@@ -430,7 +430,9 @@ sub cmd_logout {
     return unless $data = &valid_username($data);
 
     &notice("Logging out $data...");
-    $twits{$data}->end_session();
+    eval {
+        $twits{$data}->end_session();
+    };
     delete $twits{$data};
     undef $twit;
     if ( keys %twits ) {
@@ -541,10 +543,20 @@ sub cmd_login {
             }
 
             unless ( $twit->authorized ) {
+                my $url;
+                eval {
+                    $url = $twit->get_authorization_url;
+                };
+
+                if ($@) {
+                    &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("supplied with /twirssi_oath $user\@$service <pin>");
-                &notice($twit->get_authorization_url);
+                &notice("supplied with /twirssi_oauth $user\@$service <pin>");
+                &notice($url);
 
                 $oauth{pending}{"$user\@$service"} = $twit;
                 return;
@@ -600,21 +612,21 @@ sub cmd_oauth {
 
     my $store_file = Irssi::settings_get_str("twirssi_oauth_store");
     if ($store_file) {
-        my %store;
+        my @store;
         if ( open( OAUTH, $store_file ) ) {
             while (<OAUTH>) {
                 chomp;
-                my ( $k, $v ) = split ' ', 2;
-                $store{$k} = $v;
+                next if /$key/i;
+                push @store, $_;
             }
             close OAUTH;
 
         }
 
-        $store{$key} = "$access_token $access_token_secret";
+        push @store, "$key $access_token $access_token_secret";
 
         if ( open( OAUTH, ">$store_file.new" ) ) {
-            print OAUTH "$_ $store{$_}\n" foreach keys %store;
+            print OAUTH "$_\n" foreach @store;
             close OAUTH;
             rename "$store_file.new", $store_file
               or &notice("Failed to rename $store_file.new: $!");
@@ -1043,11 +1055,13 @@ sub get_updates {
 sub do_updates {
     my ( $fh, $username, $obj, $cache ) = @_;
 
-    my $rate_limit = $obj->rate_limit_status();
-    if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
-        &notice("Rate limit exceeded for $username");
-        return undef;
-    }
+    eval {
+        my $rate_limit = $obj->rate_limit_status();
+        if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
+            &notice("Rate limit exceeded for $username");
+            return undef;
+        }
+    };
 
     print scalar localtime, " - Polling for updates for $username" if &debug;
     my $tweets;
@@ -2002,9 +2016,7 @@ if ($window) {
         }
     }
 
-    if (    my $autouser = Irssi::settings_get_str("twitter_usernames")
-        and my $autopass = Irssi::settings_get_str("twitter_passwords") )
-    {
+    if ( my $autouser = Irssi::settings_get_str("twitter_usernames") ) {
         &cmd_login();
         &get_updates;
     }