Analog5:Article 005
From Hak5
Setting up an IRC Bot
By: TechCentric-Nick
Published: January 20th, 2007
Introduction
Setting up IRC bots nowadays isn't the hassle it used to be. Early on, you had to be able to code a bot from scratch, including adding in support for anything and everything you wanted to do. Now, there are several excellent bot frameworks to base bots off of, limiting the amount of work to be done while maximizing its power and capabilities, and streamlining it into nearly a 1-2-3 process. The point of this article is to walk a newbie user through setting up an IRC bot with the goal of adding external capabilities to it in the future.
We're going to be using Eggdrop in the tutorial, as it is by far the most common framework.
Prerequisites
Now, Eggdrop is first and foremost a Unix-based bot. While some people have success using Cygwin and other tools to run it under other operating systems, it would be recommended that for the sake of this tutorial you have a Unix shell account or a local Unix box to be practicing and/or running the bot from.
For the purposes of this demonstration, I will be demonstrating using an i686 machine running Debian, commonly known to most as PhreakBox. ;)
Whatever you're using, you're also going to need the following applications: tar, gzip, and gcc. I can't explicitly say how to get them because there are too many variables involved like distro and installation conditions, but check with any repositories your distribution may have if the tools aren't installed by default, or substitute others where necessary.
Getting the Bot Up
Now, logged into your shell space, download (or upload, if you're moving the package from another machine) the Eggdrop source package from Eggheads.org to the machine.
nick@phreakbox:~/analogbot$ wget ftp://ftp.eggheads.org/pub/ eggdrop/source/1.6/eggdrop1.6.18.tar.gz [NOTE: This is all on one line wih no spaces]
Once this is done, the natural next step would be to extract the files from the tarball. How do we do that?
nick@phreakbox:~/analogbot$ tar xzf eggdrop1.6.18.tar.gz
(At this point, the tarball is no longer required, so you can delete it if you want, or keep it so you don't have to re-download in case something happens.)
Your tarball probably extracted into a subdirectory, so cd into that directory and make sure you see something along these lines:
nick@phreakbox:~/analogbot/eggdrop1.6.18$ ls aclocal.m4 configure.ac doc INSTALL Makefile.in scripts ChangeLog CONTENTS eggdrop.conf language misc src config.h.in COPYING FEATURES logs NEWS text configure disabled_modules help Makefile README
The next step in prepping your bot for use is configuring your compile. Do this by running ./configure at your shell prompt. You should see a crapload of status lines and stuff fly by, and it can take a while to run through. The best advice at this point is to get up and pour yourself a drink.
Assuming all went well, you should be ready to compile Eggdrop. If something went wrong, the configure script will let you know, and using this information you can seek help out.
In this test case, everything worked out fine. So, we can now run make.
If you're anticipating everything to work out alright, you can kill two birds with one stone as I do below. If you're new to this or think you may run into a problem...separate the commands and run them separately. Note that this is not recommended, and definitely not common practice, and should be done with caution.
nick@phreakbox:~/analogbot/eggdrop1.6.18$ make config && mak e && make install [NOTE: This is all on one line wih no spaces]
Again, your compile might take upwards of several minutes. If you're already in need of a refill on that drink you just got, you should probably go get it now. You will probably see a few warning messages mixed in; this is normal, and everything will sort itself out. If there's anything that really ends up a problem, you'll be notified and it won't compile any further.
Once compiling is completed, give your Eggdrop a test run. Go ahead.
nick@phreakbox:~/analogbot/eggdrop1.6.18$ ./eggdrop Eggdrop v1.6.18 (C) 1997 Robey Pointer (C) 2006 Eggheads [15:13] --- Loading eggdrop v1.6.18 (Mon Jan 1 2007) [15:13] * Please make sure you edit your config file completely.
Wait a minute, why did I just have you do that if we're not done configuring? This was simply to test that your compiled copy was working. Assuming you saw that...you're in business. If not, try recompiling, try deleting everything and redoing this tutorial from scratch. Failing that, ask for help, and if nobody helps you (not my problem), you might as well call yourself an emo and play in traffic.
Configuring Your Bot
Now we can go through and edit your configuration file for getting the botonline. Open up your favorite text editor, be it Kate, Pico/Nano, Vi, Emacs, or whatever you have, and open up eggdrop.conf.
The first line, which looks like a CGI shebang line, is a request for you to fill in the complete path to your bot. I'd show it, but some idiot is bound to use my path in their script and then complain that it doesn't work (and it would also be a potential security hazard, something I won't have). I'm not interested in people doing that, so I'll make it fair; everyone has to punch in their own. Can't figure it out? That's what the pwd command at the shell is for.
Lines beginning with a hash mark ( # ) are comments. They are scattered throughout the file to explain different parts of the configuration to you, and can be useful if you want to leave yourself some extra hints along the way. Of course, the configuration file says that itself, but it's worth mentioning because I don't want to have to baby everyone in setting their bots up.
Basic Configuration
Scrolling through your configuration file, the first line beginning with 'set' is where we need to start. 'set username' sets the username that appears in the IRC bot's hostmask. If you want to leave it at the default (not recommended), you can, but it would be wise to change it. Right below it is the admin line; fill that with your information following the pattern outlined in the default.
I believe it is safe to assume you're not going to be networking your bots anytime soon, so we can safely leave the next set line alone. You can set the timezone if you want to, but it's not required (only useful for logging and some scripts, which we will get to momentarily).
Most home machines will have one IP to bind to, so you can scroll down past that too. (In my case, I have to configure it.) However, you probably also noticed that some of the configuration options at this point are commented too. Keep that in mind as you scroll through the file, and notice that if you want to change some of the settings as you scroll through the file.
The next two major points of interest are 'set userfile' and 'set pidfile' (and further down, 'set chanfile'). These can be left alone if you're on a single-user machine, but if you have the remote chance of being on a shared machine (most likely for shell accounts or anything that isn't a personal box), change them to something unique, perhaps 'pid.yourname' for clarity.
Now, Eggdrop features some special options as well, such as administration through DCC and telnet. I just want to take the time to point out that if you screw up configuring these, they can be a potential security hazard. Read all the comments before you make choices, and NEVER KEEP DEFAULT SETTINGS!
Continuing on, 'set owner' is remarked but required. Unremark it (remove the #), and set it to your IRC nickname. In the Channel section, read the comments about how to set up your bot to join channels, and make sure when you set modes for each channel you keep in mind what they do.
'set nick' and 'set altnick' define the bot's IRC nickname, set these to whatever you want. Change 'set realname' while you're at it too; this is a tipoff of a poorly configured bot.
Setting servers up is self-explanatory; just follow the patterns provided. Keep in mind that if you leave these set to defaults, you might be wondering why your bot doesn't show up in your channel.
For the sake of keeping this article short, I won't continue with configuration settings; the comments above them do a well-enough job of helping you decide what to set them to, follow those and use common sense. Just keep in mind that there are two "kill lines" embedded in the configuration file; these begin with 'die' and are placed to make you read through it. Remark them or delete the line. (Remember how the bot died when we tried starting it after we compiled it, and how it said we needed to edit the configuration file? It was one of the "kill lines" that did that...not the bot application itself.) Oh, and 'set modpath' should probably be set to null because you compiled this fresh - but it depends on how you set things up, again.
Getting Online
Once the bot is configured (try a test run again, only this time the bot should be saying something along the lines of "User File Not Found". If so, good, run './eggdrop -mn'. If not, go fix your configuration file; Eggdrop is nice enough to point out the problem for you.
Back on IRC, go to the channel where the bot is set up to go to, and wait for it to appear. When it does, send a private message to it with 'hello' (or if you changed it, the new keyword) so it recognizes you. In the console window, you should see a line like the following appear as you get some PMs and notices from the bot:
[16:03] Bot installation complete, first master is <yournamehere>
Respond to the PMs using the commands the bot gives, such as setting a user password.
Congratulations, the bot is now set up. Send a SigKill to the bot, and start it with just ./eggdrop. It should join back to the channel.
Conclusion
Congratulations, by now you've succeeded in setting up an IRC bot. In future articles, we can discuss adding new capabilities to your bot to make it useful. But for now, bask in your success, go get (yet another) refill of your drink of choice, and stare at the bot in your channel's userlist.
Final Disclaimer
I'm installing Eggdrop 1.6.18, the most recent release at the time of writing. These steps may differ as new versions are released, and may not match your individual setup. I'm not responsible.


