IRC Guide: Making a Bot

Making a Bot

IRC Guide: Making a Bot

Hello fellow Nullbytiens, I'm Washu, a long time commenter but first time poster. Today we'll be making an IRC bot, if you haven't seen OTW's post about the new IRC channel I would encourage you to go check it out. He does a good job at explaining what IRC is and how to get set up.

So what is a IRC bot? A IRC bot is essentially a user on an IRC channel that monitors the channel and responds to certain events. For example, if the bot is triggered by the word "command" when a user enters ".command" it will trigger a command that can do anything you wish.

Downloading

For this project we will be using the Sopel framework, this will allows us to quickly make a powerful and useful python bot. Since this bot is written in python I recommend The Defalt's guide on How to Train your Python. A great guide that will help you with any python problem.

So first we have to download and install Sopel. If we look on their main page it links us to the install instruction. Its simple, we just have to do sudo pip install sopel. So lets try it:

Alright looks good.

Great, everything seemingly works! As you may have noticed I'm running Kali 2.0 so you may have different errors depending on your OS. The next step is to run the initial install. To do that simple run sopel

Oops, a friendly reminder from the developers that you shouldn't run anything that doesn't need it with root privilege ;) Lets try again with a user account.

Warning When I did this for the on Kali 2.0 it gave me a bunch of errors about creating the config file during setup, the same issue as this. I don't have a screenshot but to fix it I had to do a couple of things.

  1. Uninstall the current Sopel with sudo pip uninstall sopel
  2. Once that is done we need to download the git from git hub with git clone git://github.com/sopel-irc/sopel.git

Note: sopel requires Python 2.7.x or Python 3.3+ to run

  1. If you using python 2.7 you must install an additional dependency with pip install backports.ssl_match_hostname
  2. Then, from within the directory of the download, run python setup.py install

Now your installation should work correctly and you can continue on with the setup.

Configuration

So lets try it again with a non-root account

Great! It works and allows us to configure our bot. When it ask you about the server to connect to put in chat.freenode.net, when it ask you about the channel enter #nullbyte. Everything else can be left as the default and it will work. If at any time you want to change anything the config file is located at /home/user/.sopel/default.cfg

Your bot should automatically connect and if everything goes as plan its name should appear in the user list at #nullbyte.

Now that your bot is working it can accept command. The first command to try is .help. This will give you a list of all command that can be used out of the box, a full list is also available here.

Some fun command to try out at first:

  • .g - Query Google for a word
  • .wiki - Search Wikipedia for an article
  • .calc - Calculate an equation
  • .tr - Translate a language to English

There are many more built in commands and modules and I leave it up to discover them all.

Above and Beyond

Now I know that we didn't really make anything ourselves yet but that's for the next tutorial. We will learn how to make our own modules and custom command, but if your are very keen to get your bot customized right away I encourage you to head over to the Sopel tutorials to start learning. Its very easy and extendable and maybe you can even submit your modules to the project :)

Last thing I want to say is don't spam! If you put your bot on the channel, please test it from within a private chat, so that there is not to much spam on the IRC.

Hope everyone has fun and hopefully we'll be seeing lots of bots around the IRC channel.

Cheers,
Washu

16 Comments

Great tutorial and excellent topic, looking forward to read the next one! :)

Thanks, It will be up soon :)
Cheers,
Washu

I was wondering about the "WashuBot" that logged in. Nice!

I will probably join the IRC channel tomorrow. Haven't gotten the chance to build up a safe connection to the IRC channel yet.

-Phoenix750

Every time I see someone connect and their full IP is revealed I cringe a little xD
Cheers,
Washu

Thanks for the post, have been wondering about bots for the longest time. Noob question if you don't mind. I connected to an IRC a couple months back via my cell phone not knowing what I was doing, (that is why I'm here) and I'm sure my full IP was revealed. I was connected to my home wifi with a few other devices connected as well. Question how can I fix that major mistake? Changed all the passwords on ALL devices but what else should I do? Thanks again for the help.

NANO_GRUNT

Honestly once its out there there isn't really a way to take it back. If you changed all your passwords then it should be good. You can also unplug your router for 10 mins and it might change your IP so then yo should be good. Also next time make sure your get a cloak and go through a proxy.

Cheers,
Washu

How busy is the IRC channel on an average, actually?

-Phoenix750

On average there 15-25 right now.

Cheers,
Washu

I always connect to IRC with a SOCKS5 proxy, and I advise everyone else to do the same. Even if it is not an anonymous proxy, the point is to protect yourself from IRC users who know that you are connected and can target you (for whatever reason).

TRT

Very good tip :)
Cheers,
Washu

Not sure about Kali, but in most GNU/Linux boxes you can just install ircd and do all your test locally. Do not forget to remove it from the start up script or it will be up every time you reboot.

Good tutorial.
cheers

P.S.: If anybody wants to know what is going on under the hood, take a look here.

This is one I wrote many years ago. It connects posts the time, quits, waits 5 minutes and so on... Very basic example, and also pretty useless. I'm not even sure if it still works.

#!/bin/sh
while (true) do
THE_TIME='date +%H:%M'
cat << EOM | nc irc-server 6667
USER TimeBot 0 * :I'm the Bot that knows what time is it
NICK TimeBot
JOIN #your-channel
PRIVMSG #your-channel : It's $THE_TIME
QUIT
EOM
sleep 300
done;

Very interesting, thanks. That's a great link for people that want to get their hand dirty with all things IRC.

Cheers,
Wahsu

To display literal characters (* and _) without affecting formatting, type them twice.

TRT

Thanks a lot TRT. Very good tip

any idea how to change the bot from accepting the period ( . ) as the starting command, twitch thinks this is a command and just gives an error

Share Your Thoughts

  • Hot
  • Latest