AnyEvent-IRC

 view release on metacpan or  search on metacpan

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


Returns a list of possible modes on this IRC server. (eg. 'o' for op).

=cut

sub available_nick_modes {
   my ($self) = @_;
   map { $self->map_prefix_to_mode ($_) } split //, $self->{prefix_chars}
}

=item $cl->is_channel_name ($string)

This return true if C<$string> is a channel name. It analyzes the prefix
of the string (eg. if it is '#') and returns true if it finds a channel prefix.
Those prefixes might be server specific, so ISUPPORT is checked for that too.

=cut

sub is_channel_name {
   my ($self, $string) = @_;

   my $cchrs = $self->{channel_chars};
   $string =~ /^([\Q$cchrs\E]+)(.+)$/;
}

=item $cl->nick_ident ($nick)

This method returns the whole ident of the C<$nick> if the information is available.
If the nick's ident hasn't been seen yet, undef is returned.

B<NOTE:> If you want to rely on the C<nick_ident> of your own nick you should
make sure to enable the C<send_initial_whois> option in the constructor.

=cut

sub nick_ident {
   my ($self, $nick) = @_;
   $self->{idents}->{$self->lower_case ($nick)}
}

=item my $bool = $cl->away_status

Returns a true value if you are away or undef if you are not away.

=cut

sub away_status { $_[0]->{away_status} }

=item $cl->ctcp_auto_reply ($ctcp_command, @msg)

=item $cl->ctcp_auto_reply ($ctcp_command, $coderef)

This method installs an auto-reply for the reception of the C<$ctcp_command>
via PRIVMSG, C<@msg> will be used as argument to the C<encode_ctcp> function of
the L<AnyEvent::IRC::Util> package. The replies will be sent with the NOTICE
IRC command.

If C<$coderef> was given and is a code reference, it will called each time a
C<$ctcp_command> is received, this is useful for eg.  CTCP PING reply
generation. The arguments will be the same arguments that the C<ctcp> event
callbacks get. (See also C<ctcp> event description above).  The return value of
the called subroutine should be a list of arguments for C<encode_ctcp>.

Currently you can only configure one auto-reply per C<$ctcp_command>.

Example:

   $cl->ctcp_auto_reply ('VERSION', ['VERSION', 'ScriptBla:0.1:Perl']);

   $cl->ctcp_auto_reply ('PING', sub {
      my ($cl, $src, $target, $tag, $msg, $type) = @_;
      ['PING', $msg]
   });

=cut

sub ctcp_auto_reply {
   my ($self, $ctcp_command, @msg) = @_;

   $self->{ctcp_auto_replies}->{$ctcp_command} = \@msg;
}

sub _setup_internal_dcc_handlers {
   my ($self) = @_;

   $self->reg_cb (ctcp_dcc => sub {
      my ($self, $src, $target, $msg, $type) = @_;

      if ($self->is_my_nick ($target)) {
         my ($dcc_type, $arg, $addr, $port) = split /\x20/, $msg;

         $dcc_type = lc $dcc_type;

         if ($dcc_type eq 'send') {
            if ($msg =~ /SEND (.*?) (\d+) (\d+)/) {
               ($arg, $addr, $port) = ($1, $2, $3);
               $arg =~ s/^\"(.*)\"$/\1/;
            }
         }

         $addr = format_address (pack "N", $addr);

         my $id = ++$self->{dcc_id};

         $self->{dcc}->{$id} = {
            type => lc ($dcc_type),
            dest => $self->lower_case ($src),
            ip   => $addr,
            port => $port,
            arg  => $arg,
         };

         $self->event (dcc_request => $id, $src, $dcc_type, $arg, $addr, $port);
      }
   });

   $self->reg_cb (dcc_ready => sub {
      my ($self, $id, $dest, $type, $local_ip, $local_port) = @_;

      $local_ip = unpack ("N", parse_address ($local_ip));



( run in 1.599 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )