X-Git-Url: https://git.sommitrealweird.co.uk/twirssi-net-twitter-lite.git/blobdiff_plain/b7bba11c9b49e4250a80ec63ef9eb4e68cc6d642..76607217eddfafc97688f74f8b686ae59e13f4a0:/twirssi.pl diff --git a/twirssi.pl b/twirssi.pl index 99c1ba2..0e372c7 100644 --- a/twirssi.pl +++ b/twirssi.pl @@ -13,7 +13,7 @@ $Data::Dumper::Indent = 1; use vars qw($VERSION %IRSSI); -$VERSION = "2.4.2beta"; +$VERSION = "2.4.2"; %IRSSI = ( authors => 'Dan Boger', contact => 'zigdon@gmail.com', @@ -542,14 +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.", - "Please authorize at the following url, then enter the pin", - "supplied with /twirssi_oauth $user\@$service ", - $url + ¬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 ); $oauth{pending}{"$user\@$service"} = $twit; @@ -678,7 +679,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 ); } @@ -979,7 +980,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 @@ -1093,9 +1094,31 @@ sub do_updates { return undef; } + my @ignore_tags = + Irssi::settings_get_str("twirssi_ignored_tags") + ? split /\s*,\s*/, Irssi::settings_get_str("twirssi_ignored_tags") + : (); + my @strip_tags = + Irssi::settings_get_str("twirssi_stripped_tags") + ? split /\s*,\s*/, Irssi::settings_get_str("twirssi_stripped_tags") + : (); foreach my $t ( reverse @$tweets ) { my $text = &get_text( $t, $obj ); my $reply = "tweet"; + + my $match = 0; + foreach my $tag (@ignore_tags) { + next unless $text =~ /\b\Q$tag\E\b/i; + $match = 1; + $text = "(ignored: $tag) $text" if &debug; + last; + } + next if not &debug and $match; + + foreach my $tag (@strip_tags) { + $text =~ s/\b\Q$tag\E\b//gi; + } + if ( Irssi::settings_get_bool("show_reply_context") and $t->{in_reply_to_screen_name} ne $username and $t->{in_reply_to_screen_name} @@ -1216,7 +1239,7 @@ sub do_updates { } $id_map{__searches}{$username}{$topic} = $search->{max_id}; - $topic =~ s/ /\\ /g; + $topic =~ s/ /%20/g; printf $fh "id:%s account:%s type:searchid topic:%s\n", $search->{max_id}, $username, $topic; @@ -1319,7 +1342,7 @@ sub monitor_child { # pretend if ( open FILE, $filename ) { - binmode FILE, ":utf8"; + binmode FILE, ":" . &get_charset; my @lines; my %new_cache; while () { @@ -1335,7 +1358,7 @@ sub monitor_child { foreach my $key (qw/id account nick type topic/) { if (s/^$key:((?:\S|\\ )+)\s*//) { $meta{$key} = $1; - $meta{$key} =~ s/\\ / /g; + $meta{$key} =~ s/%20/ /g; } } @@ -1373,8 +1396,7 @@ sub monitor_child { } my $marker = ""; - if ($meta{type} ne 'dm' 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}; $id_map{__indexes}{ $meta{nick} } = $marker; @@ -1562,7 +1584,7 @@ sub monitor_child { q{ \\ a |}, q{ ',.__. ,__.-'/}, q{ '--/_.'----'`} - ); + ); $failwhale = 1; } @@ -1701,6 +1723,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; @@ -1741,7 +1769,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; } } @@ -1758,7 +1786,7 @@ sub shorten { } } - return decode "utf8", $data; + return decode &get_charset, $data; } sub normalize_username { @@ -1819,6 +1847,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" ); @@ -1828,6 +1857,8 @@ Irssi::settings_add_str( "twirssi", "twitter_passwords", undef ); Irssi::settings_add_str( "twirssi", "twirssi_default_service", "Twitter" ); Irssi::settings_add_str( "twirssi", "twirssi_nick_color", "%B" ); Irssi::settings_add_str( "twirssi", "twirssi_topic_color", "%r" ); +Irssi::settings_add_str( "twirssi", "twirssi_ignored_tags", "" ); +Irssi::settings_add_str( "twirssi", "twirssi_stripped_tags", "" ); Irssi::settings_add_str( "twirssi", "twirssi_retweet_format", 'RT $n: "$t" ${-- $c$}' ); Irssi::settings_add_str( "twirssi", "twirssi_location", @@ -1974,9 +2005,11 @@ if ($window) { ); Irssi::signal_add_last( 'complete word' => \&sig_complete ); - ¬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"); + ¬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 ) {