Posts Tagged ‘irc’

16
Jun
16:02

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