hilight the nick of the person who tweeted @yournick, instead of hilighting @yournick...
[twirssi-net-twitter-lite.git] / twirssi.pl
index b00fe807628e6d0c6e0e9ba664c8baf29d430da4..4decda6d27c183e41f40536bc51c49b5de1e6d7b 100644 (file)
@@ -11,8 +11,8 @@ $Data::Dumper::Indent = 1;
 
 use vars qw($VERSION %IRSSI);
 
-$VERSION = "1.7.5";
-my ($REV) = '$Rev: 374 $' =~ /(\d+)/;
+$VERSION = "1.7.6";
+my ($REV) = '$Rev: 379 $' =~ /(\d+)/;
 %IRSSI = (
     authors     => 'Dan Boger',
     contact     => 'zigdon@gmail.com',
@@ -21,7 +21,7 @@ my ($REV) = '$Rev: 374 $' =~ /(\d+)/;
       . 'Can optionally set your bitlbee /away message to same',
     license => 'GNU GPL v2',
     url     => 'http://tinyurl.com/twirssi',
-    changed => '$Date: 2009-01-19 23:31:12 -0800 (Mon, 19 Jan 2009) $',
+    changed => '$Date: 2009-01-21 09:50:42 -0800 (Wed, 21 Jan 2009) $',
 );
 
 my $window;
@@ -34,6 +34,24 @@ my %friends;
 my $last_poll = time - 300;
 my %tweet_cache;
 my %id_map;
+my %irssi_to_mirc_colors = (
+    '%k'    => '01',
+    '%r'    => '05',
+    '%g'    => '03',
+    '%y'    => '07',
+    '%b'    => '02',
+    '%m'    => '06',
+    '%c'    => '10',
+    '%w'    => '15',
+    '%K'    => '14',
+    '%R'    => '04',
+    '%G'    => '09',
+    '%Y'    => '08',
+    '%B'    => '12',
+    '%M'    => '13',
+    '%C'    => '11',
+    '%W'    => '00',
+);
 
 sub cmd_direct {
     my ( $data, $server, $win ) = @_;
@@ -707,6 +725,7 @@ sub monitor_child {
         while (<FILE>) {
             chomp;
             last if /^__friends__/;
+            my $hilight = 0;
             my %meta;
             foreach my $key (qw/id account nick type/) {
                 if (s/^$key:(\S+)\s*//) {
@@ -733,17 +752,20 @@ sub monitor_child {
                 $marker                            = ":$marker";
             }
 
+            my $hilight_color = $irssi_to_mirc_colors{Irssi::settings_get_str("hilight_color")};
+            if ( $_ =~ /\@($meta{account})\W/ ) {
+                $meta{nick} = "\cC$hilight_color$meta{nick}\cO";
+                $hilight = MSGLEVEL_HILIGHT;
+            }
+
             if ( $meta{type} eq 'tweet' ) {
-                $window->printformat(MSGLEVEL_PUBLIC, 'twirssi_tweet',
-                  $account, $meta{nick}, $marker, $_);
+                push @lines, [(MSGLEVEL_PUBLIC | $hilight), $meta{type}, $account, $meta{nick}, $marker, $_];
             } elsif ( $meta{type} eq 'reply' ) {
-                $window->printformat(MSGLEVEL_PUBLIC, 'twirssi_reply',
-                  $account, $meta{nick}, $marker, $_);
+                push @lines, [(MSGLEVEL_PUBLIC | $hilight), $meta{type}, $account, $meta{nick}, $marker, $_];
             } elsif ( $meta{type} eq 'dm' ) {
-                $window->printformat(MSGLEVEL_PUBLIC, 'twirssi_dm',
-                  $account, $meta{nick}, $_);
+                push @lines, [(MSGLEVEL_MSGS | $hilight), $meta{type}, $account, $meta{nick}, $_];
             } elsif ( $meta{type} eq 'error' ) {
-                $window->print("ERROR: $_", MSGLEVEL_PUBLIC);
+                push @lines, [MSGLEVEL_MSGS, $_];
             } elsif ( $meta{type} eq 'debug' ) {
                 print "$_" if &debug,;
             } else {
@@ -763,6 +785,10 @@ sub monitor_child {
 
         if ($new_last_poll) {
             print "new last_poll = $new_last_poll" if &debug;
+            for my $line ( @lines ) {
+                $window->printformat(@$line[0], "twirssi_".@$line[1],
+                  @$line[2,3,4,5]);
+            }
 
             close FILE;
             unlink $filename
@@ -875,7 +901,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
@@ -908,6 +936,7 @@ 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',
+    'twirssi_error', 'ERROR: $0',
 ]);
 
 Irssi::settings_add_str( "twirssi", "twitter_window",     "twitter" );
@@ -929,6 +958,11 @@ 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" );