Changeset 369479d for perl


Ignore:
Timestamp:
Jan 9, 2008, 2:18:31 PM (16 years ago)
Author:
Alejandro R. Sedeño <asedeno@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:
16c6cca
Parents:
428834d (diff), 6286f26 (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 803-811 via svnmerge from 
file:///afs/sipb.mit.edu/project/barnowl/src/svn/trunk

........
  r805 | geofft | 2008-01-08 23:24:09 -0500 (Tue, 08 Jan 2008) | 5 lines
  
  Added support for channels in IRC. After you :irc-connect to a server, you can
  :irc-join #channel, and then :irc-msg either a user or a #channel. Replies,
  isprivate, and context should work vaguely as expected.
........
  r806 | nelhage | 2008-01-09 00:25:32 -0500 (Wed, 09 Jan 2008) | 1 line
........
  r807 | nelhage | 2008-01-09 00:25:56 -0500 (Wed, 09 Jan 2008) | 1 line
........
  r808 | nelhage | 2008-01-09 00:26:15 -0500 (Wed, 09 Jan 2008) | 3 lines
  
   r27173@lunatique:  nelhage | 2008-01-09 00:25:13 -0500
   Implement smartnarrow on channels
........
  r809 | nelhage | 2008-01-09 01:26:19 -0500 (Wed, 09 Jan 2008) | 4 lines
  
   r27177@lunatique:  nelhage | 2008-01-09 01:23:14 -0500
   import is_private from ::Connection
   
........
  r810 | nelhage | 2008-01-09 02:23:31 -0500 (Wed, 09 Jan 2008) | 3 lines
  
   r27179@lunatique:  nelhage | 2008-01-09 02:22:05 -0500
   Implement irc-nick
........
Location:
perl/modules/IRC/lib/BarnOwl
Files:
3 edited

Legend:

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

    rb38b0b2 r0e52069  
    3636        return $filter;
    3737    } else {
    38         # Unimplemented
    39         return undef;
     38        # To a Channel
     39        my $network = $self->network;
     40        my $channel = $self->channel;
     41        my $filter = "irc-$network-channel-$channel";
     42        my $ftext = qq{type ^irc\$ and network ^$network\$ and channel ^$channel\$};
     43        BarnOwl::filter("$filter $ftext");
     44        return $filter;
    4045    }
    4146}
     
    4348sub server {shift->{server}}
    4449sub network {shift->{network}}
     50sub channel {shift->{channel}}
    4551
    4652# display
    47 sub context {shift->{channel};}
     53sub context {shift->{network};}
     54sub subcontext {shift->{recipient};}
    4855
    4956sub long_sender {shift->{from} || ""};
  • perl/modules/IRC/lib/BarnOwl/Module/IRC.pm

    rb38b0b2 r6286f26  
    66=head1 NAME
    77
    8 BarnOwl::Module::Jabber
     8BarnOwl::Module::IRC
    99
    1010=head1 DESCRIPTION
    1111
    12 This module implements Jabber support for barnowl.
     12This module implements IRC support for barnowl.
    1313
    1414=cut
     
    1717use BarnOwl::Hooks;
    1818use BarnOwl::Message::IRC;
    19 use BarnOwl::Module::IRC::Connection;
     19use BarnOwl::Module::IRC::Connection qw(is_private);
    2020
    2121use Net::IRC;
    2222use Getopt::Long;
    2323
    24 our $VERSION = 0.01;
     24our $VERSION = 0.02;
    2525
    2626our $irc;
     
    3030
    3131sub startup {
    32     BarnOwl::new_variable_string(ircnick => {default => $ENV{USER}});
    33     BarnOwl::new_variable_string(ircuser => {default => $ENV{USER}});
    34     BarnOwl::new_variable_string(ircname => {default => ""});
     32    BarnOwl::new_variable_string('irc:nick', {default => $ENV{USER}});
     33    BarnOwl::new_variable_string('irc:user', {default => $ENV{USER}});
     34    BarnOwl::new_variable_string('irc:name', {default => ""});
     35    BarnOwl::new_variable_bool('irc:spew', {default => 0});
    3536    register_commands();
    3637    register_handlers();
     
    4041sub shutdown {
    4142    for my $conn (values %ircnets) {
    42         $conn->disconnect;
     43        $conn->disconnect();
    4344    }
    4445}
     
    6364    BarnOwl::new_command('irc-disconnect' => \&cmd_disconnect);
    6465    BarnOwl::new_command('irc-msg'     => \&cmd_msg);
     66    BarnOwl::new_command('irc-join' => \&cmd_join);
     67    BarnOwl::new_command('irc-nick' => \&cmd_nick);
    6568}
    6669
     
    7679    my $cmd = shift;
    7780
    78     my $nick = BarnOwl::getvar('ircnick');
    79     my $username = BarnOwl::getvar('ircuser');
    80     my $ircname = BarnOwl::getvar('ircname');
     81    my $nick = BarnOwl::getvar('irc:nick');
     82    my $username = BarnOwl::getvar('irc:user');
     83    my $ircname = BarnOwl::getvar('irc:name');
    8184    my $host;
    8285    my $port;
     
    9093            "alias=s"    => \$alias,
    9194            "ssl"        => \$ssl,
    92             "password=s" => \$password);
     95            "password=s" => \$password,
     96            "port=i"     => \$port,
     97        );
    9398        $host = shift @ARGV or die("Usage: $cmd HOST\n");
    9499        if(!$alias) {
     
    126131    my $conn = get_connection(\@_);
    127132    my $to = shift or die("Usage: $cmd NICK\n");
     133    # handle multiple recipients?
    128134    if(@_) {
    129135        process_msg($conn, $to, join(" ", @_));
     
    148154        body        => $body,
    149155        sender      => $conn->nick,
    150         isprivate   => 'true',
     156        is_private($to) ?
     157          (isprivate  => 'true') : (channel => $to),
    151158        replycmd    => "irc-msg $to",
    152         replysendercmd => "irc-msg " . $conn->nick
     159        replysendercmd => "irc-msg $to"
    153160       );
    154161    BarnOwl::queue_message($msg);
    155162}
    156163
     164sub cmd_join {
     165    my $cmd = shift;
     166    my $conn = get_connection(\@_);
     167    my $chan = shift or die("Usage: $cmd channel\n");
     168    $conn->join($chan);
     169}
     170
     171sub cmd_nick {
     172    my $cmd = shift;
     173    my $conn = get_connection(\@_);
     174    my $nick = shift or die("Usage: $cmd <new nick>");
     175    $conn->nick($nick);
     176}
    157177
    158178################################################################################
     
    177197
    178198sub get_connection_by_alias {
    179     die("No such ircnet: $alias\n") unless exists $ircnets{$key};
     199    my $key = shift;
     200    die("No such ircnet: $key\n") unless exists $ircnets{$key};
    180201    return $ircnets{$key};
    181202}
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    rb38b0b2 r0e52069  
    1515=cut
    1616
    17 use base qw(Net::IRC::Connection Class::Accessor);
     17use base qw(Net::IRC::Connection Class::Accessor Exporter);
    1818__PACKAGE__->mk_accessors(qw(alias channels));
     19our @EXPORT_OK = qw(&is_private);
    1920
    2021use BarnOwl;
     
    3031    bless($self, $class);
    3132
    32     $self->add_global_handler(endofmotd => sub { goto &on_connect });
    33     $self->add_global_handler(msg => sub { goto &on_msg });
    34     $self->add_global_handler(notice => sub { goto &on_msg });
     33    $self->add_global_handler(376 => sub { goto &on_connect });
     34    $self->add_global_handler(['msg', 'notice', 'public', 'caction'],
     35            sub { goto &on_msg });
     36    $self->add_global_handler(cping => sub { goto &on_ping });
    3537    $self->add_default_handler(sub { goto &on_event; });
    3638
     
    4951sub on_msg {
    5052    my ($self, $evt) = @_;
    51     my $replycmd = "irc-msg " . $evt->nick;
     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';
    5256    my $msg = BarnOwl::Message->new(
    5357        type        => 'IRC',
     
    5559        server      => $self->server,
    5660        network     => $self->alias,
    57         recipient   => $self->nick,
    58         body        => strip_irc_formatting([$evt->args]->[0]),
     61        recipient   => $recipient,
     62        body        => $body,
    5963        sender      => $evt->nick,
    6064        hostname    => $evt->host,
    6165        from        => $evt->from,
    62         notice      => $evt->type eq 'notice' ? 'true' : '',
    63         isprivate   => 'true',
    64         replycmd    => $replycmd,
    65         replysendercmd => $replycmd
     66        $evt->type eq 'notice' ?
     67          (notice     => 'true') : (),
     68        is_private($recipient) ?
     69          (isprivate  => 'true') : (channel => $recipient),
     70        replycmd    => 'irc-msg ' .
     71            (is_private($recipient) ? $evt->nick : $recipient),
     72        replysendercmd => 'irc-msg ' . $evt->nick,
    6673       );
    6774    BarnOwl::queue_message($msg);
     75}
     76
     77sub on_ping {
     78    my ($self, $evt) = @_;
     79    $self->ctcp_reply($evt->nick, join (' ', ($evt->args)));
     80}
     81
     82sub on_event {
     83    my ($self, $evt) = @_;
     84    BarnOwl::admin_message("IRC",
     85            "Unhandled IRC event of type " . $evt->type . ":\n"
     86            . strip_irc_formatting(join("\n", $evt->args)))
     87        if BarnOwl::getvar('irc:spew') eq 'on';
    6888}
    6989
     
    83103}
    84104
     105# Determines if the given message recipient is a username, as opposed to
     106# a channel that starts with # or &.
     107sub is_private {
     108    return shift !~ /^[\#\&]/;
     109}
    85110
    861111;
Note: See TracChangeset for help on using the changeset viewer.