Пример #1
0
	def parseResponse(self):
		# Get the timestamp we should send to the server next time we make a request.
		lastSeenPattern = PatternManager.getOrCompilePattern("chatLastSeen")
		match = lastSeenPattern.search(self.responseText)
		self.responseData["lastSeen"] = match.group(1)
		
		# Parse the chat messages.
		text = self.responseText[:self.responseText.find('<!--lastseen')]
		self.responseData["chatMessages"] = ChatUtils.parseMessages(self.responseText)
    def parseResponse(self):
        # Get the timestamp we should send to the server next time we make a request.
        lastSeenPattern = PatternManager.getOrCompilePattern("chatLastSeen")
        match = lastSeenPattern.search(self.responseText)
        self.responseData["lastSeen"] = match.group(1)

        # Parse the chat messages.
        text = self.responseText[:self.responseText.find('<!--lastseen')]
        self.responseData["chatMessages"] = ChatUtils.parseIncomingChatMessage(self.responseText)
Пример #3
0
    def parseResponse(self):
        # Get the timestamp we should send to the server next time we make a request.
        lastSeenPattern = PatternManager.getOrCompilePattern("chatLastSeen")
        match = lastSeenPattern.search(self.responseText)
        self.responseData["lastSeen"] = match.group(1)

        # Parse the chat messages.
        text = self.responseText[:self.responseText.find('<!--lastseen')]
        self.responseData["chatMessages"] = ChatUtils.parseMessages(self.responseText, True)

        # Trace out unknown messages.
        for chat in self.responseData["chatMessages"]:
            if chat["type"] == "unknown":
                Report.trace("chat", "Unable to parse chat message: %s" % chat)
Пример #4
0
    def parseResponse(self):
        # Get the timestamp we should send to the server next time we make a request.
        lastSeenPattern = PatternManager.getOrCompilePattern("chatLastSeen")
        match = lastSeenPattern.search(self.responseText)
        self.responseData["lastSeen"] = match.group(1)

        # Parse the chat messages.
        text = self.responseText[:self.responseText.find('<!--lastseen')]
        self.responseData["chatMessages"] = ChatUtils.parseMessages(
            self.responseText, True)

        # Trace out unknown messages.
        for chat in self.responseData["chatMessages"]:
            if chat["type"] == "unknown":
                Report.trace("chat", "Unable to parse chat message: %s" % chat)
Пример #5
0
	def sendChatMessage(self, text):
		"""
		Sends a chat message. This method will throttle chats sent to the same channel or person.
		Otherwise the KoL server could display them out-of-order to other users.
		"""
		messages = []
		
		# Clean the text.
		text = ChatUtils.cleanChatMessageToSend(text)
		
		# Get information about the chat.
		chatInfo = ChatUtils.parseChatMessageToSend(text)
		
		if len(text) > MAX_CHAT_LENGTH:
			
			# Figure out the prefix that should be appended to every message.
			prefix = ''
			if "type" in chatInfo:
				if chatInfo["type"] == "private":
					prefix = "/w %s " % chatInfo["recipient"]
				elif chatInfo["type"] == "channel":
					if "channel" in chatInfo:
						prefix = "/%s " % chatInfo["channel"]
					if "isEmote" in chatInfo:
						prefix += "/me "
			
			# Construct the array of messages to send.
			while len(text) > (MAX_CHAT_LENGTH - len(prefix)):
				index = text.rfind(" ", 0, MAX_CHAT_LENGTH - len(prefix) - 6)
				if index == -1:
					index = MAX_CHAT_LENGTH - len(prefix) - 6
					msg = text[:index] + "..."
					text = text[index:]
				else:
					msg = text[:index] + "..."
					text = text[index+1:]
				
				if len(messages) > 0:
					msg = "..." + msg
					messages.append(prefix + msg)
				else:
					messages.append(msg)
				
			if len(messages) > 0:
				messages.append(prefix + "..." + text)
			else:
				messages.append(prefix + text)
		else:
			messages.append(text)
		
		# Determine if we need to throttle the message as we don't want to send two messages
		# to the same person or channel without a little time for the server to figure out
		# which message is first.
		key = None
		lastTime = None
		doThrottle = False
		if "type" in chatInfo:
			if chatInfo["type"] == "private":
				key = "private:%s" % chatInfo["recipient"]
			elif chatInfo["type"] == "channel":
				if "channel" in chatInfo:
					key = "channel:%s" % chatInfo["channel"]
				else:
					key = "channel:%s" % self.currentChannel
		if key != None and key in self.lastChatTimestamps:
			lastTime = self.lastChatTimestamps[key]
			if lastTime != None:
				if lastTime >= time.time() - 2:
					doThrottle = True
		
		# Send the message(s).
		chats = []
		for message in messages:
			if doThrottle:
				time.sleep(2)
			r = SendChatRequest(self.session, message)
			data = r.doRequest()
			tmpChats = data["chatMessages"]
			for chat in tmpChats:
				chats.append(chat)
			doThrottle = True
		
		if key != None:
			self.lastChatTimestamps[key] = time.time()
			
		return chats
