X-Git-Url: https://git.sommitrealweird.co.uk/twirssi-net-twitter-lite.git/blobdiff_plain/ba48424a621abb05eb7219d01cdac67e2f474b9d..2cbdec5357caa3a57ae4fee320a8da2e420d2d4f:/twirssi.pl diff --git a/twirssi.pl b/twirssi.pl index 46d2e2c..edb207e 100644 --- a/twirssi.pl +++ b/twirssi.pl @@ -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.6"; +my ($REV) = '$Rev: 379 $' =~ /(\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-21 09:50:42 -0800 (Wed, 21 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"; @@ -615,8 +611,8 @@ sub do_updates { foreach my $t ( reverse @$tweets ) { my $text = decode_entities( $t->{text} ); - $text =~ s/%/%%/g; - $text =~ s/(^|\W)\@([-\w]+)/$1%B\@$2%n/g; + $text =~ s/(^|\W)\@([-\w]+)/$1\cC12\@$2\cO/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 @@ -631,8 +627,8 @@ sub do_updates { if ($context) { my $ctext = decode_entities( $context->{text} ); - $ctext =~ s/%/%%/g; - $ctext =~ s/(^|\W)\@([-\w]+)/$1%B\@$2%n/g; + $ctext =~ s/(^|\W)\@([-\w]+)/$1\cC12\@$2\cO/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; @@ -668,8 +664,8 @@ sub do_updates { if exists $friends{ $t->{user}{screen_name} }; my $text = decode_entities( $t->{text} ); - $text =~ s/%/%%/g; - $text =~ s/(^|\W)\@([-\w]+)/$1%B\@$2%n/g; + $text =~ s/(^|\W)\@([-\w]+)/$1\cC12\@$2\cO/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; } @@ -688,8 +684,8 @@ sub do_updates { foreach my $t ( reverse @$tweets ) { my $text = decode_entities( $t->{text} ); - $text =~ s/%/%%/g; - $text =~ s/(^|\W)\@([-\w]+)/$1%B\@$2%n/g; + $text =~ s/(^|\W)\@([-\w]+)/$1\cC12\@$2\cO/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; } @@ -711,6 +707,7 @@ sub monitor_child { while () { chomp; last if /^__friends__/; + my $hilight = 0; my %meta; foreach my $key (qw/id account nick type/) { if (s/^$key:(\S+)\s*//) { @@ -737,14 +734,18 @@ sub monitor_child { $marker = ":$marker"; } + if ( $_ =~ /\@$meta{account}\W/ ) { + $hilight = MSGLEVEL_HILIGHT; + } + if ( $meta{type} eq 'tweet' ) { - push @lines, "[$account%B\@$meta{nick}%n$marker] $_\n",; + push @lines, [(MSGLEVEL_PUBLIC | $hilight), $meta{type}, $account, $meta{nick}, $marker, $_]; } elsif ( $meta{type} eq 'reply' ) { - push @lines, "[$account\\--> %B\@$meta{nick}%n$marker] $_\n",; + push @lines, [(MSGLEVEL_PUBLIC | $hilight), $meta{type}, $account, $meta{nick}, $marker, $_]; } elsif ( $meta{type} eq 'dm' ) { - push @lines, "[$account%B\@$meta{nick}%n (%WDM%n)] $_\n",; + push @lines, [(MSGLEVEL_MSGS | $hilight), $meta{type}, $account, $meta{nick}, $_]; } elsif ( $meta{type} eq 'error' ) { - push @lines, "ERROR: $_\n"; + $window->print("ERROR: $_", MSGLEVEL_PUBLIC); } elsif ( $meta{type} eq 'debug' ) { print "$_" if &debug,; } else { @@ -764,12 +765,9 @@ sub monitor_child { if ($new_last_poll) { print "new last_poll = $new_last_poll" if &debug; - foreach my $line (@lines) { - chomp $line; - $window->print( $line, MSGLEVEL_PUBLIC ); - foreach ( $line =~ /\@([-\w]+)/ ) { - $nicks{$1} = time; - } + for my $line ( @lines ) { + $window->printformat(@$line[0], "twirssi_".@$line[1], + @$line[2,3,4,5]); } close FILE; @@ -883,7 +881,9 @@ sub sig_complete { and $linestart =~ /^\/reply(?:_as)?\s*$/ ) ) { # /twitter_reply gets a nick:num - @$complist = grep /^\Q$word/i, sort keys %{ $id_map{__indexes} }; + $word =~ s/^@//; + @$complist = map { "$_:$id_map{__indexes}{$_}" } grep /^\Q$word/i, + sort keys %{ $id_map{__indexes} }; } # /tweet, /tweet_as, /dm, /dm_as - complete @nicks (and nicks as the first @@ -897,6 +897,27 @@ 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::theme_register([ + 'twirssi_tweet', '[$0%B@$1%n$2] $3', + 'twirssi_reply', '[$0\--> %B@$1%n$2] $3', + 'twirssi_dm', '[$0%B@$1%n (%WDM%n)] $2', +]); + 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,8 +934,14 @@ 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) { + $window = Irssi::Windowitem::window_create (Irssi::settings_get_str('twitter_window'), 1); + $window->set_name (Irssi::settings_get_str('twitter_window')); +} + if ($window) { Irssi::command_bind( "dm", "cmd_direct" ); Irssi::command_bind( "dm_as", "cmd_direct_as" ); @@ -1016,3 +1043,4 @@ if ($window) { . " or change the value of twitter_window. Then, reload twirssi." ); } +# vim: set sts=4 expandtab: