New irssi Frontend patch



Got an email a while back with a hugely updated irssi plugin from Martin 
van Beers <martijn eekeek org>.

Attached is a patch against the last CVS copy.

This patch adds capabilities much like the ones currently in gaim: It 
keeps track of statements which have been made in the past in the 
window, and if you change to that window, it sends these clues to the 
Dashboard.

Maximum lines sent is 5 at this time, could probably use a bit more with 
decreasing relevance. However, want to get this in, since I don't have a 
ton of time to hack on it, and I just realized that it didn't get sent 
to the dashboard list in the first place ;)

-- Chris
--- clue.pl	2004-03-15 23:46:00.000000000 -0600
+++ /home/crschmidt/irssi-frontend.pl	2004-05-11 13:37:35.000000000 -0500
@@ -2,50 +2,86 @@
 # Sends clue packets to the GNOME Dashboard application (see
 # http://www.nat.org/dashboard).  Does not do any interpretation
 # Of cluepackets, and only sends $msg with type textblock.
-# By Christopher Schmidt, 2/27/2004
-# crschmid uiuc edu
+# Christopher Schmidt -- crschmid uiuc edu
+# Martijn van Beers -- martijn eekeek org
 
 use Irssi;
 use Irssi::Irc;
 use Dashboard;
 $VERSION = "0.2";
 %IRSSI = (
-    authors     => 'Christopher Schmidt',
-    contact     => 'crschmid uiuc edu',
+    authors     => 'Multiple: See Source',
+    contact     => 'Multiple: See Source',
     name        => 'cluepacket',
     description => 'Sends cluepackets to dashboard',
     license     => 'Unlimited',
     url         => 'http://dashboard.crschmidt.net',
 );
 
+my $dash = new Dashboard("irssi", 'khazad-dum.copa');
+
+my %logs;
+
 sub on_public {
     my ($server, $msg, $nick, $addr, $target) = @_;
 
     $nick = $server->{'nick'} if ($nick =~ /^#/);
-    my $dash = new Dashboard("irssi");
     my $window = Irssi::active_win();
     #if ($target eq $window->{'name'}) {
     my $w = $window->{'active'};
     my $name = $w->{'name'};
     if (!$target || $target eq $name) {
-    $dash->send_cluepacket(
-            "$name",
-            1,
-            [
-                {
-                    'data' => $msg,
-                    'type' => "textblock",
-                    'relevance' => 10,
-                },
-            ]
-        );
+    	send_clues ($name, $msg);
+    } else {
+	if (defined $logs{$target}) {
+	    push (@{$logs{$target}}, $msg);
+	} else {
+	    $logs{$target} = [$msg];
+	}
+	shift @{$logs{$target}} if (@{$logs{$target}} >= 5);
+	#$server->print ($target, "($target, $name) added msg to queue", MSGLEVEL_NO_ACT);
     }
+}
 
+sub on_win_changed {
+	my ($window, $wi_item) = @_;
+	my $name;
+
+	$name = $wi_item->{'name'} if (defined $wi_item);
+	$name = $window->{'active'}->{'name'} unless (defined $name);
+
+	if (defined $logs{$name}) {
+		send_clues ($name);
+	}
 }
 
-# add ability to turn on/off cluepacket sending.
+sub send_clues {
+	my ($name, $msg) = @_;
+
+	my @list;
+	@list = @{$logs{$name}} if (defined $logs{$name});
+	$logs{$name} = [];
+	unshift (@list, $msg) if (defined $msg);
+	#my $count = @list;
+	#$server->print ($name, "($target, $name) sending $count clues", MSGLEVEL_NO_ACT);
+	@list = map {
+			{
+				data	=> $_,
+				type	=> "textblock",
+				relevance	=> 10,
+			}
+		} @list;
+
+	$dash->send_cluepacket("$name", 1, \ list);
+}
+	
+# FIXME: add ability to turn on/off cluepacket sending.
 
 # Put hooks on events
 Irssi::signal_add_last("message public", "on_public");
 Irssi::signal_add_last("message own_public", "on_public");
 
+Irssi::signal_add_last("window item changed", "on_win_changed");
+Irssi::signal_add_last("window changed", "on_win_changed");
+
+1;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]