Posts Tagged ‘python’

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

31
May
14:49

I’m a spoiled ass who likes Python

Recently I’ve started developing dicey for some RPGs over IRC. I started with little knowledge of python and the IRC protocol, but actually went as far as to develop a pretty robust and feature-packed bot.

I think I have at least some experience with about every language out there. I’m a shitty coder for the most part because I just don’t have the patience, but I at least take a look at them. The basic syntax, their features, just out of general interest.

I’ve been a long time fan of python, but never really used it to this degree until now. My projects were mostly boring stuff like a BF interpreter and scripts here and there to do repetitive tasks. Never a bot.

I started by googling code samples of using IRC in python. Not long after I found a very basic implementation that would just connect, ping back when asked to and print the raw output.

One thing about IRC, it’s a wonderful protocol. You hardly even need a client for most of it. It’s ancient and missing some things, but I can willingly overlook that.

(Dicey will be released eventually.)