Changeset c2866ec for perl/modules/IRC


Ignore:
Timestamp:
May 13, 2013, 8:11:59 PM (9 years ago)
Author:
Jason Gross <jgross@mit.edu>
Branches:
master
Children:
2e9b9ad, 53151d4, 67009f92
Parents:
0625919
git-author:
Jason Gross <jgross@mit.edu> (05/09/13 17:26:37)
git-committer:
Jason Gross <jgross@mit.edu> (05/13/13 20:11:59)
Message:
Split irc messages into chunks

From Zephyr:
   barnowl / irc-cutoff / kchen  2013-05-09 16:38  (Everyone Left Wheel Thru)
       This might be an IRC limitation.  RFC 1459 says:

       "IRC messages are always lines of characters terminated with a CR-LF
       (Carriage Return - Line Feed) pair, and these messages shall not
       exceed 512 characters in length, counting all characters including
       the trailing CR-LF. Thus, there are 510 characters maximum allowed
       for the command and its parameters.  There is no provision for
       continuation message lines.  See section 7 for more details about
       current implementations."

       (I didn't read the rest of the RFC to know how many other bytes are
       involved in sending a message.)

I chose 450 to be the default cut-off semi-arbitrarily; freenode seems
to allow up to about 463 characters (to channel #agda, with username
jgross).
File:
1 edited

Legend:

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

    rb8a3e00 rc2866ec  
    2323use Getopt::Long;
    2424use Encode;
     25use Text::Wrap;
    2526
    2627our $VERSION = 0.02;
     
    6566        description => 'If set, each (space-separated) message type ' .
    6667        'provided will be hidden and ignored if received.'
     68       });
     69
     70    BarnOwl::new_variable_int('irc:max-message-length', {
     71        default     => 450,
     72        summary     => 'Split messages to at most this many characters.' .
     73                       "If non-positive, don't split messages",
     74        description => 'If set to a positive number, any paragraph in an ' .
     75                       'IRC message will be split after this many characters.'
    6776       });
    6877
     
    427436    @msgs = split "\n\n", $fullbody;
    428437    map { tr/\n/ / } @msgs;
     438    # split each body at irc:max-message-length characters, if that number
     439    # is positive.  Only split at space boundaries.  Start counting a-fresh
     440    # at the beginning of each paragraph
     441    my $max_len = BarnOwl::getvar('irc:max-message-length');
     442    if ($max_len > 0) {
     443        local($Text::Wrap::columns) = $max_len;
     444        @msgs = split "\n", wrap("", "", join "\n", @msgs);
     445    }
    429446    for my $body (@msgs) {
    430447        if ($body =~ /^\/me (.*)/) {
Note: See TracChangeset for help on using the changeset viewer.