X-Git-Url: https://git.sommitrealweird.co.uk/twirssi-net-twitter-lite.git/blobdiff_plain/763abb96238ae536e92ff472342f7e0c89bf2e65..e27a5afde618822a4890917e5e1587d45b2886a4:/twirssi.pl diff --git a/twirssi.pl b/twirssi.pl index c133378..334a633 100644 --- a/twirssi.pl +++ b/twirssi.pl @@ -13,7 +13,7 @@ $Data::Dumper::Indent = 1; use vars qw($VERSION %IRSSI); -$VERSION = "2.4.1beta"; +$VERSION = "2.4.2beta"; %IRSSI = ( authors => 'Dan Boger', contact => 'zigdon@gmail.com', @@ -131,11 +131,6 @@ sub cmd_retweet { sub cmd_retweet_as { my ( $data, $server, $win ) = @_; - unless ( Irssi::settings_get_bool("twirssi_track_replies") ) { - ¬ice("twirssi_track_replies is required in order to reteet."); - return; - } - return unless &logged_in($twit); $data =~ s/^\s+|\s+$//; @@ -296,13 +291,6 @@ sub cmd_reply { sub cmd_reply_as { my ( $data, $server, $win ) = @_; - unless ( Irssi::settings_get_bool("twirssi_track_replies") ) { - ¬ice("twirssi_track_replies is required in order to reply to " - . "specific tweets. Either enable it, or just use /tweet " - . "\@username ." ); - return; - } - return unless &logged_in($twit); $data =~ s/^\s+|\s+$//; @@ -524,7 +512,7 @@ sub cmd_login { ); } else { $twit = Net::Twitter->new( - traits => [ 'API::REST', 'OAuth', 'API::Search' ], + traits => [ 'API::REST', 'OAuth', 'API::Search' ], consumer_key => 'BZVAvBma4GxdiRwXIvbnw', consumer_secret => '0T5kahwLyb34vciGZsgkA9lsjtGCQ05vxVE2APXM', @@ -554,18 +542,15 @@ sub cmd_login { eval { $url = $twit->get_authorization_url; }; if ($@) { - ¬ice( -"ERROR: Failed to get OAuth authorization_url. Try again later." - ); + ¬ice( "ERROR: Failed to get OAuth authorization_url. " . + "Try again later."); return; } - - ¬ice("Twirssi not autorized to access $service for $user."); - ¬ice( - "Please authorize at the following url, then enter the pin " + ¬ice( "Twirssi not autorized to access $service for $user.", + "Please authorize at the following url, then enter the pin", + "supplied with /twirssi_oauth $user\@$service ", + $url ); - ¬ice("supplied with /twirssi_oauth $user\@$service "); - ¬ice($url); $oauth{pending}{"$user\@$service"} = $twit; return; @@ -693,7 +678,7 @@ sub verify_twitter_object { $poll = Irssi::timeout_add( &get_poll_time * 1000, \&get_updates, "" ); ¬ice("Logged in as $user\@$service, loading friends list..."); &load_friends(); - ¬ice( "loaded friends: ", scalar keys %friends ); + ¬ice( "loaded friends: ". scalar keys %friends ); if ( Irssi::settings_get_bool("twirssi_first_run") ) { Irssi::settings_set_bool( "twirssi_first_run", 0 ); } @@ -955,7 +940,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; } @@ -993,7 +979,7 @@ sub get_updates { return unless &logged_in($twit); my ( $fh, $filename ) = File::Temp::tempfile(); - binmode( $fh, ":utf8" ); + binmode( $fh, ":" . &get_charset ); $child_pid = fork(); if ($child_pid) { # parent @@ -1230,6 +1216,7 @@ sub do_updates { } $id_map{__searches}{$username}{$topic} = $search->{max_id}; + $topic =~ s/ /%20/g; printf $fh "id:%s account:%s type:searchid topic:%s\n", $search->{max_id}, $username, $topic; @@ -1332,7 +1319,7 @@ sub monitor_child { # pretend if ( open FILE, $filename ) { - binmode FILE, ":utf8"; + binmode FILE, ":" . &get_charset; my @lines; my %new_cache; while () { @@ -1346,8 +1333,9 @@ sub monitor_child { my %meta; foreach my $key (qw/id account nick type topic/) { - if (s/^$key:(\S+)\s*//) { + if (s/^$key:((?:\S|\\ )+)\s*//) { $meta{$key} = $1; + $meta{$key} =~ s/%20/ /g; } } @@ -1385,10 +1373,7 @@ sub monitor_child { } my $marker = ""; - if ( $meta{type} ne 'dm' - and Irssi::settings_get_bool("twirssi_track_replies") - and $meta{nick} - and $meta{id} ) + if ($meta{type} ne 'dm' and $meta{nick} and $meta{id} ) { $marker = ( $id_map{__indexes}{ $meta{nick} } + 1 ) % 100; $id_map{ lc $meta{nick} }[$marker] = $meta{id}; @@ -1526,7 +1511,7 @@ sub monitor_child { Irssi::pidwait_remove($child_pid); # and that we don't leave any zombies behind, somehow - wait(); + waitpid( -1, WNOHANG ); # save id_map hash if ( keys %id_map @@ -1554,7 +1539,7 @@ sub monitor_child { } else { print "Giving up on polling $filename" if &debug; Irssi::pidwait_remove($child_pid); - wait(); + waitpid( -1, WNOHANG ); unlink $filename unless &debug; return unless Irssi::settings_get_bool("twirssi_notify_timeouts"); @@ -1568,7 +1553,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 +1562,7 @@ sub monitor_child { q{ \\ a |}, q{ ',.__. ,__.-'/}, q{ '--/_.'----'`} - ) - { - &ccrap($whale); - } + ); $failwhale = 1; } @@ -1595,11 +1577,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 { @@ -1715,6 +1701,12 @@ sub get_poll_time { return 60; } +sub get_charset { + my $charset = Irssi::settings_get_str("twirssi_charset"); + return "utf8" if $charset =~ /^\s*$/; + return $charset; +} + sub hilight { my $text = shift; @@ -1755,7 +1747,7 @@ sub shorten { "Set short_url_args to username,API_key or change your", "short_url_provider." ); - return decode "utf8", $data; + return decode &get_charset, $data; } } @@ -1772,7 +1764,7 @@ sub shorten { } } - return decode "utf8", $data; + return decode &get_charset, $data; } sub normalize_username { @@ -1833,6 +1825,7 @@ Irssi::theme_register( ); Irssi::settings_add_int( "twirssi", "twitter_poll_interval", 300 ); +Irssi::settings_add_str( "twirssi", "twirssi_charset", "utf8" ); 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" ); @@ -1845,11 +1838,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 ); @@ -1860,7 +1853,6 @@ 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_replies_autonick", 1 ); Irssi::settings_add_bool( "twirssi", "twirssi_use_reply_aliases", 0 ); Irssi::settings_add_bool( "twirssi", "twirssi_notify_timeouts", 1 ); @@ -1989,10 +1981,9 @@ if ($window) { ); Irssi::signal_add_last( 'complete word' => \&sig_complete ); - ¬ice(" %Y<%C(%B^%C)%N TWIRSSI v%R$VERSION%N"); - ¬ice(" %C(_(\\%N http://twirssi.com/ for full docs"); - ¬ice( - " %Y||%C `%N Log in with /twitter_login, send updates with /tweet"); + ¬ice(" %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 ) {