[1139] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r1091 - trunk/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC

daemon@ATHENA.MIT.EDU (geofft@MIT.EDU)
Thu Oct 29 18:13:25 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
X-Original-To: nelhage@nelhage.com
Date: Wed, 23 Jul 2008 21:05:18 -0400 (EDT)
To: dirty-owl-hackers@MIT.EDU
From: geofft@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU

Author: geofft
Date: 2008-07-23 21:05:18 -0400 (Wed, 23 Jul 2008)
New Revision: 1091

Modified:
   trunk/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
Log:
IRC: Add proper display for the :irc-names reply.

Modified: trunk/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
===================================================================
--- trunk/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm	2008-07-24 00:18:30 UTC (rev 1090)
+++ trunk/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm	2008-07-24 01:05:18 UTC (rev 1091)
@@ -17,7 +17,7 @@
 use Net::IRC::Connection;
 
 use base qw(Class::Accessor Exporter);
-__PACKAGE__->mk_accessors(qw(conn alias channels connected motd));
+__PACKAGE__->mk_accessors(qw(conn alias channels connected motd names_tmp whois_tmp));
 our @EXPORT_OK = qw(&is_private);
 
 use BarnOwl;
@@ -44,6 +44,8 @@
     $self->channels([]);
     $self->motd("");
     $self->connected(0);
+    $self->names_tmp([]);
+    $self->whois_tmp("");
 
     $self->conn->add_handler(376 => sub { shift; $self->on_connect(@_) });
     $self->conn->add_default_handler(sub { shift; $self->on_event(@_) });
@@ -66,6 +68,8 @@
     $self->conn->add_handler(cping     => sub { shift; $self->on_ping(@_) });
     $self->conn->add_handler(topic     => sub { shift; $self->on_topic(@_) });
     $self->conn->add_handler(topicinfo => sub { shift; $self->on_topicinfo(@_) });
+    $self->conn->add_handler(namreply  => sub { shift; $self->on_namreply(@_) });
+    $self->conn->add_handler(endofnames=> sub { shift; $self->on_endofnames(@_) });
 
     return $self;
 }
@@ -221,7 +225,25 @@
         if BarnOwl::getvar('irc:spew') eq 'on';
 }
 
+# IRC gives us a bunch of namreply messages, followed by an endofnames.
+# We need to collect them from the namreply and wait for the endofnames message.
+# After this happens, the names_tmp variable is cleared.
 
+sub on_namreply {
+    my ($self, $evt) = @_;
+    $self->names_tmp([@{$self->names_tmp}, split(' ', [$evt->args]->[3])]);
+}
+
+sub on_endofnames {
+    my ($self, $evt) = @_;
+    my $names = BarnOwl::Style::boldify("Members of " . [$evt->args]->[1] . ":\n");
+    for my $name (@{$self->names_tmp}) {
+        $names .= "  $name\n";
+    }
+    BarnOwl::popless_ztext($names);
+    $self->names_tmp([]);
+}
+
 ################################################################################
 ########################### Utilities/Helpers ##################################
 ################################################################################


home help back first fref pref prev next nref lref last post