2017-10-24 14 views
0

robot.brain의 속성을 내 스크립트 본문 module.exports에 초기화하면 작동하지 않습니다 (아래 코드 참조). 응답하는 동안 초기화하면 작동합니다. 내 가설이 허비 -Redis-brain correct에 의해 덮어 쓰여지는 것입니까? 어떻게하면 좋을까요?robot.brain의 값을 너무 일찍 설정하면 hubot-redis-brain으로 덮어 씁니다.

module.exports = (robot) => { 
    robot.logger.debug("Setting the fucking property"); 
    robot.brain.set("stringproperty", "stringvalue"); 
    robot.logger.debug("SET!"); 
    // logs these two entries before 'INFO hubot-redis-brain: Data for hubot brain retrieved from Redis' 

    const respondAndLog = (res, message) => { 
     robot.logger.debug("Responding: " + message); 
     res.reply(message); 
    }; 

    robot.respond(/get_stringproperty/, (res) => { 
     respondAndLog(res, `${robot.brain.get("stringproperty")}`); 
     // prints null. WTF? 
    }); 

    robot.respond(/get_laterinitializedproperty/, (res) => { 
     robot.brain.set("laterinitializedproperty", "laterinitializedvalue"); 
     respondAndLog(res, `${robot.brain.get("laterinitializedproperty")}`); 
    // prints laterinitializedproperty, works OK 
    }); 
}; 

답변

1

hubot-redis-brainrobot.brain는) https://github.com/hubotio/hubot-redis-brain/blob/487dd4a9641f35ffb5ae18fb5e1b09e8114c4b70/src/redis-brain.js#L55](see 라인 55 및 59 참조 데이터 레디 스로부터로드되거나 초기화되는 이벤트 "connected"을 방출한다. 따라서 이것이 어떻게 고정되어야하는지입니다 :

robot.brain.on("connected",() => { 
    robot.logger.debug("Setting the fucking property"); 
    robot.brain.set("stringproperty", "stringvalue"); 
    robot.logger.debug("SET!"); 
});