Ignore:
Timestamp:
Jan 11, 2008, 2:28:36 PM (14 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
fac5463
Parents:
16c6cca (diff), 9e02bb7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:
Merged revisions 812-830 via svnmerge from 
file:///afs/sipb.mit.edu/project/barnowl/src/svn/trunk

........
  r814 | nelhage | 2008-01-09 23:14:20 -0500 (Wed, 09 Jan 2008) | 3 lines
  
   r27181@lunatique:  nelhage | 2008-01-09 23:13:52 -0500
   Implement /part and /names. We don't parse the /names response yet
........
  r815 | nelhage | 2008-01-10 00:12:52 -0500 (Thu, 10 Jan 2008) | 1 line
  
  Show PART and JOIN messages
........
  r816 | nelhage | 2008-01-10 00:13:11 -0500 (Thu, 10 Jan 2008) | 2 lines
  
  Show the channel in LOG{IN,OUT} messages
........
  r817 | geofft | 2008-01-10 00:32:44 -0500 (Thu, 10 Jan 2008) | 6 lines
  
  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)
........
  r818 | nelhage | 2008-01-10 01:01:32 -0500 (Thu, 10 Jan 2008) | 2 lines
  
  Document the IRC variables
........
  r819 | nelhage | 2008-01-10 01:02:06 -0500 (Thu, 10 Jan 2008) | 3 lines
  
  Handle recreation of an existing variable better. Copy over the
  default and docstrings, but preserve the old value.
