def handle_message(self, msg):
        """
        Takes a raw message direct from the server, parses it, and stores its
        data in the world and body model objects given at init.  Returns the
        type of message received.
        """

        # get all the expressions contained in the given message
        parsed = messageparser.parse(msg)

        if PRINT_SERVER_MESSAGES:
            print msg
            # print parsed[0] + ":", parsed[1:], "\n"

        # this is the name of the function that should be used to handle
        # this message type.  we pull it from this object dynamically to
        # avoid having a huge if/elif/.../else statement.
        msg_func = "_handle_%s" % parsed[0]

        if hasattr(self, msg_func):
            # call the appropriate function with this message
            getattr(self, msg_func).__call__(parsed)

        # throw an exception if we don't know about the given message type
        else:
            m = "Can't handle message type '%s', function '%s' not found."
            # FIXME raising will kill the agent.
            raise sp_exceptions.MessageTypeError(m % (parsed[0], msg_func))
            # print sp_exceptions.MessageTypeError(m % (parsed[0], msg_func))

        # return the type of message received
        return parsed[0]
Esempio n. 2
0
def message_handle(message, kiwi):
    response = Response()
    # we do not want the bot to reply to itself
    if message.author == kiwi:
        return response

    action = messageparser.parse(message)
    if action.type == 'simple_reply':
        response.messages_to_send.append(action.simple_reply)
        response.should_respond = True
    # if message.content.startswith('!hello'):
    #    response.messages_to_send.append('Hello {0.author.mention}'.format(message))
    #  #response.messages_to_send.append('Hello {0.author.mention}')
    #   response.should_respond = True
    return response
Esempio n. 3
0
 def handleIncomingMsg(self, data, r):
     try:
         inputMsg = mp.parse(data)
         type = inputMsg.type
     except :
         type = 'error'
     if type == "new":
         print 'Game request: NEW'
         self.handleJoinGame(inputMsg, r)    
     elif type == "move":
         self.handleMove(inputMsg, r)
     elif type == "exit":
         pass
     elif type == "reqgameplay":
         pass
     else:
         print 'Error reading game request.'
         self.sendMessage(r, 'Error reading game request. Please make sure message type is either [new move exit reqgameply]')
Esempio n. 4
0
def on_message(message):
    response = messageparser.parse(message)
    if (response is not None):
        client.send_message(message.channel, response)
    botfunc.commands(client, message)
Esempio n. 5
0
def on_message(message):
    response = messageparser.parse(message)
    if(response is not None):
        client.send_message(message.channel, response)
    botfunc.commands(client, message)