from twisted.internet.protocol import Factory from twisted.protocols.basic import LineReceiver from twisted.internet import reactor class IRC(LineReceiver): def connectionMade(self): print "yay" class Boo(LineReceiver): def __init__(self): self.supportAnsi = 0 self.state = 0 def connectionMade(self): self.sendLine("Welcome.") self.sendLine("Does your terminal support ANSI Colors? Please answer \"Yes\" or \"No\"") def lineReceived(self,line): if self.state == 0: temp = line.lower() if temp == "no" or temp == "yes": if temp == "no": self.supportAnsi = 0 elif temp == "yes": self.supportAnsi = 1 self.sendLine("Ok. which server would you like to join?") self.state = 1 else: self.sendLine("Does your terminal support ANSI Colors? Please answer \"Yes\" or \"No\"") elif self.state == 1: reactor.connectTCP("127.0.0.1",6667,IRCFag()) class IRCFag(Factory): protocol = IRC class CLFag(Factory): protocol = Boo reactor.listenTCP(8007, CLFag()) reactor.run()