IRC(3pm)
π you're reading IRC(3pm) π part 1 of 2, buckle up bestie π
π NAME π
Net::IRC β DEAD SINCE 2004 Perl interface to the Internet Relay Chat protocol
okay so. sit down. i have news. π
π¨ USE THESE INSTEAD π¨
bestie, plot twist: this module is abandoned and is no longer developed. this release literally only exists to warn current and future users about that, and to point y'all toward the libraries that are supported and actively developed for connecting Perl to IRC. no cap. π
so like, most new users are gonna want Bot::BasicBot, periodt. and the more advanced girlies will highkey appreciate the flexibility that POE::Component::IRC offers. π¦
and look β we get it, porting your code to a whole new framework is hard. genuinely. so please stop by #perl on irc.freenode.net and we'll happily help you bring your bots into the modern era. we're nice, i promise π«Ά
π SYNOPSIS π
use Net::IRC;
$irc = new Net::IRC;
$conn = $irc->newconn(Nick => 'some_nick',
Server => 'some.irc.server.com',
Port => 6667,
Ircname => 'Some witty comment.');
$irc->start;
π DESCRIPTION π
so. this module has been abandoned and deprecated since 2004. the original authors moved on to POE::Component::IRC and more modern techniques, iconic of them honestly. this distribution is not maintained and is only uploaded to present successively louder "don't use this" warnings to those who are unaware. π like, each release is just a scream. and it gets louder. π
welcome to Net::IRC, a work in progress β¨. originally it was just meant to be a quick little tool for writing an IRC script in Perl, but it has grown into a comprehensive Perl implementation of the IRC protocol (RFC 1459), developed by several members of the EFnet IRC channel #perl, and maintained in channel #net-irc. slay. π
there are 4 component modules that make up Net::IRC:
Net::IRCβ the wrapper for everything else. it's got methods to generate Connection objects (see below) plus a connection manager which runs an event loop on all the available filehandles. sockets or files that are readable (or writable, or whatever you want it to <code>select()</code> for, bestie, live your truth) get passed along to user-supplied handler subroutines in other packages or in user code. πNet::IRC::Connectionβ the big time sink on this project, fr fr. each Connection instance = a single connection to an IRC server. the module itself contains methods for every single IRC command available to users (Net::IRC isn't designed for writing servers, for obvious reasons duh), plus methods to set, retrieve, and call handler functions that the user can set (more on this later), and too many cute comments. i mean. what can i say, we were bored. πNet::IRC::Eventβ kind of a struct-like object for storing info about things the IRC server tells you (server responses, channel talk, joins and parts, et cetera). it records who initiated the event, who it affects, the event type, and any other arguments provided for that event. incidentally, it's the only argument passed to a handler function. βNet::IRC::DCCβ the analogous object to <code>Connection.pm</code> for connecting, sending and retrieving with the DCC protocol. instances of <code>DCC.pm</code> are invoked from <code>Connection->new_{send,get,chat}</code> in the same way that <code>IRC->newconn</code> invokes <code>Connection->new</code>. this will make more sense later, we promise π«Ά
okay so the central concept Net::IRC is built around is that of handlers (or hooks, or callbacks, or whatever the heck you feel like calling them, i don't gatekeep). we tried to make it a completely event-driven model, Γ la Tk β for every conceivable type of event your client might see on IRC, you can give your program a custom subroutine to call. but wait, there's more! π there are 3 levels of handler precedence:
- Default handlers β considering they're hardwired into Net::IRC, these won't do much more than the bare minimum needed to keep the client listening on the server, with an option to print (nicely formatted, of course π ) what it hears to whatever filehandles you specify (<code>STDOUT</code> by default). these get called only when the user hasn't defined any of their own handlers for this event.
- User-definable global handlers β the user can set up their own subroutines to replace the default actions for every IRC connection managed by your program. these only get invoked if the user hasn't set up a per-connection handler for the same event.
- User-definable per-connection handlers β simple: this tells a single connection what to do if it gets an event of this type. supersedes global handlers if any are defined for this event. π
and even better β you can choose to call your custom handlers before or after the default handlers instead of replacing them, if you wish. β¨ in short: it's not perfect, but it's about as good as you can get and still be documentable, given the sometimes horrendous complexity of the IRC protocol. π
πΈ GETTING STARTED πΈ
β¨ Initialization β¨
to start a Net::IRC script, you need two things: a <code>Net::IRC</code> object, and a <code>Net::IRC::Connection</code> object. the Connection object does the dirty work of connecting to the server, and the IRC object handles the input and output for it. π¦ to that end, say something like this:
use Net::IRC;
$irc = new Net::IRC;
$conn = $irc->newconn(Nick => 'some_nick',
Server => 'some.irc.server.com');
...or something similar, no pressure bestie. π acceptable parameters to <code>newconn()</code> are:
Nickβ the nickname you'll be known by on IRC, often limited to a maximum of 9 letters. acceptable characters for a nickname are[\w{}[]\^|-]`. if you don't specify a nick, it defaults to your username. πServerβ the IRC server to connect to. there are dozens of them across several widely-used IRC networks, but the oldest and most popular is EFNet (Eris Free Net), home to#perl. seehttp://www.irchelp.org/for lists of popular servers, or ask a friend. π«ΆPortβ the port to connect to this server on. by custom, the default is 6667.Usernameβ on systems not running <code>identd</code>, you can set the username for your <code>user@host</code> to anything you wish. note that some IRC servers won't allow connections from clients which don't run <code>identd</code>. πIrcnameβ a short (maybe 60 or so chars) piece of text, originally intended to display your real name, which people often use for pithy quotes and URLs. defaults to the contents of your GECOS field. β¨Passwordβ if the IRC server you're trying to write a bot for is password-protected, no problem. just say""Password =" 'foo'>"and you're set. π₯SSLβ if you wish to connect to an irc server which is using SSL, set this to a true value. i.e.:""SSL =" 1>". π
β¨ Handlers β¨
once that's over and done with, you need to set up some handlers if you want your bot to do anything more than sit on a connection and waste resources (π real). handlers are references to subroutines which get called when a specific event occurs. here's a sample handler sub:
# What to do when the bot successfully connects.
sub on_connect {
my $self = shift;
print "Joining #IRC.pm...";
$self->join("#IRC.pm");
$self->privmsg("#IRC.pm", "Hi there.");
}
the arguments to a handler function are always the same:
$_[0]: β the Connection object that's calling it.$_[1]: β an Event object (see below) that describes what the handler is responding to.
got it? if not, see the examples in the <code>irctest</code> script that came with this distribution. π anyhow, once you've defined your handler subroutines, you need to add them to the list of handlers as either a global handler (affects all Connection objects) or a local handler (affects only a single Connection). to do so, say something along these lines:
$self->add_global_handler('376', \&on_connect); # global
$self->add_handler('msg', \&on_msg); # local
376, incidentally, is the server number for "end of MOTD", which is an event that the server sends to you after you're connected. see <code>Event.pm</code> for a list of all possible numeric codes. the <code>'msg'</code> event gets called whenever someone else on IRC sends your client a private message. π for a big list of possible events, see the Event List section in the documentation for <code>Net::IRC::Event</code>. β
β¨ Getting Connected β¨
when you've set up all your handlers, the following command will put your program in an infinite loop, grabbing input from all open connections and passing it off to the proper handlers:
$irc->start;
note that new connections can be added and old ones dropped from within your handlers even after you call this. just don't expect any code below the call to <code>start()</code> to ever get executed. π like. ever. rest in peace to that code i guess.
if you're tying Net::IRC into another event-based module, such as perl/Tk, there's a nifty <code>do_one_loop()</code> method provided for your convenience π«Ά. calling <code>$irc->do_one_loop()</code> runs through the <code>IRC.pm</code> event loop once, hands all ready filehandles over to the appropriate handler subs, then returns control to your program. slay. π
π to be continued, bestie π¦
β¨ METHOD DESCRIPTIONS β¨
okay so this section is literally only about the methods that live in IRC.pm itself, bestie. The method lists for Net::IRC::Connection, Net::IRC::Event, or Net::IRC::DCC live in their own modules' docs β just run perldoc Net::IRC::Connection (or Event or DCC or whatever) and read them there. Functions take no arguments unless their description says otherwise. π«Ά
Also, heads up: expect Net::IRC to use AutoLoader sometime in the future, once it becomes a little more stable. manifesting that glow-up β¨
addconn()β adds the specified object's socket to the select loop indo_one_loop(). This is mostly for the use ofConnectionandDCCobjects (and for pre-0.5 compatibility)... for most (read: all) purposes, you can just useaddfh(), described below.
Takes at least 1 arg:
- An object whose socket needs to be added to the select loop
- Optional: A string consisting of one or more of the letters
r,w, ande. Passed directly toaddfh()... see the description below for more info.
addfh()β this sub takes a user's socket or filehandle and a sub to handle it with and merges it intodo_one_loop()'s list ofselect()able filehandles. This makes integration with other event-based systems (Tk, for instance) a good deal easier than in previous releases. iconic behavior, fr fr
Takes at least 2 args:
- A socket or filehandle to monitor
- A reference to a subroutine. When
select()determines that the filehandle is ready, it passes the filehandle to this (presumably user-supplied) sub, where you can read from it, write to it, etc. as your script sees fit. - Optional: A string containing any combination of the letters
r,wore(standing for read, write, and error, respectively) which determines what conditions you're expecting on that filehandle. For example, this lineselect()s$fh(a filehandle, of course) for both reading and writing:
$irc->addfh( $fh, \&callback, "rw" );
do_one_loop()βselect()s on all open filehandles and passes any ready ones to the appropriate handler subroutines. Also responsible for executing scheduled events fromNet::IRC::Connection->schedule()on time. β° on time, bestienew()β a fairly vanilla constructor which creates and returns a newNet::IRCobject.newconn()β creates and returns a newConnectionobject. All arguments are passed straight toNet::IRC::Connection->new(); examples of common arguments can be found in the Synopsis or Getting Started sections.removeconn()β removes the specified object's socket fromdo_one_loop()'s list ofselect()able filehandles. This is mostly for the use ofConnectionandDCCobjects (and for pre-0.5 compatibility)... for most (read: all) purposes, you can just useremovefh(), described below.
Takes 1 arg:
- An object whose socket or filehandle needs to be removed from the select loop
removefh()β this method removes a given filehandle fromdo_one_loop()'s list of selectable filehandles.
Takes 1 arg:
- A socket or filehandle to remove
start()β starts an infinite event loop which repeatedly callsdo_one_loop()to read new events from all open connections and pass them off to any applicable handlers. infinite loop era πtimeout()β sets or returns the currentselect()timeout for the main event loop, in seconds (fractional amounts allowed). See the documentation for theselect()function for more info.
Takes 1 optional arg:
- Optional: A new value for the
select()timeout for this IRC object.
flush_output_queue()β flushes any waiting messages in the output queue if pacing is enabled. This method will not return until the output queue is empty. π
π AUTHORS π
shoutout to the absolute legends:
- Conceived and initially developed by Greg Bacon
<gbacon@adtran.com>and Dennis Taylor<dennis@funkplanet.com>. π - Ideas and large amounts of code donated by Nat "King" Torkington
<gnat@frii.com>. π - Currently being hacked on, hacked up, and worked over by the members of the Net::IRC developers mailing list. For details, see
http://www.execpc.com/~corbeau/irc/list.html. π
π URL π
Up-to-date source and information about the Net::IRC project can be found at http://www.sourceforge.net/projects/net-irc/ . go peek, bestie β¨
πΈ SEE ALSO πΈ
perl(1).RFC 1459: The Internet Relay Chat Protocolhttp://www.irchelp.org/, home of fine IRC resources.
π and that's a wrap, bestie! this page is perl v5.36.0, dated 2022-10-15, and it's IRC(3pm). periodt β¨
π¦ where this page comes from
- ubuntu noble: libnet-irc-perl 0.79-4 Β· Artistic-1.0-Perl
- ubuntu resolute: libnet-irc-perl 0.79-4 Β· Artistic-1.0-Perl
- ubuntu stonking: libnet-irc-perl 0.79-4 Β· Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms