from twisted.words.protocols import irc from twisted.internet import reactor, protocol import time, sys, os class JokBot(irc.IRCClient): '''The Jokosher IRC bot.''' nickname = 'jokbot' channel = 'cjlucas' def buildProtocol(self, addr): peer = protocol.ClientFactory.buildProtocol(self, addr) self.protoInstance = peer def connectionMade(self): irc.IRCClient.connectionMade(self) def connectionLost(self, reason): irc.IRCClient.connectionLost(self, reason) def signedOn(self): self.join(self.channel) def irc_INVITE(self, prefix, params): print prefix, params print "Invited" join(chan) def privmsg(self, user, channel, msg): print user, channel, msg '''This will get called when the bot receives a message.''' user = user.split('!', 1)[0] if channel.lower() == '#cjlucas': self.factory.peer.protoInstance.msg(channel, msg) # Check to see if they're sending me a private message # Otherwise check to see if it is a message directed at me if msg.startswith(self.nickname + ':'): self.msg(channel, '%s said %s' % (user, msg[len(self.nickname + ':'):])) return class JokBotFactory(protocol.ClientFactory): protocol = JokBot def __init__(self): pass def clientConnectionLost(self, connector, reason): connector.connect() def clientConnectionFailed(self, connector, reason): reactor.stop() if __name__ == '__main__': f = JokBotFactory() reactor.connectTCP('irc.blackened.com', 6667, f) g = JokBotFactory() reactor.connectTCP('irc.freenode.net', 6667, g) reactor.run()