Skip to content

%25define=commands block bgcolor=black color=yellow margin-right=5em margin-left=5em padding=1em overflow=auto%25

%25define=output10 block bgcolor=black color=white height=10em margin-right=5em margin-left=5em padding=1em overflow=auto%25

%25define=output block bgcolor=black color=white margin-right=5em margin-left=5em padding=1em overflow=auto%25

%25define=config block bgcolor=darkgrey color=white height=10em margin-right=5em margin-left=5em padding=1em overflow=auto%25

%25define=code block bgcolor=lightgrey color=black height=10em margin-right=5em margin-left=5em padding=1em overflow=auto%25

%25define=note block bgcolor=lightblue color=black margin-right=5em margin-left=5em padding=1em overflow=auto%25

%25define=warn block bgcolor=yellow color=black margin-right=5em margin-left=5em padding=1em overflow=auto %25

Catagories: [[!bots]], [[!perl]]

Perl Bot::BasicBot

This is a simple irc bot class you can base your bot off. It handles the basics of connecting to an irc server and channels.

[[https://metacpan.org/pod/Bot::BasicBot]]

This isn't likely the class you want to build your bot off of as it is very limited beyond the basics. Its the base class used by the next one though, so the documentation is relevant for all bots based off of it.

Perl Bot::BasicBot::Pluggable

This is the main class you will want to base your bot off of. It's based off Bot::BasicBot but also adds pluggable modules.

[[https://metacpan.org/pod/Bot::BasicBot::Pluggable]]

Installing

To create your bot, you'll need to install the perl modules. Easiest way to do this is with cpan command. This will install all the dependencies so expect it will take a while to complete and produce a lot of output. You'll need more then a coffee break; might I suggest finding a book or movie while you wait... :( I'm quite sure not all of the packages installed are needed so this could probably be optimized at some point. The output is limited to just the relevant parts of the install.

%25commands%25cpan -i Bot::BassicBot::Pluggable

%25output10%25##STARTCODEBLOCK## (...)

Building Bot-BasicBot-Pluggable

Installing /usr/local/man/man1/bot-basicbot-pluggable.1

Installing /usr/local/man/man1/bot-basicbot-pluggable-cgi.1

Installing /usr/local/libdata/perl5/site_perl/App/Bot/BasicBot/Pluggable.pm

Installing /usr/local/libdata/perl5/site_perl/App/Bot/BasicBot/Pluggable/Terminal.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Module.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Store.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Terminal.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Module/Auth.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Module/Base.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Module/ChanOp.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Module/DNS.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Module/Google.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Module/Infobot.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Module/Join.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Module/Karma.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Module/Loader.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Module/Seen.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Module/Title.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Module/Vars.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Store/DBI.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Store/Deep.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Store/Memory.pm

Installing /usr/local/libdata/perl5/site_perl/Bot/BasicBot/Pluggable/Store/Storable.pm

Installing /usr/local/libdata/perl5/site_perl/Test/Bot/BasicBot/Pluggable.pm

Installing /usr/local/libdata/perl5/site_perl/Test/Bot/BasicBot/Pluggable/Store.pm

Installing /usr/local/man/man3p/App::Bot::BasicBot::Pluggable.3p

Installing /usr/local/man/man3p/App::Bot::BasicBot::Pluggable::Terminal.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Module.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Module::Auth.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Module::ChanOp.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Module::DNS.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Module::Google.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Module::Infobot.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Store.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Module::Join.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Module::Karma.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Module::Loader.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Module::Seen.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Module::Title.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Module::Vars.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Store::DBI.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Store::Deep.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Store::Memory.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Terminal.3p

Installing /usr/local/man/man3p/Bot::BasicBot::Pluggable::Store::Storable.3p

Installing /usr/local/man/man3p/Test::Bot::BasicBot::Pluggable.3p

Installing /usr/local/man/man3p/Test::Bot::BasicBot::Pluggable::Store.3p

Installing /usr/local/bin/bot-basicbot-pluggable

Installing /usr/local/bin/bot-basicbot-pluggable-cgi

Installing /usr/local/bin/bot-basicbot-pluggable-cli

Installing /usr/local/bin/bot-basicbot-pluggable-infobot-upgrade

Installing /usr/local/bin/bot-basicbot-pluggable.rej

Installing /usr/local/bin/storable2dbi.pl

BIGPRESH/Bot-BasicBot-Pluggable-1.30.tar.gz

./Build install -- OK

Create a User

You'll want to run your bot in its own user account for security reasons.

%25commands%25##STARTCODEBLOCK##

doas useradd -m mybot

doas su - mybot

Create your bot

The code snip from the perldoc page is a good starting point for your bot. The following example connects to the ircnow network.

%25commands%25vi mybot.pl

%25code%25##STARTCODEBLOCK##

!/usr/bin/perl

use strict;

use warnings;

use Bot::BasicBot::Pluggable;

Create your bot and connect it to ircnow

my $bot = Bot::BasicBot::Pluggable->new(

channels => ["#bottest"],

server => "irc.ircnow.com",

port => "6667",

nick => "pluggabot",

alt_nicks => ["pbot", "pluggable"],

username => "bot",

name => "Yet Another Pluggable Bot",

);

print "Starting Bot\n";

$bot->run();

Save and quit with :wq, then make it executable and run it like this:

%25commands%25##STARTCODEBLOCK##

chmod +x mybot.pl

./mybot.pl

That's it# You should now see your bot in the #bottest channel if all went well. Congratulations# Unfortunately, it wont do anything more then join the channel at this point. You hit ctrl-c to stop it.

%25note%25NOTE: If the bot doesn't join the channel, it may be a firewall issue or port conflict. If you're running this on your irc server, you want to use server => "localhost" or it wont be able to connect as port 6667 is already in use for incoming traffic.

Loading Modules

To make your bot do something useful, you'll need to add some modules. We'll start with the following:

Add the following lines to your mybot.pl before the $bot->run();

%25code%25##STARTCODEBLOCK##

Load modules

my $modules=[qw{Loader Auth}];

my $mod={}

foreach (@$modules) {

$mod->{$_}=$bot->load($_);

}

print "Starting Bot\n";

$bot->run();

%25warn%25WARNING: The Auth module has a hard coded password for admin of julia. You will need to change this. See the link above for Auth for details.

You'll need to /query the bot to authenticate before you can issue commands to it. Once authenticated, you'll be able to request a list of available modules thanks to the loader module. See the doc link above for it

%25commands%25!list

%25output%25##STARTCODEBLOCK##

Loaded modules: Auth, Loader

..Available modules: ChanOp, DNS, Google, Infobot, Join, Karma, Seen, Title, Vars

The following are some of the modules available:

  • Auth - Basic authentication module. Very basic - I may write something better at some point...

  • Loader - Lets you Load/unload and list modules on the fly.

  • Join - Lets you Join/part channels on the fly.

  • Seen - Tracks when a nick was last seen.

  • Karma - tracks karma for various concepts.

  • DNS - Perform dns lookups for names and ip addresses. Usage: 'dns ' for the hostname, 'nslookup ' for the IP address.

  • Infobot - Allows users to add factoids for the bot to recall on demand. try asking it wiki? the trigger is the ? See the link for programming it.

  • Wiki - Module izzyb created to track changes on the wiki and post notices in the channels. Docs and links to code to follow. Ask izzyb on #planetofnix if you would like a copy of the code in the short term.

Catagories: [[!bots]], [[!perl]]