AnyEvent-IRC

 view release on metacpan or  search on metacpan

lib/AnyEvent/IRC/Client.pm  view on Meta::CPAN

the messages if it hasn't joined the channel C<$channel> yet. The queued
messages will be send once the connection successfully JOINed the C<$channel>.

C<$channel> will be lowercased so that any case that comes from the server matches.
(Yes, IRC handles upper and lower case as equal :-(

Be careful with this, there are chances you might not join the channel you
wanted to join. You may wanted to join #bla and the server redirects that
and sends you that you joined #blubb. You may use C<clear_chan_queue> to
remove the queue after some timeout after joining, so that you don't end up
with a memory leak.

=cut

sub send_chan {
   my ($self, $chan, @msg) = @_;

   if ($self->{channel_list}->{$self->lower_case ($chan)}) {
      $self->send_msg (@msg);

   } else {
      push @{$self->{chan_queue}->{$self->lower_case ($chan)}}, \@msg;
   }
}

=item $cl->clear_chan_queue ($channel)

Clears the channel queue of the channel C<$channel>.

=cut

sub clear_chan_queue {
   my ($self, $chan) = @_;
   $self->{chan_queue}->{$self->lower_case ($chan)} = [];
}

=item my (@lines) = $cl->send_long_message ($encoding, $overhead, $cmd, @params, $msg)

As IRC only allows 512 byte blocks of messages and sometimes
your messages might get longer, you have a problem. This method
will solve your problem:

This method can be used to split up long messages into multiple
commands.

C<$cmd> and C<@params> are the IRC command and it's first parameters,
except the last one: the C<$msg>. C<$msg> can be a Unicode string,
which will be encoded in C<$encoding> before sending.

If you want to send a CTCP message you can encode it in the C<$cmd> by
appending the CTCP command with a C<"\001">. For example if you want to
send a CTCP ACTION you have to give this C<$cmd>:

   $cl->send_long_message (undef, 0, "PRIVMSG\001ACTION", "#test", "rofls");

C<$encoding> can be undef if you don't need any recoding of C<$msg>.
But in case you want to send Unicode it is necessary to determine where
to split a message exactly, to not break the encoding.

Please also note that the C<nick_ident> for your own nick is necessary to
compute this. To ensure best performance as possible use the
C<send_initial_whois> option if you want to use this method.

But note that this method might not work 100% correct and you might still get
at least partially chopped off lines if you use C<send_long_message> before the
C<WHOIS> reply to C<send_initial_whois> arrived.

To be on the safest side you might want to wait until that initial C<WHOIS>
reply arrived.

The return value of this method is the list of the actually sent lines (but
without encoding applied).

=cut

sub send_long_message {
   my ($self, $encoding, $overhead, $cmd, @params) = @_;
   my $msg = pop @params;

   my $ctcp;
   ($cmd, $ctcp) = split /\001/, $cmd;

   my $id = $self->nick_ident ($self->nick);
   if ($id eq '') {
      $id = "X" x 60; # just in case the ident is not available...
   }

   my $init_len = length mk_msg ($id, $cmd, @params, " "); # i know off by 1

   if ($ctcp ne '') {
      $init_len += length ($ctcp) + 3; # CTCP cmd + " " + "\001" x 2
   }

   my $max_len = 500; # give 10 bytes extra margin

   my $line_len = $max_len - $init_len;

   # split up the multiple lines in the message:
   my @lines = split /\n/, $msg;

   # splitup long lines into multiple ones:
   @lines =
      map split_unicode_string ($encoding, $_, $line_len), @lines;

   # send lines line-by-line:
   for my $line (@lines) {
      my $smsg = encode ($encoding, $line);

      if ($ctcp ne '') {
         $smsg = encode_ctcp ([$ctcp, $smsg])
      }

      $self->send_srv ($cmd => @params, $smsg);
   }

   @lines
}

=item $cl->enable_ping ($interval, $cb)

This method enables a periodical ping to the server with an interval of



( run in 0.862 second using v1.01-cache-2.11-cpan-39bf76dae61 )