Пример #6
0
    def sendChatMessage(self, text):
        """
        Sends a chat message. This method will throttle chats sent to the same channel or person.
        Otherwise the KoL server could display them out-of-order to other users.
        """
        messages = []

        # Clean the text.
        text = ChatUtils.cleanChatMessageToSend(text)

        # Get information about the chat.
        chatInfo = ChatUtils.parseChatMessageToSend(text)

        if len(text) > MAX_CHAT_LENGTH:

            # Figure out the prefix that should be appended to every message.
            prefix = ''
            if "type" in chatInfo:
                if chatInfo["type"] == "private":
                    prefix = "/w %s " % chatInfo["recipient"]
                elif chatInfo["type"] == "channel":
                    if "channel" in chatInfo:
                        prefix = "/%s " % chatInfo["channel"]
                    if "isEmote" in chatInfo:
                        prefix += "/me "

            # Construct the array of messages to send.
            while len(text) > (MAX_CHAT_LENGTH - len(prefix)):
                index = text.rfind(" ", 0, MAX_CHAT_LENGTH - len(prefix) - 6)
                if index == -1:
                    index = MAX_CHAT_LENGTH - len(prefix) - 6
                    msg = text[:index] + "..."
                    text = text[index:]
                else:
                    msg = text[:index] + "..."
                    text = text[index + 1:]

                if len(messages) > 0:
                    msg = "..." + msg
                    messages.append(prefix + msg)
                else:
                    messages.append(msg)

            if len(messages) > 0:
                messages.append(prefix + "..." + text)
            else:
                messages.append(prefix + text)
        else:
            messages.append(text)

        # Determine if we need to throttle the message as we don't want to send two messages
        # to the same person or channel without a little time for the server to figure out
        # which message is first.
        key = None
        lastTime = None
        doThrottle = False
        if "type" in chatInfo:
            if chatInfo["type"] == "private":
                key = "private:%s" % chatInfo["recipient"]
            elif chatInfo["type"] == "channel":
                if "channel" in chatInfo:
                    key = "channel:%s" % chatInfo["channel"]
                else:
                    key = "channel:%s" % self.currentChannel
        if key != None and key in self.lastChatTimestamps:
            lastTime = self.lastChatTimestamps[key]
            if lastTime != None:
                if lastTime >= time.time() - 2:
                    doThrottle = True

        # Send the message(s).
        chats = []
        for message in messages:
            if doThrottle:
                time.sleep(2)
            r = SendChatRequest(self.session, message)
            data = r.doRequest()
            tmpChats = data["chatMessages"]
            for chat in tmpChats:
                chats.append(chat)
            doThrottle = True

        if key != None:
            self.lastChatTimestamps[key] = time.time()

        for chat in chats:
            if 'listen' in chat['type'] or 'channel' in chat['type']:
                self.currentChannel = chat['current']

        return chats
Пример #7
0
	def parseResponse(self):
		# Parse the chat messages returned.
		self.responseData["chatMessages"] = ChatUtils.parseMessages(self.responseText)
