POE::C...asicBot(3pm)
π NAME π
POE::Component::IRC::Cookbook::BasicBot β it's literally a basic IRC bot, bestie. That's the whole vibe. π¦
β¨ SYNOPSIS β¨
Okay so picture this: it's a very basic bot. It connects to IRC, joins a few channels, and announces its arrival like the main character it is. π
π DESCRIPTION π
We start off quite simply, no drama, no cap:
#!/usr/bin/env perl
use strict;
use warnings
(ok that's the first two lines up there, keep scrolling, we're not done bestie π)
Then we use the stuff we're going toβ¦ well, use. π«Ά
::Stateis a subclass which keeps track of state information related to channels and nicknames. It is needed by theAutoJoinplugin β and that plugin is the one that takes care of keeping us on our channels. Iconic teamwork honestly. π
use POE;
use POE::Component::IRC::State;
use POE::Component::IRC::Plugin::AutoJoin;
Next up is our POE session. We create it, we list our event handlers, and then we start the POE kernel. The way that this is like three whole steps but it reads so clean?? obsessed. β¨
POE::Session->create(
package_states => [
main => [ qw(_start irc_join) ]
]
);
$poe_kernel->run();
Now all we have to do is write the handlers for _start and irc_join. π§
In _start, we:
- create our IRC component,
- add an
AutoJoinplugin, - register for the
irc_joinevent, - and connect to the IRC server.
sub _start {
my $irc = POE::Component::IRC::State->spawn(
Nick => 'basic_bot',
Server => 'irc.freenode.net',
);
$irc->plugin_add('AutoJoin', POE::Component::IRC::Plugin::AutoJoin->new(
Channels => [ '#test_channel1', '#test_channel2' ]
));
$irc->yield(register => 'join');
$irc->yield('connect');
}
Now comes our irc_join event handler. We send a message to the channel once we've joined it. Hi everybody!! πΈ
sub irc_join {
my $nick = (split /!/, $_[ARG0])[0];
my $channel = $_[ARG1];
my $irc = $_[SENDER]->get_heap();
# only send the message if we were the one joining
if ($nick eq $irc->nick_name()) {
$irc->yield(privmsg => $channel, 'Hi everybody!');
}
}
That's it! Periodt. π π₯
π AUTHOR π
Hinrik Γrn SigurΓ°sson, hinrik.sig@gmail.com β absolute legend, we stan π«Ά
okay bestie that's the whole page!! this one is perl v5.40.1, dated 2025-08-21, and it lives in the POE::C...asicBot(3pm) section of the User Contributed Perl Documentation β go forth and make your bot say hi πβ¨π¦
π¦ where this page comes from
- ubuntu resolute: libpoe-component-irc-perl 6.95+dfsg-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libpoe-component-irc-perl 6.95+dfsg-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms