AnyEve...C::Util(3pm)

πŸ“¦
version 0.97 Β· 2 versions
  • 0.97 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.97 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– AnyEvent::IRC::Util β€” the lil toolbox that makes IRC protocol handling not a whole crisis πŸ’–

okay bestie, so this is AnyEvent::IRC::Util, part of the User Contributed Perl Documentation situation, and it's literally just a grab bag of common utilities that help you deal with IRC protocol stuff. no cap. πŸ¦‹


✨ SYNOPSIS ✨

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

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

🌸 FUNCTIONS 🌸

these are some lil utility functions that might come in handy when you're handling the IRC protocol, and honestly? they ate. πŸ’…

you can export them like this, for example:

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

  • parse_irc_msg ($ircline) β€” this one parses the $ircline, which is one line of the IRC protocol without the trailing "\015\012". it hands you back a hash with these entries:
    • prefix β€” the message prefix. πŸŽ€
    • command β€” the IRC command.
    • params β€” the parameters to the IRC command, in an array reference. this includes the trailing parameter (the one after the ':', or the 14th parameter). periodt.
  • mk_msg ($prefix, $command, @params) β€” this function assembles an IRC message. the generated message will look like this (pseudo code, bestie, don't @ me):
:<prefix> <command> <params> :<trail>

please refer to RFC 1459 for how IRC messages normally look, iykyk.

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!

EXAMPLES:

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"
  • decode_ctcp ($data) β€” this function decodes CTCP messages that are contained in an IRC message. $data should be the last parameter of an IRC PRIVMSG or NOTICE.

it will first unescape the lower layer, extract the 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 the first element (eg. "VERSION") and the rest of the CTCP message as the second element. slay. ✨

  • encode_ctcp (@msg) β€” this function encodes a CTCP message for transmission via the NOTICE or PRIVMSG command. @msg is an array of strings or array references. if an array reference shows up in the @msg array, its first element will be interpreted as the CTCP TAG (eg. one of PING, VERSION, .. whatever honestly) and 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 (that's literally what the lowlevel quoting allows). iconic behaviour fr fr.

  • filter_colors ($line) β€” 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 a bit in some occasions. πŸ™ˆ it's giving collateral damage, bestie.
  • split_prefix ($prefix) β€” this function splits an IRC user prefix as described by RFC 2817 into three parts: nickname, user and host. which will be returned as a list, in that order.

$prefix can also be a hash like the one returned by "parse_irc_msg".

  • is_nick_prefix ($prefix) β€” returns true if the prefix is a nick prefix, containing user and host. βœ…
  • join_prefix ($nick, $user, $host) β€” joins $nick, $user and $host together to form a prefix. 🫢
  • prefix_nick ($prefix) β€” a shortcut to extract the nickname from the $prefix.

$prefix can also be a hash like the one returned by "parse_irc_msg".

  • prefix_user ($prefix) β€” a shortcut to extract the username from the $prefix.

$prefix can also be a hash like the one returned by "parse_irc_msg".

  • prefix_host ($prefix) β€” a shortcut to extract the hostname from the $prefix.

$prefix can also be a hash like the one returned by "parse_irc_msg".

  • rfc_code_to_name ($code) β€” this function is an interface to the internal mapping of numeric replies to the reply name in RFC 2812 (which you may also consult, if you're feeling scholarly πŸ“š).

$code is returned if no name for $code exists (as some servers may have extended the protocol, messy behaviour honestly).

  • 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. πŸ‘‘ genuinely the most thoughtful one in the group chat.


πŸ’œ AUTHOR πŸ’œ

Robin Redeker, "<elmex@ta-sa.org>"


🌈 SEE ALSO 🌈


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.


and that's the whole page, bestie πŸ¦‹ this was perl v5.34.0, dated 2022-06-06, from AnyEve...C::Util(3pm) β€” go forth and handle IRC protocol like the main character you are πŸ’…βœ¨

πŸ“¦ where this page comes from