Пример #8
0
    def sendChatMessage(self, text, waitForReply=False, useEmoteFormat=False):
        """
        Sends a chat message. This method will throttle chats sent to the 
        same channel or person. Otherwise the KoL server could display them 
        out-of-order to other users.
        """
        messages = []

        # Clean the text.
        text = ChatUtils.cleanChatMessageToSend(text)

        # Get information about the chat.
        chatInfo = ChatUtils.parseChatMessageToSend(text)

        # remove commands from beginning of text
        if useEmoteFormat and chatInfo.get("type", None) != "private":

            # get text, not counting /commands at beginning
            arr = text.split(' ')
            while len(arr) > 0 and arr[0][0] == "/":
                del arr[0]
            text = ' '.join(arr)

            if "channel" in chatInfo:
                text = "/%s /me : %s" % (chatInfo["channel"], text)
            else:
                text = "/me : %s" % (text)
            chatInfo["isEmote"] = True

        if len(text) > MAX_CHAT_LENGTH:

            # Figure out the prefix that should be appended to every message.
            prefix = ''
            if "type" in chatInfo:
                if chatInfo["type"] == "private":
                    prefix = "/w %s " % chatInfo["recipient"]
                elif chatInfo["type"] == "channel":
                    if "channel" in chatInfo:
                        prefix = "/%s " % chatInfo["channel"]
                    if "isEmote" in chatInfo:
                        prefix += "/me "

            # Construct the array of messages to send.
            while len(text) > (MAX_CHAT_LENGTH - len(prefix)):
                index = text.rfind(" ", 0, MAX_CHAT_LENGTH - len(prefix) - 6)
                if index == -1:
                    index = MAX_CHAT_LENGTH - len(prefix) - 6
                    msg = text[:index] + "..."
                    text = text[index:]
                else:
                    msg = text[:index] + "..."
                    text = text[index + 1:]

                if len(messages) > 0:
                    msg = "... " + msg
                    messages.append(prefix + msg)
                else:
                    messages.append(msg)

            if len(messages) > 0:
                messages.append(prefix + "... " + text)
            else:
                messages.append(text)
        else:
            messages.append(text)

        # Send the message(s).
        chats = []
        for message in messages:
            chatToSend = chatInfo
            chatToSend["text"] = message
            replyQueue = Queue.Queue()
            self._dispatcher.dispatch(chatToSend, replyQueue)

            if waitForReply:
                replies = replyQueue.get()
                chats.extend(replies)
                replyQueue.task_done()

        for chat in chats:
            if 'listen' in chat['type'] or 'channel' in chat['type']:
                if 'currentChannel' in chat:
                    self.currentChannel = chat['currentChannel']

        return chats
Пример #9
0
 def parseResponse(self):
     # Parse the chat messages returned.
     self.responseData["chatMessages"] = ChatUtils.parseOutgoingChatMessages(self.responseText)
Пример #10
0
    def sendChatMessage(self, text, waitForReply=False, useEmoteFormat=False):
        """
        Sends a chat message. This method will throttle chats sent to the 
        same channel or person. Otherwise the KoL server could display them 
        out-of-order to other users.
        """
        messages = []

        # Clean the text.
        text = ChatUtils.cleanChatMessageToSend(text)

        # Get information about the chat.
        chatInfo = ChatUtils.parseChatMessageToSend(text)

        # remove commands from beginning of text
        if useEmoteFormat and chatInfo.get("type", None) != "private":

            # get text, not counting /commands at beginning
            arr = text.split(' ')
            while len(arr) > 0 and arr[0][0] == "/":
                del arr[0]
            text = ' '.join(arr)

            if "channel" in chatInfo:
                text = "/%s /me : %s" % (chatInfo["channel"], text)
            else:
                text = "/me : %s" % (text)
            chatInfo["isEmote"] = True


        if len(text) > MAX_CHAT_LENGTH:

            # Figure out the prefix that should be appended to every message.
            prefix = ''
            if "type" in chatInfo:
                if chatInfo["type"] == "private":
                    prefix = "/w %s " % chatInfo["recipient"]
                elif chatInfo["type"] == "channel":
                        if "channel" in chatInfo:
                            prefix = "/%s " % chatInfo["channel"]
                        if "isEmote" in chatInfo:
                            prefix += "/me "

            # Construct the array of messages to send.
            while len(text) > (MAX_CHAT_LENGTH - len(prefix)):
                index = text.rfind(" ", 0, MAX_CHAT_LENGTH - len(prefix) - 6)
                if index == -1:
                    index = MAX_CHAT_LENGTH - len(prefix) - 6
                    msg = text[:index] + "..."
                    text = text[index:]
                else:
                    msg = text[:index] + "..."
                    text = text[index + 1:]

                if len(messages) > 0:
                    msg = "... " + msg
                    messages.append(prefix + msg)
                else:
                    messages.append(msg)

            if len(messages) > 0:
                messages.append(prefix + "... " + text)
            else:
                messages.append(text)
        else:
            messages.append(text)


        # Send the message(s).
        chats = []
        for message in messages:
            chatToSend = chatInfo
            chatToSend["text"] = message
            replyQueue = Queue.Queue()
            self._dispatcher.dispatch(chatToSend, replyQueue)

            if waitForReply:
                replies = replyQueue.get()
                chats.extend(replies)
                replyQueue.task_done()

        for chat in chats:
            if 'listen' in chat['type'] or 'channel' in chat['type']:
                if 'currentChannel' in chat:
                    self.currentChannel = chat['currentChannel']

        return chats