Changeset 9a023d0 for perl/modules


Ignore:
Timestamp:
Feb 6, 2010, 6:11:26 PM (12 years ago)
Author:
Geoffrey Thomas <geofft@mit.edu>
Branches:
master, release-1.6, release-1.7, release-1.8, release-1.9
Children:
3f18ad5
Parents:
c3a47c9
git-author:
Joshua Oreman <oremanj@mit.edu> (02/06/10 18:11:26)
git-committer:
Geoffrey Thomas <geofft@mit.edu> (02/06/10 18:11:26)
Message:
Send multiple PRIVMSGs for IRC messages entered as multiple paragraphs

It is occasionally useful to be able to send multiple lines of IRC text
at once, and I've grown used to barnowl's excellent support for
composing long messages. As a compromise between allowing multiline IRC
messages and not causing autowrap to send them inadvertently, send one
IRC-level message (PRIVMSG or CTCP ACTION) for each
two-newlines-separated paragraph in the user input to :irc-msg.

Reviewed-by: Geoffrey Thomas <geofft@mit.edu>
File:
1 edited

Legend:

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

    r416241f r9a023d0  
    453453    my $conn = shift;
    454454    my $to = shift;
    455     my $body = shift;
    456     # Strip whitespace. In the future -- send one message/line?
    457     $body =~ tr/\n\r/  /;
    458     if ($body =~ /^\/me (.*)/) {
    459         $conn->conn->me($to, Encode::encode('utf-8', $1));
    460         $body = '* '.$conn->nick.' '.$1;
    461     } else {
    462         $conn->conn->privmsg($to, Encode::encode('utf-8', $body));
    463     }
    464     my $msg = BarnOwl::Message->new(
    465         type        => 'IRC',
    466         direction   => is_private($to) ? 'out' : 'in',
    467         server      => $conn->server,
    468         network     => $conn->alias,
    469         recipient   => $to,
    470         body        => $body,
    471         sender      => $conn->nick,
    472         is_private($to) ?
    473           (isprivate  => 'true') : (channel => $to),
    474         replycmd    => BarnOwl::quote('irc-msg',  '-a', $conn->alias, $to),
    475         replysendercmd => BarnOwl::quote('irc-msg', '-a', $conn->alias, $to),
    476        );
    477     BarnOwl::queue_message($msg);
     455    my $fullbody = shift;
     456    my @msgs;
     457    # Require the user to send in paragraphs (double-newline between) to
     458    # actually send multiple PRIVMSGs, in order to play nice with autofill.
     459    $fullbody =~ s/\r//g;
     460    @msgs = split "\n\n", $fullbody;
     461    map { tr/\n/ / } @msgs;
     462    for my $body (@msgs) {
     463        if ($body =~ /^\/me (.*)/) {
     464            $conn->conn->me($to, Encode::encode('utf-8', $1));
     465            $body = '* '.$conn->nick.' '.$1;
     466        } else {
     467            $conn->conn->privmsg($to, Encode::encode('utf-8', $body));
     468        }
     469        my $msg = BarnOwl::Message->new(
     470            type        => 'IRC',
     471            direction   => is_private($to) ? 'out' : 'in',
     472            server      => $conn->server,
     473            network     => $conn->alias,
     474            recipient   => $to,
     475            body        => $body,
     476            sender      => $conn->nick,
     477            is_private($to) ?
     478              (isprivate  => 'true') : (channel => $to),
     479            replycmd    => BarnOwl::quote('irc-msg',  '-a', $conn->alias, $to),
     480            replysendercmd => BarnOwl::quote('irc-msg', '-a', $conn->alias, $to),
     481        );
     482        BarnOwl::queue_message($msg);
     483    }
    478484    return;
    479485}
Note: See TracChangeset for help on using the changeset viewer.