def longPoll(self, count=50): """Receive a list of operations that have to be processed by original Line cleint. :param count: number of operations to get from :returns: a generator which returns operations >>> for op in client.longPoll(): sender = op[0] receiver = op[1] message = op[2] print "%s->%s : %s" % (sender, receiver, message) """ if self._check_auth(): """Check is there any operations from LINE server""" OT = OperationType try: operations = self._fetchOperations(self.revision, count) except EOFError: return except TalkException as e: if e.code == 9: self.raise_error("user logged in to another machien") else: return for operation in operations: if operation.type == OT.END_OF_OPERATION: pass elif operation.type == OT.SEND_MESSAGE: pass elif operation.type == OT.RECEIVE_MESSAGE: message = LineMessage(self, operation.message) raw_sender = operation.message._from raw_receiver = operation.message.to sender = self.getContactOrRoomOrGroupById(raw_sender) receiver = self.getContactOrRoomOrGroupById(raw_receiver) if sender is None or receiver is None: self.refreshGroups() self.refreshContacts() self.refreshActiveRooms() sender = self.getContactOrRoomOrGroupById(raw_sender) receiver = self.getContactOrRoomOrGroupById( raw_receiver) yield (sender, receiver, message) else: pass # print "[*] %s" % OT._VALUES_TO_NAMES[operation.type] # print operation self.revision = max(operation.revision, self.revision)
def getLineMessageFromMessage(self, messages=[]): """Change Message objects to LineMessage objects :param messges: list of Message object """ lineMessages = [] for message in messages: lineMessages.append(LineMessage(self, message)) return lineMessages
def longPollUpdate(self, count=50, debug=False): """Receive a list of operations that have to be processed by original Line cleint. :param count: number of operations to get from :returns: a generator which returns operations >>> for op in client.longPoll(): sender = op[0] receiver = op[1] message = op[2] print "%s->%s : %s" % (sender, receiver, message) """ """Check is there any operations from LINE server""" OT = OperationType try: operations = self._fetchOperations(self.revision, count) except EOFError: return except TalkException as e: if e.code == 9: self.raise_error("user logged in to another machine") else: return print operations for operation in operations: if debug: print operation if operation.type == OT.END_OF_OPERATION: pass elif operation.type == OT.SEND_MESSAGE: pass elif operation.type == OT.RECEIVE_MESSAGE: message = LineMessage(self, operation.message) yield message elif operation.type in [60, 61]: pass else: print "[*] %s" % OT._VALUES_TO_NAMES[operation.type] print operation self.revision = max(operation.revision, self.revision)
def getLineMessageFromMessage(self, messages=[]): """Change Message objects to LineMessage objects :param messges: list of Message object """ return [LineMessage(self, message) for message in messages]
def longPoll(self, count=50, debug=False): """Receive a list of operations that have to be processed by original Line cleint. :param count: number of operations to get from :returns: a generator which returns operations >>> for op in client.longPoll(): sender = op[0] receiver = op[1] message = op[2] print "%s->%s : %s" % (sender, receiver, message) """ """Check is there any operations from LINE server""" OT = OperationType try: operations = self._fetchOperations(self.revision, count) except EOFError: return except TalkException as e: if e.code == 9: self.raise_error("user logged in to another machine") else: return for operation in operations: if debug: print operation if operation.type == OT.END_OF_OPERATION: pass elif operation.type == OT.SEND_MESSAGE: pass elif operation.type == OT.RECEIVE_MESSAGE: message = LineMessage(self, operation.message) raw_sender = operation.message._from raw_receiver = operation.message.to sender = self.getContactOrRoomOrGroupById(raw_sender) receiver = self.getContactOrRoomOrGroupById(raw_receiver) # If sender is not found, check member list of group chat sent to if sender is None: try: for m in receiver.members: if m.id == raw_sender: sender = m break except (AttributeError, TypeError): pass # If sender is not found, check member list of room chat sent to if sender is None: try: for m in receiver.contacts: if m.id == raw_sender: sender = m break except (AttributeError, TypeError): pass if sender is None or receiver is None: self.refreshGroups() self.refreshContacts() self.refreshActiveRooms() sender = self.getContactOrRoomOrGroupById(raw_sender) receiver = self.getContactOrRoomOrGroupById(raw_receiver) if sender is None or receiver is None: contacts = self._getContacts([raw_sender, raw_receiver]) if contacts: if len(contacts) == 2: sender = LineContact(self, contacts[0]) receiver = LineContact(self, contacts[1]) yield (sender, receiver, message) elif operation.type in [60, 61]: pass else: print "[*] %s" % OT._VALUES_TO_NAMES[operation.type] print operation self.revision = max(operation.revision, self.revision)