Example #1
0
    def __process_command(self, message: State) -> Action:
        if not message.is_already_processed():
            message.previous_execution = self.server_status_datasource.get_last_message(message.user_name)
            actions = self.__process_command_ai(message)
            message.mark_as_processed()
            logger.info(f"after setting info: {message.is_already_processed()}")
            self.server_status_datasource.store_info(message)
            action = self.server_pending_actions_datasource.store_pending_actions(
                message.command_id,
                actions,
                message.user_name)
        else:
            logger.info(f"we have pending action")
            action = self.server_pending_actions_datasource.get_next_action(message.command_id, message.user_name)

        if action is None:
            action = Action(
                suggested_command=message.command,
                origin_command=message.command,
                execute=False
            )

        action.origin_command = message.command
        if message.is_post_process():
            message.action_post_suggested = action
        else:
            message.action_suggested = action
        self.server_status_datasource.store_info(message)
        action.execute = action.execute or self.server_status_datasource.is_power()

        return action
Example #2
0
    def process_message(self, message: State) -> Action:
        try:
            message = self.server_status_datasource.store_info(message)
            if message.is_post_process():
                message = self.server_status_datasource.find_message_stored(message.command_id, message.user_name)
                return self.process_post_command(message)
            if message.is_command():
                return self.__process_command(message)

        # pylint: disable=broad-except
        except Exception as ex:
            logger.info(f"error processing message {ex}")
            logger.info(traceback.format_exc())

        return Action(origin_command=message.command)