def getsentence(self, msg): brain.add_to_brain(msg, self.factory.chain_length, write_to_file=True) sentence = brain.generate_sentence(msg, self.factory.chain_length, self.factory.max_words) if sentence: return sentence else: return msg
config.read("twitter.config") self.channel = channel self.nickname = nickname self.chain_length = chain_length self.chattiness = chattiness self.max_words = max_words self.api = twitter.Api(config.get('OAuth','consumer_key'), config.get('OAuth','consumer_secret'), config.get('OAuth','access_token_key'), config.get('OAuth', 'access_token_secret')) def clientConnectionLost(self, connector, reason): print "Lost connection "+str(reason)+", reconnection" connector.connect() def clientConnectionFailed(self, connector, reason): print "Could not connect: "+str(reason) if __name__ == "__main__": chan = "" chain_length = 2 try: chan = sys.argv[1] except IndexError: print "You need a channel name" if os.path.exists('training_text.txt'): f = open('training_text.txt', 'r') for line in f: brain.add_to_brain(line.upper(), chain_length) print "brain loaded" f.close() reactor.connectTCP("irc.freenode.net", 6667, twistedBotFactory("#"+chan, 'lessthanthree', 2, chattiness=0.05)) reactor.run()