Chatbot (HexChat)


The !help listing you are sent by IRC 'notify' when you request help from the bot. It lists all of the possible options and instructs somewhat in their use. There is a rude word which I have censored just in case, but we all know what it says.

An example of the static link that the bot generates and sends when a cat is requested. Rather than link to the original url which accesses a random image every time someone accesses it. An example showing the difference in link between requests, as well as the spam limiter function


I’ve always been interested in extending my various IRC clients (originally mIRC but now HexChat because inter-OS compatability), and my first big project was a channel greeter which had various safeguards and custom messages and such.
So when someone in a channel I frequent said “Wouldn’t it be great if I could mention that I was sad and you’d link me a cat picture?!”, I thought to myself… “You know… That WOULD be great!”.
And thus was my chatbot born.

Originally named catBot, all it did was respond to the word ‘sad’ and the word ‘cat’. It did this by first testing the message for a leading ‘!’, and then if found, searching the string (using Python’s excellent string searching capabilities) for either of the phrases. It was only because of Python in-fact, that I was able to set up the bot to react to natural speech in a reasonably intuitive and accurate manner instead of rigid and highly specific commands, though as I have recently discovered, I may need to sacrifice this ability in order to broaden it’s capabilities.

The main breakthroughs were of course finding The Cat API which allowed me to randomise the cat picture, and figuring out how to use the randomisation link to pre-generate a static link to a particular picture to link to in the chat, so that everyone saw the same random image as everyone else.
Discovering that The Cat API also allowed me to specify what file format I wanted the picture to be allowed me to further refine the bot to be able to respond appropriately to the words ‘pic’ and ‘gif’, also in natural language (so ‘!Gimme a gif of a cat’ and ‘!I want a cat gif’ work just the same).

I also implemented a spam limiter for my features which denies requests for said features that are repeated too frequently. This also necessitated a spam limiter for the denial so that THAT wasn’t spammed either. The amount of time is (of course) variable, as is the initial delay (which prevents the bot being triggered by the IRC server re-playing recent lines of chat history to newly joining clients, which is a handy thing that you can tell it to do).

Of course, once I’d gone that far, it was inevitable that I’d want to start adding things.
And adding things.
And adding things.

It has now reached the stage of having 20 top-level features, some I use on a daily basis, some are kinda handy, some are there for fun, and some are specifically targeted at annoying people who request porn.
Along the way, I was forced to almost completely re-write the program to modularise it enough that adding new features wasn’t a giant messy pain.

It still lacks several features I would like such as the ability to arbitrarily chain conditions for triggers “This word AND that word OR this word” and such, as well as the ability to run on a server and be ‘always-on’, but I fear that adding these features would require my re-writing it yet again in a different language, so I have put it off.

For anyone interested in my development process, or the path that it took with this project in particular, or even want to just read the code and see what it does and how it works… You can do so over on my BitBucket account.