Changeset bc0d7bc for perl/modules


Ignore:
Timestamp:
Jan 10, 2008, 12:32:44 AM (17 years ago)
Author:
Geoffrey Thomas <geofft@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
b10f340
Parents:
2fb58e4
Message:
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)
File:
1 edited

Legend:

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

    r47b6a5f rbc0d7bc  
    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
     
    3435    $self->add_global_handler(['msg', 'notice', 'public', 'caction'],
    3536            sub { goto &on_msg });
     37    $self->add_global_handler(['welcome', 'yourhost', 'created',
     38            'luserclient', 'luserop', 'luserchannels', 'luserme'],
     39            sub { goto &on_admin_msg });
     40    $self->add_global_handler(['myinfo', 'map', 'n_local', 'n_global',
     41            'luserconns'],
     42            sub { });
     43    $self->add_handler(375 => sub { goto &on_motdstart });
     44    $self->add_handler(372 => sub { goto &on_motd });
     45    $self->add_handler(376 => sub { goto &on_endofmotd });
    3646    $self->add_global_handler(cping => sub { goto &on_ping });
    3747    $self->add_global_handler(join  => sub { goto &on_join });
     
    6979    my ($recipient) = $evt->to;
    7080    my $body = strip_irc_formatting([$evt->args]->[0]);
     81    my $nick = $self->nick;
     82    BarnOwl::beep() if $body =~ /\b\Q$nick\E\b/;
    7183    $body = BarnOwl::Style::boldify($evt->nick.' '.$body) if $evt->type eq 'caction';
    7284    my $msg = $self->new_message($evt,
     
    89101    my ($self, $evt) = @_;
    90102    $self->ctcp_reply($evt->nick, join (' ', ($evt->args)));
     103}
     104
     105sub on_admin_msg {
     106    my ($self, $evt) = @_;
     107    BarnOwl::admin_message("IRC",
     108            BarnOwl::Style::boldify('IRC ' . $evt->type . ' message from '
     109                . $evt->alias) . "\n"
     110            . strip_irc_formatting(join '\n', cdr $evt->args));
     111}
     112
     113sub on_motdstart {
     114    my ($self, $evt) = @_;
     115    $self->motd(join "\n", cdr $evt->args);
     116}
     117
     118sub on_motd {
     119    my ($self, $evt) = @_;
     120    $self->motd(join "\n", $self->motd, cdr $evt->args);
     121}
     122
     123sub on_endofmotd {
     124    my ($self, $evt) = @_;
     125    $self->motd(join "\n", $self->motd, cdr $evt->args);
     126    BarnOwl::admin_message("IRC",
     127            BarnOwl::Style::boldify('MOTD for ' . $evt->alias) . "\n"
     128            . strip_irc_formatting($self->motd));
    91129}
    92130
     
    138176}
    139177
     178sub cdr {
     179    shift;
     180    return @_;
     181}
     182
    1401831;
Note: See TracChangeset for help on using the changeset viewer.