def connect(self): print notify('i','m',"Connecting to %s on port %d..."%(SERVER,PORT)) sock = self.sock sock.connect((SERVER,PORT)) if self.password: sock.send("PASS %s\r\n"%self.password) sock.send("NICK %s\r\n"%self.nick) sock.send("USER %s %s * :%s\r\n"%(self.nick,SERVER,self.nick)) sock.send("JOIN %s\r\n"%ROOM)
def connect(self): print notify('i', 'm', "Connecting to %s on port %d..." % (SERVER, PORT)) sock = self.sock sock.connect((SERVER, PORT)) if self.password: sock.send("PASS %s\r\n" % self.password) sock.send("NICK %s\r\n" % self.nick) sock.send("USER %s %s * :%s\r\n" % (self.nick, SERVER, self.nick)) sock.send("JOIN %s\r\n" % ROOM)
def main(client_maker): ''' pass a function that constructs a client (subclass of ChatClient)''' c = client_maker() c.connect() try: c.loop(1) except SASLAuthenticationFailed: print notify('!','r',"Authentication failed. Try again.") return True except KeyboardInterrupt: print "Disconnecting..." c.disconnect() return False
def message_received(self,frm,body): print colorize('k',frm+':'),body if self.log: self.write_log(frm,body) msg = None cmd_match = re.match("(?:%s\s*[:,;:->]+\s*|!)(\w+)"%self.name,body) if cmd_match: cmd_name = cmd_match.group(1).lower() if cmd_name in self.commands: cmd = self.commands[cmd_name] try: msg = cmd(self,frm,body) except Exception, e: print notify('!','r',"Error processing command: "+cmd_name) print e
def message_received(self, frm, body): print colorize('k', frm + ':'), body if self.log: self.write_log(frm, body) msg = None cmd_match = re.match("(?:%s\s*[:,;:->]+\s*|!)(\w+)" % self.name, body) if cmd_match: cmd_name = cmd_match.group(1).lower() if cmd_name in self.commands: cmd = self.commands[cmd_name] try: msg = cmd(self, frm, body) except Exception, e: print notify('!', 'r', "Error processing command: " + cmd_name) print e
def mode(self,frm,usr,msg): print notify('i','m',"%s sets mode: %s"%(usr,msg))
def quit(self,frm,msg): print notify('i','m',frm+' '+msg)
def part(self,frm,channel): print notify('i','m',frm+' left '+channel)
def join(self,frm,channel): print notify('i','m',frm+' joined '+channel)
def notice(self,frm,to,msg): print notify('i','m',"Notice to %s: %s"%(to,msg))
def mode(self, frm, usr, msg): print notify('i', 'm', "%s sets mode: %s" % (usr, msg))
def quit(self, frm, msg): print notify('i', 'm', frm + ' ' + msg)
def part(self, frm, channel): print notify('i', 'm', frm + ' left ' + channel)
def join(self, frm, channel): print notify('i', 'm', frm + ' joined ' + channel)
def notice(self, frm, to, msg): print notify('i', 'm', "Notice to %s: %s" % (to, msg))