Ignore:
Timestamp:
Apr 3, 2011, 3:06:00 PM (11 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
38d50c2
Parents:
fb96152
git-author:
Nelson Elhage <nelhage@nelhage.com> (02/24/11 22:14:37)
git-committer:
Nelson Elhage <nelhage@mit.edu> (04/03/11 15:06:00)
Message:
Port IRC support to AnyEvent::IRC.
File:
1 edited

Legend:

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

    r9620c8d r8ba9313  
    2020use BarnOwl::Module::IRC::Completion;
    2121
    22 use Net::IRC;
     22use AnyEvent::IRC;
    2323use Getopt::Long;
    2424use Encode;
     
    7070
    7171    register_commands();
    72     register_handlers();
    7372    BarnOwl::filter(qw{irc type ^IRC$ or ( type ^admin$ and adminheader ^IRC$ )});
    7473}
     
    7675sub shutdown {
    7776    for my $conn (values %ircnets) {
    78         $conn->conn->disconnect();
     77        $conn->conn->disconnect('Quitting');
    7978    }
    8079}
     
    105104
    106105    return $list;
    107 }
    108 
    109 #sub mainloop_hook {
    110 #    return unless defined $irc;
    111 #    eval {
    112 #        $irc->do_one_loop();
    113 #    };
    114 #    return;
    115 #}
    116 
    117 sub OwlProcess {
    118     return unless defined $irc;
    119     eval {
    120         $irc->do_one_loop();
    121     };
    122     return;
    123 }
    124 
    125 
    126 sub register_handlers {
    127     if(!$irc) {
    128         $irc = Net::IRC->new;
    129         $irc->timeout(0);
    130     }
    131106}
    132107
     
    406381    }
    407382
    408     my $conn = BarnOwl::Module::IRC::Connection->new($irc, $alias,
    409         Nick      => $nick,
    410         Server    => $host,
    411         Port      => $port,
    412         Username  => $username,
    413         Ircname   => $ircname,
    414         Port      => $port,
    415         Password  => $password,
    416         SSL       => $ssl
    417        );
    418 
    419     if ($conn->conn->connected) {
    420         $conn->connected("Connected to $alias as $nick");
    421     } else {
    422         die("IRC::Connection->connect failed: $!");
    423     }
    424 
     383    my $conn = BarnOwl::Module::IRC::Connection->new($alias, $host, $port, {
     384        nick      => $nick,
     385        user      => $username,
     386        real      => $ircname,
     387        password  => $password,
     388        SSL       => $ssl,
     389        timeout   => sub {0}
     390       });
    425391    return;
    426392}
     
    429395    my $cmd = shift;
    430396    my $conn = shift;
    431     if ($conn->conn->connected) {
    432         $conn->conn->disconnect;
     397    if ($conn->conn->is_connected) {
     398        $conn->conn->disconnect("Goodbye!");
    433399    } elsif ($reconnect{$conn->alias}) {
    434400        BarnOwl::admin_message('IRC',
     
    463429    for my $body (@msgs) {
    464430        if ($body =~ /^\/me (.*)/) {
    465             $conn->conn->me($to, Encode::encode('utf-8', $1));
     431            $conn->me($to, Encode::encode('utf-8', $1));
    466432            $body = '* '.$conn->nick.' '.$1;
    467433        } else {
    468             $conn->conn->privmsg($to, Encode::encode('utf-8', $body));
     434            $conn->conn->send_msg('privmsg', $to, Encode::encode('utf-8', $body));
    469435        }
    470436        my $msg = BarnOwl::Message->new(
     
    491457    my $target = shift;
    492458    $target ||= shift;
    493     $conn->conn->mode($target, @_);
     459    $conn->conn->send_msg(mode => $target, @_);
    494460    return;
    495461}
     
    501467    $channels{$chan} ||= [];
    502468    push @{$channels{$chan}}, $conn;
    503     $conn->conn->join($chan, @_);
     469    $conn->conn->send_msg(join => $chan, @_);
    504470    return;
    505471}
     
    510476    my $chan = shift;
    511477    $channels{$chan} = [grep {$_ ne $conn} @{$channels{$chan} || []}];
    512     $conn->conn->part($chan);
     478    $conn->conn->send_msg(part => $chan);
    513479    return;
    514480}
     
    518484    my $conn = shift;
    519485    my $nick = shift or die("Usage: $cmd <new nick>\n");
    520     $conn->conn->nick($nick);
     486    $conn->conn->send_msg(nick => $nick);
    521487    return;
    522488}
     
    527493    my $chan = shift;
    528494    $conn->names_tmp([]);
    529     $conn->conn->names($chan);
     495    $conn->conn->send_msg(names => $chan);
    530496    return;
    531497}
     
    535501    my $conn = shift;
    536502    my $who = shift || die("Usage: $cmd <user>\n");
    537     $conn->conn->whois($who);
     503    $conn->conn->send_msg(whois => $who);
    538504    return;
    539505}
     
    542508    my $cmd = shift;
    543509    my $conn = shift;
    544     $conn->conn->motd;
     510    $conn->conn->send_msg('motd');
    545511    return;
    546512}
     
    560526    my $conn = shift;
    561527    my $who = shift || die("Usage: $cmd <user>\n");
    562     BarnOwl::error("WHO $cmd $conn $who");
    563     $conn->conn->who($who);
     528    $conn->conn->send_msg(who => $who);
    564529    return;
    565530}
     
    569534    my $conn = shift;
    570535    my $type = shift || die("Usage: $cmd <chiklmouy> [server] \n");
    571     $conn->conn->stats($type, @_);
     536    $conn->conn->send_msg(stats => $type, @_);
    572537    return;
    573538}
     
    577542    my $conn = shift;
    578543    my $chan = shift;
    579     $conn->conn->topic($chan, @_ ? join(" ", @_) : undef);
     544    $conn->conn->send_msg(topic => $chan, @_ ? join(" ", @_) : undef);
    580545    return;
    581546}
     
    584549    my $cmd = shift;
    585550    my $conn = shift;
    586     $conn->conn->sl(join(" ", @_));
     551    $conn->conn->send_msg(@_);
    587552    return;
    588553}
Note: See TracChangeset for help on using the changeset viewer.