def receive(self): ''' Retrieves and parses incoming socket data. Invokes the event callback of the pyric object, pyric.event(e), when new events are received. ''' try: self.buffr += str(self.pyric.irc.recv(2048), 'UTF-8') except: traceback.print_stack() self.pyric.log.error(( "net-error", "could not read data correctly from irc server" )) data = self.buffr.split('\n') # data which is not terminated by newline will be kept in buffer self.buffr = data.pop() for line in data: try: eventdata = parse(line.rstrip(), 'dict') e = Event(eventdata) self.pyric.event(e) except: traceback.print_stack() self.pyric.log.error(( "parse-error", "could not parse received data correctly" ))
def listen(sock, queue, nick, channel, operator): """Listen to the IRC output.""" join_channel = True buff = "" while run: messages = sock.recv(4096).split("\r\n") for msg in messages[:-1]: if buff != "": msg = buff + msg parsed = ircparser.parse(msg, output='object') handle_parsed(parsed, sock, queue, nick, channel, operator) if join_channel: if "451" in msg or "NOTICE AUTH" in msg: sock.send("NICK {0}\r\n".format(nick)) sock.send("USER slightCIb 0 * :slightCIb\r\n") sock.send("JOIN :{0}\r\n".format(channel)) if "JOIN :{0}".format(channel) in msg: join_channel = False buff = messages[-1:][0]