........
  r820 | nelhage | 2008-01-10 01:16:33 -0500 (Thu, 10 Jan 2008) | 2 lines
  
  Handle zephyrs to users on non -c message better (fixes #39)
........
  r821 | nelhage | 2008-01-10 01:28:59 -0500 (Thu, 10 Jan 2008) | 2 lines
  
  sprintf -> snprintf
........
  r822 | nelhage | 2008-01-10 01:43:11 -0500 (Thu, 10 Jan 2008) | 2 lines
  
  Make :reload-modules work correctly with PARs
........
  r823 | nelhage | 2008-01-10 15:47:00 -0500 (Thu, 10 Jan 2008) | 1 line
  
  Require 'isprivate' to be a literal 'true', not merely present for a message to be considered private
........
  r824 | nelhage | 2008-01-10 15:48:00 -0500 (Thu, 10 Jan 2008) | 2 lines
  
  Document (nearly) every public function in the BarnOwl:: namespace
........
  r825 | nelhage | 2008-01-10 15:49:27 -0500 (Thu, 10 Jan 2008) | 2 lines
  
  `beep' is already a barnowl command, so this binding is superfluous
........
  r826 | nelhage | 2008-01-10 15:58:49 -0500 (Thu, 10 Jan 2008) | 1 line
  
  strip IRC coloring from IRC messages
........
  r827 | nelhage | 2008-01-10 17:22:46 -0500 (Thu, 10 Jan 2008) | 2 lines
  
  Document ::Hook and ::Hooks
........
  r828 | geofft | 2008-01-10 21:01:27 -0500 (Thu, 10 Jan 2008) | 1 line
  
  Move comment around so that perlglue.xs compiles.
........
  r829 | nelhage | 2008-01-10 23:25:27 -0500 (Thu, 10 Jan 2008) | 1 line
  
  doc nits
........
  r830 | nelhage | 2008-01-11 01:38:50 -0500 (Fri, 11 Jan 2008) | 2 lines
  
  Handle `nickinuse' errors and disconnects
........
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    r0e52069 r9e02bb7  
    1616
    1717use base qw(Net::IRC::Connection Class::Accessor Exporter);
    18 __PACKAGE__->mk_accessors(qw(alias channels));
     18__PACKAGE__->mk_accessors(qw(alias channels motd));
    1919our @EXPORT_OK = qw(&is_private);
    2020
     
    2929    $self->alias($alias);
    3030    $self->channels([]);
     31    $self->motd("");
    3132    bless($self, $class);
    3233
    33     $self->add_global_handler(376 => sub { goto &on_connect });
    34     $self->add_global_handler(['msg', 'notice', 'public', 'caction'],
     34    $self->add_default_handler(sub { goto &on_event; });
     35    $self->add_handler(376 => sub { goto &on_connect });
     36    $self->add_handler(['msg', 'notice', 'public', 'caction'],
    3537            sub { goto &on_msg });
    36     $self->add_global_handler(cping => sub { goto &on_ping });
    37     $self->add_default_handler(sub { goto &on_event; });
     38    $self->add_handler(['welcome', 'yourhost', 'created',
     39            'luserclient', 'luserop', 'luserchannels', 'luserme'],
     40            sub { goto &on_admin_msg });
     41    $self->add_handler(['myinfo', 'map', 'n_local', 'n_global',
     42            'luserconns'],
     43            sub { });
     44    $self->add_handler(motdstart => sub { goto &on_motdstart });
     45    $self->add_handler(motd      => sub { goto &on_motd });
     46    $self->add_handler(endofmotd => sub { goto &on_endofmotd });
     47    $self->add_handler(join      => sub { goto &on_join });
     48    $self->add_handler(part      => sub { goto &on_part });
     49    $self->add_handler(disconnect => sub { goto &on_disconnect });
     50    $self->add_handler(nicknameinuse => sub { goto &on_nickinuse });
     51    $self->add_handler(cping     => sub { goto &on_ping });
    3852
    3953    return $self;
     
    4963}
    5064
    51 sub on_msg {
    52     my ($self, $evt) = @_;
    53     my ($recipient) = $evt->to;
    54     my $body = strip_irc_formatting([$evt->args]->[0]);
    55     $body = BarnOwl::Style::boldify($evt->nick.' '.$body) if $evt->type eq 'caction';
    56     my $msg = BarnOwl::Message->new(
     65sub new_message {
     66    my $self = shift;
     67    my $evt = shift;
     68    return BarnOwl::Message->new(
    5769        type        => 'IRC',
    58         direction   => 'in',
    5970        server      => $self->server,
    6071        network     => $self->alias,
    61         recipient   => $recipient,
    62         body        => $body,
    6372        sender      => $evt->nick,
    6473        hostname    => $evt->host,
    6574        from        => $evt->from,
     75        @_
     76       );
     77}
     78
     79sub on_msg {
     80    my ($self, $evt) = @_;
     81    my ($recipient) = $evt->to;
     82    my $body = strip_irc_formatting([$evt->args]->[0]);
     83    my $nick = $self->nick;
     84    BarnOwl::beep() if $body =~ /\b\Q$nick\E\b/;
     85    $body = BarnOwl::Style::boldify($evt->nick.' '.$body) if $evt->type eq 'caction';
     86    my $msg = $self->new_message($evt,
     87        direction   => 'in',
     88        recipient   => $recipient,
     89        body => $body,
    6690        $evt->type eq 'notice' ?
    6791          (notice     => 'true') : (),
     
    7094        replycmd    => 'irc-msg ' .
    7195            (is_private($recipient) ? $evt->nick : $recipient),
    72         replysendercmd => 'irc-msg ' . $evt->nick,
     96        replysendercmd => 'irc-msg ' . $evt->nick
    7397       );
     98
    7499    BarnOwl::queue_message($msg);
    75100}
     
    80105}
    81106
     107sub on_admin_msg {
     108    my ($self, $evt) = @_;
     109    BarnOwl::admin_message("IRC",
     110            BarnOwl::Style::boldify('IRC ' . $evt->type . ' message from '
     111                . $evt->alias) . "\n"
     112            . strip_irc_formatting(join '\n', cdr $evt->args));
     113}
     114
     115sub on_motdstart {
     116    my ($self, $evt) = @_;
     117    $self->motd(join "\n", cdr $evt->args);
     118}
     119
     120sub on_motd {
     121    my ($self, $evt) = @_;
     122    $self->motd(join "\n", $self->motd, cdr $evt->args);
     123}
     124
     125sub on_endofmotd {
     126    my ($self, $evt) = @_;
     127    $self->motd(join "\n", $self->motd, cdr $evt->args);
     128    BarnOwl::admin_message("IRC",
     129            BarnOwl::Style::boldify('MOTD for ' . $evt->alias) . "\n"
     130            . strip_irc_formatting($self->motd));
     131}
     132
     133sub on_join {
     134    my ($self, $evt) = @_;
     135    my $msg = $self->new_message($evt,
     136        loginout   => 'login',
     137        channel    => $evt->to,
     138        );
     139    BarnOwl::queue_message($msg);
     140}
     141
     142sub on_part {
     143    my ($self, $evt) = @_;
     144    my $msg = $self->new_message($evt,
     145        loginout   => 'logout',
     146        channel    => $evt->to,
     147        );
     148    BarnOwl::queue_message($msg);
     149}
     150
     151sub on_disconnect {
     152    my $self = shift;
     153    delete $BarnOwl::Module::IRC::ircnets{$self->alias};
     154
     155    BarnOwl::admin_message('IRC',
     156                           "[" . $self->alias . "] Disconnected from server");
     157}
     158
     159sub on_nickinuse {
     160    my ($self, $evt) = @_;
     161    BarnOwl::admin_message("IRC",
     162                           "[" . $self->alias . "] " .
     163                           [$evt->args]->[1] . ": Nick already in use");
     164}
     165
    82166sub on_event {
    83167    my ($self, $evt) = @_;
    84168    BarnOwl::admin_message("IRC",
    85             "Unhandled IRC event of type " . $evt->type . ":\n"
     169            "[" . $self->alias . "] Unhandled IRC event of type " . $evt->type . ":\n"
    86170            . strip_irc_formatting(join("\n", $evt->args)))
    87171        if BarnOwl::getvar('irc:spew') eq 'on';
    88172}
    89173
     174
    90175################################################################################
    91176########################### Utilities/Helpers ##################################
     
    94179sub strip_irc_formatting {
    95180    my $body = shift;
    96     my @pieces = split /\x02/, $body;
     181    # Strip mIRC colors. If someone wants to write code to convert
     182    # these to zephyr colors, be my guest.
     183    $body =~ s/\cC\d+(?:,\d+)?//g;
     184    $body =~ s/\cO//g;
     185   
     186    my @pieces = split /\cB/, $body;
    97187     my $out;
    98188    while(@pieces) {
     
    109199}
    110200
     201sub cdr {
     202    shift;
     203    return @_;
     204}
     205
    1112061;
Note: See TracChangeset for help on using the changeset viewer.