1.7.5 - r374 - Minor fix, avoid another unevaled call to JSON::Any
[twirssi-net-twitter-lite.git] / twirssi.pl
index 46d2e2cce105e36f00063d1d3bdd9f7af73209e9..ad7bf88b8901a4ef4f694ede5560cd40ec6d52f1 100644 (file)
@@ -6,20 +6,13 @@ use HTML::Entities;
 use File::Temp;
 use LWP::Simple;
 use Data::Dumper;
+use Net::Twitter;
 $Data::Dumper::Indent = 1;
 
-BEGIN {
-    $ENV{JSON_ANY_ORDER} = "JSON Syck DWIW";
-    require JSON::Any;
-    import JSON::Any;
-    require Net::Twitter;
-    import Net::Twitter;
-}
-
 use vars qw($VERSION %IRSSI);
 
-$VERSION = "1.7.3";
-my ($REV) = '$Rev: 353 $' =~ /(\d+)/;
+$VERSION = "1.7.5";
+my ($REV) = '$Rev: 374 $' =~ /(\d+)/;
 %IRSSI = (
     authors     => 'Dan Boger',
     contact     => 'zigdon@gmail.com',
@@ -28,7 +21,7 @@ my ($REV) = '$Rev: 353 $' =~ /(\d+)/;
       . 'Can optionally set your bitlbee /away message to same',
     license => 'GNU GPL v2',
     url     => 'http://tinyurl.com/twirssi',
-    changed => '$Date: 2009-01-08 14:17:30 -0800 (Thu, 08 Jan 2009) $',
+    changed => '$Date: 2009-01-19 23:31:12 -0800 (Mon, 19 Jan 2009) $',
 );
 
 my $window;
@@ -604,8 +597,11 @@ sub do_updates {
 
     unless ( ref $tweets ) {
         if ( $obj->can("get_error") ) {
+            my $error;
+            eval { $error = JSON::Any->jsonToObj( $obj->get_error() ) };
+            if ($@) { $error = $obj->get_error() }
             print $fh "type:debug API Error during friends_timeline call: ",
-              JSON::Any->jsonToObj( $obj->get_error() ), "  Aborted.\n";
+              "$error  Aborted.\n";
         } else {
             print $fh
               "type:debug API Error during friends_timeline call. Aborted.\n";
@@ -617,6 +613,7 @@ sub do_updates {
         my $text = decode_entities( $t->{text} );
         $text =~ s/%/%%/g;
         $text =~ s/(^|\W)\@([-\w]+)/$1%B\@$2%n/g;
+        $text =~ s/[\n\r]/ /g;
         my $reply = "tweet";
         if (    Irssi::settings_get_bool("show_reply_context")
             and $t->{in_reply_to_screen_name} ne $username
@@ -633,6 +630,7 @@ sub do_updates {
                 my $ctext = decode_entities( $context->{text} );
                 $ctext =~ s/%/%%/g;
                 $ctext =~ s/(^|\W)\@([-\w]+)/$1%B\@$2%n/g;
+                $ctext =~ s/[\n\r]/ /g;
                 printf $fh "id:%d account:%s nick:%s type:tweet %s\n",
                   $context->{id}, $username,
                   $context->{user}{screen_name}, $ctext;
@@ -670,6 +668,7 @@ sub do_updates {
         my $text = decode_entities( $t->{text} );
         $text =~ s/%/%%/g;
         $text =~ s/(^|\W)\@([-\w]+)/$1%B\@$2%n/g;
+        $text =~ s/[\n\r]/ /g;
         printf $fh "id:%d account:%s nick:%s type:tweet %s\n",
           $t->{id}, $username, $t->{user}{screen_name}, $text;
     }
@@ -690,6 +689,7 @@ sub do_updates {
         my $text = decode_entities( $t->{text} );
         $text =~ s/%/%%/g;
         $text =~ s/(^|\W)\@([-\w]+)/$1%B\@$2%n/g;
+        $text =~ s/[\n\r]/ /g;
         printf $fh "id:%d account:%s nick:%s type:dm %s\n",
           $t->{id}, $username, $t->{sender_screen_name}, $text;
     }
@@ -897,6 +897,21 @@ sub sig_complete {
     }
 }
 
+sub event_send_text {
+    my ( $line, $server, $win ) = @_;
+    my $awin = Irssi::active_win();
+
+    # if the window where we got our text was the twitter window, and the user
+    # wants to be lazy, tweet away!
+    if ( ( $awin->get_active_name() eq $window->{name} )
+        and Irssi::settings_get_bool("tweet_window_input") )
+    {
+        &cmd_tweet( $line, $server, $win );
+    }
+}
+
+Irssi::signal_add( "send text", "event_send_text" );
+
 Irssi::settings_add_str( "twirssi", "twitter_window",     "twitter" );
 Irssi::settings_add_str( "twirssi", "bitlbee_server",     "bitlbee" );
 Irssi::settings_add_str( "twirssi", "short_url_provider", "TinyURL" );
@@ -913,6 +928,7 @@ Irssi::settings_add_bool( "twirssi", "twirssi_debug",             0 );
 Irssi::settings_add_bool( "twirssi", "twirssi_first_run",         1 );
 Irssi::settings_add_bool( "twirssi", "twirssi_track_replies",     1 );
 Irssi::settings_add_bool( "twirssi", "twirssi_use_reply_aliases", 0 );
+Irssi::settings_add_bool( "twirssi", "tweet_window_input",        0 );
 $window = Irssi::window_find_name( Irssi::settings_get_str('twitter_window') );
 
 if ($window) {