Progbot: A progressive IRC Bot
One of my favorite hobbies, is writing automated bots. I can still remember my first IRC bot in Perl. It’s actually made for fun, and of course there are some exceptional capabilities. I worked with many people before, and once, we coded a multi-threaded IRC bot just to scan SQL Injection vulnerabilities. Yes, I wish I still have that code.
Progbot
I decided to write a python IRC bot. And since I’m very open to OOP nowadays, I made a class for it. The main feature of the bot is progressive learning. It learns from other people.
I’m not yet finished, and the code is still under development. And because I love writing these kind of projects, I will continue developing Progbot, and become progressive to it as well. More features will be added, and less errors.
For now, the code is dynamically capable of responding to messages. Unlike before, I still need to change the code if I want my bot to respond to some string. Now, I can just edit a text file, and save it. I do not need to re-run the script, so more time is saved. I created a file called responses.txt and if I want Progbot to respond to Hi! with a hello, I will just add:
Hello! ~ S ~ Hi!
And here’s what responses.txt looks like:
# This is the responses file. If a line has a pound (#) symbol at front, the line is ignored. # # The syntax for this file is: # match string ~ [S|A|R] ~ string # # S - PRIVMSG String # A - ACTION String # R - RAW String # # NOTE: Progbot won't recognize any RAW conditions unless the source is the defined owner # # Example: # Hi! ~ S ~ Hello! # - Whenever you say 'Hi!', Progbot says 'Hello!' back. # # Special Variables: # %nick% - Source nick # %bnick% - Bot nick # %source% - Source Medium # %m% - String Match # %bnick% ~ S ~ Sup %nick%? sup ~ S ~ sup your face. slap me ~ A ~ slaps %nick% # Channel commands !j %m% ~ R ~ JOIN :#%m% !p %m% ~ R ~ PART #%m% !p ~ R ~ PART %source%
The syntax is kinda simple, strings are separated by ~ . If you have a better suggestion, please comment. There are 3 types of response, a normal message, an action, and a raw IRC command. Raw IRC commands are only recognized if the source nick is the owner of the bot. There are also variables in this file, and you can even match strings and such.
Usage
Progbot’s initializer accepts five parameters. An example looks like:
#!/usr/bin/python ''' Main file, Progbot's implementation. Most of Progbot's functions are found on the class. So this is pretty self-explanatory. ''' from progbot import Progbot def main(): ''' I want to connect to irc.rizon.net, with the following options: ''' ircNick = 'Progbot' ircServ = 'irc.rizon.net' ircPort = '6667' ircChan = '#Progbot' ircOwner = 'Ruel' fileName = 'responses.txt' bot = Progbot(ircNick, ircServ, ircPort, ircChan, ircOwner) bot.File = fileName bot.Connect(True); if __name__ == '__main__': main()
Source Code
The source code is released under GNU GPL v3, and is available here.
NOTE: I’m open for suggestions and forks!