Ignore:
Timestamp:
Jan 8, 2008, 11:24:09 PM (13 years ago)
Author:
Geoffrey Thomas <geofft@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:
0e52069
Parents:
c0f9e30
Message:
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.
File:
1 edited

Legend:

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

    rb38b0b2 r2c40dc0  
    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
     
    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);
    6567}
    6668
     
    7678    my $cmd = shift;
    7779
    78     my $nick = BarnOwl::getvar('ircnick');
    79     my $username = BarnOwl::getvar('ircuser');
    80     my $ircname = BarnOwl::getvar('ircname');
     80    my $nick = BarnOwl::getvar('irc:nick');
     81    my $username = BarnOwl::getvar('irc:user');
     82    my $ircname = BarnOwl::getvar('irc:name');
    8183    my $host;
    8284    my $port;
     
    9092            "alias=s"    => \$alias,
    9193            "ssl"        => \$ssl,
    92             "password=s" => \$password);
     94            "password=s" => \$password,
     95            "port=i"     => \$port,
     96        );
    9397        $host = shift @ARGV or die("Usage: $cmd HOST\n");
    9498        if(!$alias) {
     
    126130    my $conn = get_connection(\@_);
    127131    my $to = shift or die("Usage: $cmd NICK\n");
     132    # handle multiple recipients?
    128133    if(@_) {
    129134        process_msg($conn, $to, join(" ", @_));
     
    148153        body        => $body,
    149154        sender      => $conn->nick,
    150         isprivate   => 'true',
     155        is_private($to) ?
     156          (isprivate  => 'true') : (),
    151157        replycmd    => "irc-msg $to",
    152         replysendercmd => "irc-msg " . $conn->nick
     158        replysendercmd => "irc-msg $to"
    153159       );
    154160    BarnOwl::queue_message($msg);
    155161}
    156162
     163sub cmd_join {
     164    my $cmd = shift;
     165    my $conn = get_connection(\@_);
     166    my $chan = shift or die("Usage: $cmd channel\n");
     167    $conn->join($chan);
     168}
    157169
    158170################################################################################
     
    177189
    178190sub get_connection_by_alias {
    179     die("No such ircnet: $alias\n") unless exists $ircnets{$key};
     191    my $key = shift;
     192    die("No such ircnet: $key\n") unless exists $ircnets{$key};
    180193    return $ircnets{$key};
    181194}
    182195
     196# Determines if the given message recipient is a username, as opposed to
     197# a channel that starts with # or &.
     198sub is_private {
     199    return shift !~ /^[\#\&]/;
     200}
     201
    1832021;
Note: See TracChangeset for help on using the changeset viewer.