X-Git-Url: https://git.sommitrealweird.co.uk/twirssi-net-twitter-lite.git/blobdiff_plain/5716c1e0ce7cd0149f01d3755e9fc52a45d8c484..80e4d669710c85419d93922eab15a556b6ab0c36:/twirssi.pl diff --git a/twirssi.pl b/twirssi.pl index af37616..b7e1767 100644 --- a/twirssi.pl +++ b/twirssi.pl @@ -1,7 +1,6 @@ use strict; use Irssi; use Irssi::Irc; -use Net::Twitter; use HTTP::Date; use HTML::Entities; use File::Temp; @@ -9,10 +8,18 @@ use LWP::Simple; use Data::Dumper; $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.2"; -my ($REV) = '$Rev: 348 $' =~ /(\d+)/; +$VERSION = "1.7.3"; +my ($REV) = '$Rev: 352 $' =~ /(\d+)/; %IRSSI = ( authors => 'Dan Boger', contact => 'zigdon@gmail.com', @@ -21,7 +28,7 @@ my ($REV) = '$Rev: 348 $' =~ /(\d+)/; . 'Can optionally set your bitlbee /away message to same', license => 'GNU GPL v2', url => 'http://tinyurl.com/twirssi', - changed => '$Date: 2009-01-06 11:09:34 -0800 (Tue, 06 Jan 2009) $', + changed => '$Date: 2009-01-08 13:46:50 -0800 (Thu, 08 Jan 2009) $', ); my $window; @@ -564,7 +571,7 @@ sub load_friends { }; if ($@) { - print $fh "type:error Error during friends list update. Aborted.\n"; + print $fh "type:debug Error during friends list update. Aborted.\n"; return; } @@ -637,7 +644,7 @@ sub get_updates { } if ($error) { - print $fh "type:error Update encountered errors. Aborted\n"; + print $fh "type:debug Update encountered errors. Aborted\n"; print $fh $last_poll; } else { print $fh $new_poll; @@ -659,17 +666,17 @@ sub do_updates { }; if ($@) { - print $fh "type:error Error during friends_timeline call. Aborted.\n"; + print $fh "type:debug Error during friends_timeline call. Aborted.\n"; return 1; } unless ( ref $tweets ) { if ( $obj->can("get_error") ) { - print $fh "type:error API Error during friends_timeline call: ", + print $fh "type:debug API Error during friends_timeline call: ", JSON::Any->jsonToObj( $obj->get_error() ), " Aborted.\n"; } else { print $fh - "type:error API Error during friends_timeline call. Aborted.\n"; + "type:debug API Error during friends_timeline call. Aborted.\n"; } return 1; } @@ -685,7 +692,11 @@ sub do_updates { and not exists $friends{ $t->{in_reply_to_screen_name} } ) { $nicks{ $t->{in_reply_to_screen_name} } = time; - my $context = $obj->show_status( $t->{in_reply_to_status_id} ); + my $context; + eval { + $context = $obj->show_status( $t->{in_reply_to_status_id} ); + }; + if ($context) { my $ctext = decode_entities( $context->{text} ); $ctext =~ s/%/%%/g; @@ -694,8 +705,10 @@ sub do_updates { $context->{id}, $username, $context->{user}{screen_name}, $ctext; $reply = "reply"; + } elsif ($@) { + print $fh "type:debug request to get context failed: $@"; } else { - print "Failed to get context from $t->{in_reply_to_screen_name}" + print $fh "type:debug Failed to get context from $t->{in_reply_to_screen_name}" if &debug; } } @@ -713,7 +726,7 @@ sub do_updates { }; if ($@) { - print $fh "type:error Error during replies call. Aborted.\n"; + print $fh "type:debug Error during replies call. Aborted.\n"; return 1; } @@ -736,7 +749,7 @@ sub do_updates { }; if ($@) { - print $fh "type:error Error during direct_messages call. Aborted.\n"; + print $fh "type:debug Error during direct_messages call. Aborted.\n"; return 1; } @@ -767,8 +780,9 @@ sub monitor_child { last if /^__friends__/; my %meta; foreach my $key (qw/id account nick type/) { - s/^$key:(\S+)\s*//; - $meta{$key} = $1; + if (s/^$key:(\S+)\s*//) { + $meta{$key} = $1; + } } next if exists $meta{id} and exists $tweet_cache{ $meta{id} }; @@ -875,8 +889,12 @@ sub notice { sub sig_complete { my ( $complist, $window, $word, $linestart, $want_space ) = @_; - # /twitter_reply gets a nick:num - if ( $linestart =~ /^\/twitter_reply(?:_as)?\s*$/ ) { + if ( + $linestart =~ /^\/twitter_reply(?:_as)?\s*$/ + or ( Irssi::settings_get_bool("twirssi_use_reply_aliases") + and $linestart =~ /^\/reply(?:_as)?\s*$/ ) + ) + { # /twitter_reply gets a nick:num @$complist = grep /^\Q$word/i, sort keys %{ $id_map{__indexes} }; } @@ -900,12 +918,13 @@ Irssi::settings_add_str( "twirssi", "twitter_usernames", undef ); Irssi::settings_add_str( "twirssi", "twitter_passwords", undef ); Irssi::settings_add_str( "twirssi", "twirssi_replies_store", ".irssi/scripts/twirssi.json" ); -Irssi::settings_add_bool( "twirssi", "tweet_to_away", 0 ); -Irssi::settings_add_bool( "twirssi", "show_reply_context", 0 ); -Irssi::settings_add_bool( "twirssi", "show_own_tweets", 1 ); -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", "tweet_to_away", 0 ); +Irssi::settings_add_bool( "twirssi", "show_reply_context", 0 ); +Irssi::settings_add_bool( "twirssi", "show_own_tweets", 1 ); +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 ); $window = Irssi::window_find_name( Irssi::settings_get_str('twitter_window') ); if ($window) { @@ -919,6 +938,10 @@ if ($window) { Irssi::command_bind( "twitter_logout", "cmd_logout" ); Irssi::command_bind( "twitter_switch", "cmd_switch" ); Irssi::command_bind( "twirssi_upgrade", "cmd_upgrade" ); + if ( Irssi::settings_get_bool("twirssi_use_reply_aliases") ) { + Irssi::command_bind( "reply", "cmd_reply" ); + Irssi::command_bind( "reply_as", "cmd_reply_as" ); + } Irssi::command_bind( "twirssi_dump", sub { @@ -933,9 +956,11 @@ if ($window) { Irssi::command_bind( "twirssi_version", sub { - ¬ice( -"Twirssi v$VERSION (r$REV); Net::Twitter v$Net::Twitter::VERSION. " - . "See details at http://tinyurl.com/twirssi" ); + ¬ice("Twirssi v$VERSION (r$REV); " + . "Net::Twitter v$Net::Twitter::VERSION. " + . "JSON in use: " + . JSON::Any::handler() + . ". See details at http://twirssi.com/" ); } ); Irssi::command_bind(