My speech bot, using irclib.py

Okay, revamped the basic idea, now using the irclib, which in spite of a lack of documentation, actually proved to be pretty easy to use. You should be able to figure out what it does, and modify it to use your own nicks and channel.

[sourcecode lang=”python”]
#!/usr/bin/env python

import sys
import os
import optparse
import irclib

network = "irc.freenode.net"
port = 6667
channel = "#somechannel"
nick = "SomeNick"
name = "SomeNick is a bot."

irc = irclib.IRC()
server = irc.server()
server.connect(network, port, nick, ircname = name)
server.join(channel)

lastspeaker = None

def handlePubMessage(connection, event):
global lastspeaker
target = event.target()
speaker = event.source().split(‘!’)[0]
msg = event.arguments()[0]
print target, ">", speaker, ":", msg
p = os.popen("festival –tts", "w")
if speaker != lastspeaker:
p.write(speaker + " says ")
p.write(msg)
p.close()
lastspeaker = speaker

irc.add_global_handler(‘pubmsg’, handlePubMessage)

irc.process_forever()
[/sourcecode]