[823] in BarnOwl Developers

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

[D-O-H] r817 - in trunk/owl: . perl/modules/IRC/lib/BarnOwl/Module/IRC

daemon@ATHENA.MIT.EDU (geofft@MIT.EDU)
Thu Oct 29 18:10:06 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
Date: Thu, 10 Jan 2008 00:47:44 -0500
To: dirty-owl-hackers@mit.edu
From: geofft@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU

Author: geofft
Date: 2008-01-10 00:32:44 -0500 (Thu, 10 Jan 2008)
New Revision: 817

Modified:
   trunk/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
   trunk/owl/perlglue.xs
Log:
A (broken) attempt at handling motds and other IRC admin messages

Export owl_function_beep() to Perl, and ring the bell on receiving a message
containing your nick (on that network)



Modified: trunk/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
===================================================================
--- trunk/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm	2008-01-10 05:13:11 UTC (rev 816)
+++ trunk/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm	2008-01-10 05:32:44 UTC (rev 817)
@@ -15,7 +15,7 @@
 =cut
 
 use base qw(Net::IRC::Connection Class::Accessor Exporter);
-__PACKAGE__->mk_accessors(qw(alias channels));
+__PACKAGE__->mk_accessors(qw(alias channels motd));
 our @EXPORT_OK = qw(&is_private);
 
 use BarnOwl;
@@ -28,11 +28,21 @@
     my $self = $class->SUPER::new($irc, %args);
     $self->alias($alias);
     $self->channels([]);
+    $self->motd("");
     bless($self, $class);
 
     $self->add_global_handler(376 => sub { goto &on_connect });
     $self->add_global_handler(['msg', 'notice', 'public', 'caction'],
             sub { goto &on_msg });
+    $self->add_global_handler(['welcome', 'yourhost', 'created',
+            'luserclient', 'luserop', 'luserchannels', 'luserme'],
+            sub { goto &on_admin_msg });
+    $self->add_global_handler(['myinfo', 'map', 'n_local', 'n_global',
+            'luserconns'],
+            sub { });
+    $self->add_handler(375 => sub { goto &on_motdstart });
+    $self->add_handler(372 => sub { goto &on_motd });
+    $self->add_handler(376 => sub { goto &on_endofmotd });
     $self->add_global_handler(cping => sub { goto &on_ping });
     $self->add_global_handler(join  => sub { goto &on_join });
     $self->add_global_handler(part  => sub { goto &on_part });
@@ -68,6 +78,8 @@
     my ($self, $evt) = @_;
     my ($recipient) = $evt->to;
     my $body = strip_irc_formatting([$evt->args]->[0]);
+    my $nick = $self->nick;
+    BarnOwl::beep() if $body =~ /\b\Q$nick\E\b/;
     $body = BarnOwl::Style::boldify($evt->nick.' '.$body) if $evt->type eq 'caction';
     my $msg = $self->new_message($evt,
         direction   => 'in',
@@ -90,6 +102,32 @@
     $self->ctcp_reply($evt->nick, join (' ', ($evt->args)));
 }
 
+sub on_admin_msg {
+    my ($self, $evt) = @_;
+    BarnOwl::admin_message("IRC",
+            BarnOwl::Style::boldify('IRC ' . $evt->type . ' message from '
+                . $evt->alias) . "\n"
+            . strip_irc_formatting(join '\n', cdr $evt->args));
+}
+
+sub on_motdstart {
+    my ($self, $evt) = @_;
+    $self->motd(join "\n", cdr $evt->args);
+}
+
+sub on_motd {
+    my ($self, $evt) = @_;
+    $self->motd(join "\n", $self->motd, cdr $evt->args);
+}
+
+sub on_endofmotd {
+    my ($self, $evt) = @_;
+    $self->motd(join "\n", $self->motd, cdr $evt->args);
+    BarnOwl::admin_message("IRC",
+            BarnOwl::Style::boldify('MOTD for ' . $evt->alias) . "\n"
+            . strip_irc_formatting($self->motd));
+}
+
 sub on_join {
     my ($self, $evt) = @_;
     my $msg = $self->new_message($evt,
@@ -137,4 +175,9 @@
     return shift !~ /^[\#\&]/;
 }
 
+sub cdr {
+    shift;
+    return @_;
+}
+
 1;

Modified: trunk/owl/perlglue.xs
===================================================================
--- trunk/owl/perlglue.xs	2008-01-10 05:13:11 UTC (rev 816)
+++ trunk/owl/perlglue.xs	2008-01-10 05:32:44 UTC (rev 817)
@@ -324,3 +324,8 @@
 				      summ,
 				      desc,
 				      ival);
+
+void
+beep()
+    CODE:
+    owl_function_beep();


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