Beispiel #1
0
 def do_search(query, call_function):
     print(plugin_handler.subscriptions().call_plugin(
         call_function, {
             "command": query,
             "db": db,
             "user_table": db['users'].find_one(username="******")
         }))
Beispiel #2
0
    def command(command_data, session, db, add_to_updates_queue=True):
        """
        Main command parsing function

        :param command_data:
        :param session:
        :param db:
        :param add_to_updates_queue:
        :return: response object
        """
        global processed_commands
        global error_num
        global success_num
        processed_commands += 1
        # Call the parser
        command_data.update({"db": db})
        parse_data = parser.parse(command_data, session)
        log.info(
            ":{0}:nlp parsing finished, adding data to event queue".format(
                session["id"]))
        response = plugin_handler.subscriptions().process_event(parse_data, db)
        log.info("Got response {0} with type {1}".format(
            response, type(response)))
        if response["type"] == "success":
            success_num += 1
        else:
            error_num += 1
        log.debug("Got response {0} from plugin handler".format(response))
        command_id = command_data['id']
        log.info("{0}:Setting update for command with response {1}".format(
            command_id, response))
        session_id = session['id']
        #Add the response to the update queue
        global sessions
        if add_to_updates_queue:
            sessions[session_id]["updates"].put({
                "command_id": command_id,
                "response": response
            })
        if session_id in commands.keys():
            commands[session_id].append(
                [command_data["command"], response["text"]])
        else:
            commands.update(
                {session_id: [[command_data["command"], response["text"]]]})
        return response