2017-10-24 4 views
0

robot.brainのプロパティをスクリプトのmodule.exportsに初期化すると、動作しません(下のコードを参照)。応答中に初期化すると動作します。私の仮説は、ハッボット - レディス - 脳の正しいものによって上書きされるのだろうか?どのように私はいいやり方でそれを修正するのですか?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-brainデータのRedisからロードまたは初期化されるときrobot.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!"); 
}); 
関連する問題