(no commit message)
[twirssi-net-twitter-lite.git] / twirssi.pl
index fc59bc828c3fd7d9d19646580e7bae5ad063ef39..093a1b84bcab255efdb862e07dbd1a075503431e 100644 (file)
@@ -6,13 +6,13 @@ use HTML::Entities;
 use File::Temp;
 use LWP::Simple;
 use Data::Dumper;
-use Net::Twitter;
+use Net::Identica;
 $Data::Dumper::Indent = 1;
 
 use vars qw($VERSION %IRSSI);
 
-$VERSION = "2.0.5";
-my ($REV) = '$Rev: 480 $' =~ /(\d+)/;
+$VERSION = "2.0.6";
+my ($REV) = '$Rev: 483 $' =~ /(\d+)/;
 %IRSSI = (
     authors     => 'Dan Boger',
     contact     => 'zigdon@gmail.com',
@@ -21,7 +21,7 @@ my ($REV) = '$Rev: 480 $' =~ /(\d+)/;
       . 'Can optionally set your bitlbee /away message to same',
     license => 'GNU GPL v2',
     url     => 'http://twirssi.com',
-    changed => '$Date: 2009-02-18 13:41:52 -0800 (Wed, 18 Feb 2009) $',
+    changed => '$Date: 2009-02-20 14:37:28 -0800 (Fri, 20 Feb 2009) $',
 );
 
 my $window;
@@ -81,20 +81,25 @@ sub cmd_direct_as {
     return unless &valid_username($username);
 
     eval {
-        unless ( $twits{$username}
+        if ( $twits{$username}
             ->new_direct_message( { user => $target, text => $text } ) )
         {
+            &notice("DM sent to $target");
+            $nicks{$target} = time;
+        } else {
+            my $error;
+            eval {
+                $error = JSON::Any->jsonToObj( $twits{$username}->get_error() );
+                $error = $error->{error};
+            };
+            die $error if $error;
             &notice("DM to $target failed");
-            return;
         }
     };
 
     if ($@) {
-        &notice("DM caused an error: $@.  Aborted");
+        &notice("DM caused an error: $@");
         return;
-    } else {
-        &notice("DM sent to $target");
-        $nicks{$target} = time;
     }
 }
 
@@ -141,16 +146,18 @@ sub cmd_tweet_as {
 
     return if &too_long($data);
 
+    my $success = 1;
     eval {
         unless ( $twits{$username}->update($data) )
         {
             &notice("Update failed");
-            return;
+            $success = 0;
         }
     };
+    return unless $success;
 
     if ($@) {
-        &notice("Update caused an error.  Aborted.");
+        &notice("Update caused an error: $@.  Aborted.");
         return;
     }
 
@@ -227,17 +234,20 @@ sub cmd_reply_as {
         $data = "\@$nick " . $data;
     }
 
-    if ( Irssi::settings_get_str("short_url_provider") ) {
-        foreach my $url ( $data =~ /(https?:\/\/\S+[\w\/])/g ) {
-            eval {
-                my $short = makeashorterlink($url);
-                $data =~ s/\Q$url/$short/g;
-            };
+    if ( &too_long( $data, 1 ) ) {
+        if ( Irssi::settings_get_str("short_url_provider") ) {
+            foreach my $url ( $data =~ /(https?:\/\/\S+[\w\/])/g ) {
+                eval {
+                    my $short = makeashorterlink($url);
+                    $data =~ s/\Q$url/$short/g;
+                };
+            }
         }
     }
 
     return if &too_long($data);
 
+    my $success = 1;
     eval {
         unless (
             $twits{$username}->update(
@@ -249,12 +259,13 @@ sub cmd_reply_as {
           )
         {
             &notice("Update failed");
-            return;
+            $success = 0;
         }
     };
+    return unless $success;
 
     if ($@) {
-        &notice("Update caused an error.  Aborted");
+        &notice("Update caused an error: $@.  Aborted");
         return;
     }
 
@@ -281,13 +292,15 @@ sub gen_cmd {
             return;
         }
 
+        my $success = 1;
         eval {
             unless ( $twit->$api_name($data) )
             {
                 &notice("$api_name failed");
-                return;
+                $success = 0;
             }
         };
+        return unless $success;
 
         if ($@) {
             &notice("$api_name caused an error.  Aborted.");
@@ -360,7 +373,7 @@ sub cmd_login {
 
     %friends = %nicks = ();
 
-    $twit = Net::Twitter->new(
+    $twit = Net::Identica->new(
         username => $user,
         password => $pass,
         source   => "twirssi"
@@ -412,7 +425,7 @@ sub cmd_add_search {
     my ( $data, $server, $win ) = @_;
 
     unless ( $twit and $twit->can('search') ) {
-        &notice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
+        &notice("ERROR: Your version of Net::Identica ($Net::Identica::VERSION) "
               . "doesn't support searches." );
         return;
     }
@@ -438,7 +451,7 @@ sub cmd_del_search {
     my ( $data, $server, $win ) = @_;
 
     unless ( $twit and $twit->can('search') ) {
-        &notice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
+        &notice("ERROR: Your version of Net::Identica ($Net::Identica::VERSION) "
               . "doesn't support searches." );
         return;
     }
@@ -490,13 +503,6 @@ sub cmd_upgrade {
         return;
     }
 
-    if ( not -x "/usr/bin/md5sum" and not $data ) {
-        &notice(
-"/usr/bin/md5sum can't be found - try '/twirssi_upgrade nomd5' to skip MD5 verification"
-        );
-        return;
-    }
-
     my $md5;
     unless ($data) {
         eval { use Digest::MD5; };
@@ -689,7 +695,8 @@ sub do_updates {
     };
 
     if ($@) {
-        print $fh "type:debug Error during friends_timeline call.  Aborted.\n";
+        print $fh
+          "type:debug Error during friends_timeline call: $@.  Aborted.\n";
         return 1;
     }
 
@@ -1200,7 +1207,7 @@ if ($window) {
         "twirssi_version",
         sub {
             &notice("Twirssi v$VERSION (r$REV); "
-                  . "Net::Twitter v$Net::Twitter::VERSION. "
+                  . "Net::Identica v$Net::Identica::VERSION. "
                   . "JSON in use: "
                   . JSON::Any::handler()
                   . ".  See details at http://twirssi.com/" );