def __init__(self, irc_address, nick): 5. self.socket = socket.socket() 6. self.socket.connect(irc_address) 7. self.register_user(nick) 8. self.nick = nick 9. 10. def send_command(self, cmd): 11. cmd += '\r\n' 12. self.socket.send(cmd.encode('utf8')) 13. 14. def receive_command(self): 15. msg = self.socket.recv(4096) 16. msg=msg.decode('utf8', errors='ignore') 17. self.answer_ping(msg) 18. return msg 19. def register_user(self, nick): 20. self.send_command('NICK ' + nick) 21. self.send_command('USER {0} {0} {0} :{0}'.format(nick)) 22. 23. def answer_ping(self, msg): 24. match = re.match(PING :(.*)', msg) 25. if match: 26. pong = match.group(1) 27. self.send_command('PONG :' + pong) 38