Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages

Manual Reference Pages  -  ANYEVENT::IRC::UTIL (3)

.ds Aq ’


AnyEvent::IRC::Util - Common utilities that help with IRC protocol handling



   use AnyEvent::IRC::Util qw/parse_irc_msg mk_msg/;

   my $msgdata = mk_msg (undef, PRIVMSG => "mcmanus", "my hands glow!");


These are some utility functions that might come in handy when handling the IRC protocol.

You can export these with eg.:

   use AnyEvent::IRC::Util qw/parse_irc_msg/;

<B>parse_irc_msg ($ircline)B> This method parses the $ircline, which is one line of the IRC protocol without the trailing \015\012.

It returns a hash which has the following entrys:
prefix The message prefix.
command The IRC command.
params The parameters to the IRC command in a array reference, this includes the trailing parameter (the one after the ’:’ or the 14th parameter).

<B>mk_msg ($prefix, B>$command<B>, B>@params<B>)B> This function assembles a IRC message. The generated message will look like (pseudo code!)

   :<prefix> <command> <params> :<trail>

Please refer to RFC 1459 how IRC messages normally look like.

The prefix will be omitted if they are undef.

Please note that only the last parameter may contain spaces, and if it contains spaces it will be quoted as the trailing part of the IRC message.

NOTE: The trailing \015\012 is NOT added by this function!


   mk_msg (undef, "PRIVMSG", "magnus", "you suck!");
   # will return: "PRIVMSG magnus :you suck!"

   mk_msg (undef, "PRIVMSG", "magnus", "Hi!");
   # will return: "PRIVMSG magnus :Hi!"

   mk_msg (undef, "JOIN", "#test");
   # will return: "JOIN #test"

<B>decode_ctcp ($data)B> This function decodes CTCP messages contained in an IRC message. $data should be the last parameter of a IRC PRIVMSG or NOTICE.

It will first unescape the lower layer, extract CTCP messages and then return a list with two elements: the line without the CTCP messages and an array reference which contains array references of CTCP messages. Those CTCP message array references will have the CTCP message tag as first element (eg. VERSION) and the rest of the CTCP message as the second element.

<B>encode_ctcp (@msg)B> This function encodes a CTCP message for the transmission via the NOTICE or PRIVMSG command. @msg is an array of strings or array references. If an array reference occurs in the @msg array it’s first element will be interpreted as CTCP TAG (eg. one of PING, VERSION, .. whatever) the rest of the array ref will be appended to the tag and separated by spaces.

All parts of the message will be concatenated and lowlevel quoted. That means you can embed _any_ character from 0 to 255 in this message (thats what the lowlevel quoting allows).

<B>filter_colors ($line)B> This function will filter out any mIRC colors and (most) ansi escape sequences. Unfortunately the mIRC color coding will destroy improper colored numbers. So this function may destroy the message in some occasions a bit.
<B>split_prefix ($prefix)B> This function splits an IRC user prefix as described by RFC 2817 into the three parts: nickname, user and host. Which will be returned as a list with that order.

$prefix can also be a hash like it is returned by parse_irc_msg.

<B>is_nick_prefix ($prefix)B> Returns true if the prefix is a nick prefix, containing user and host.
<B>join_prefix ($nick, B>$user<B>, B>$host<B>)B> Joins $nick, $user and $host together to form a prefix.
<B>prefix_nick ($prefix)B> A shortcut to extract the nickname from the $prefix.

$prefix can also be a hash like it is returned by parse_irc_msg.

<B>prefix_user ($prefix)B> A shortcut to extract the username from the $prefix.

$prefix can also be a hash like it is returned by parse_irc_msg.

<B>prefix_host ($prefix)B> A shortcut to extract the hostname from the $prefix.

$prefix can also be a hash like it is returned by parse_irc_msg.

<B>rfc_code_to_name ($code)B> This function is a interface to the internal mapping or numeric replies to the reply name in RFC 2812 (which you may also consult).

$code is returned if no name for $code exists (as some server may extended the protocol).

my (@lines) = split_unicode_string ($encoding, $string, $maxlinebytes) This function splits up $string into multiple @lines which are not longer than $maxlinebytes bytes. Encoding can be given in $encoding. (eg. ’utf-8’). But the output will not be encoded.

This function takes care that your characters are not garbled.


Robin Redeker, <>


Internet Relay Chat Client To Client Protocol from February 2, 1997

RFC 1459 - Internet Relay Chat: Client Protocol


Copyright 2006-2009 Robin Redeker, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Search for    or go to Top of page |  Section 3 |  Main Index

perl v5.20.3 ANYEVENT::IRC::UTIL (3) 2011-04-29

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.