16
Jun
16:02 2009

bot.py, the python IRC bot toolkit

This is a quick post, I’ve not got exactly all the time I want to have, but I’m very eager to show this one to the world as a useful GPL program.

bot.py is an IRC bot toolkit for python. It’s really quite simple. You:

  1. Import it.
    import bot
  2. Initialize a new bot object
    a = bot.bot(master="yourname", channels=["#somechan"], nick="foobar")
  3. Register events
    irc.register(check_func, act_func)
    Where check_func is a function that receives the sender, arguments of the IRC command and the text of it. Also, it’s possible to set the evtype= argument to act on other commands (e.g. NICK, QUIT, etc.)
  4. Connect and run
    a.connect("server.com", 6667)
    a.start()

Protip: a.send(a) will send a to the server. For instance:
a.send(b'PRIVMSG #channel :Hello!')
will send “Hello!” to #channel. Or whatever other command you like.

Yes, you need to know the IRC protocol, a bit. The rest should be fairly obvious, if not, contact me. Also, contact me with improvements and I will gladly add them!

NB: This is for Python 3
Download bot.py

4 comments

  1. Reply

    Cool Thanks for your article. I am just starting python and this will help a lot.

  2. Reply

    Show us how to make it join channels and how to do a simple “Hello IRC” command.

  3. Reply

    I like what you did, it’s feel like simple and clean, like python !

Leave a Reply

This is your chance to voice your opinion! Type it down below and submit it. As long as it's not abusive, rude or annoying it will likely be approved.

Avatars are generated by the gravatar service and are based on your email address. To change them, head to gravatar.com and register.

The following tags are allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>