2017-10-14 6 views
0

私は最近hubotをインストールしてテストしていました。レスポンスが送信されますか? (hubot-script)

今、私はsthを見ました。私は理解していない:このコード(hubot-mapsの一部 - maps.coffee file)を考えると

私は私が手にこの

enter image description here

のような応答を得るか、なぜ

robot.respond /(?:(satellite|terrain|hybrid)[- ])?map(me)? (.+)/i, (msg) -> 
mapType = msg.match[1] or "roadmap" 
location = encodeURIComponent(msg.match[3]) 
mapUrl = "http://maps.google.com/maps/api/staticmap?markers=" + 
      location + 
      "&size=400x400&maptype=" + 
      mapType + 
      "&sensor=false" + 
      "&format=png" # So campfire knows it's an image 
url  = "http://maps.google.com/maps?q=" + 
      location + 
      "&hl=en&sll=37.0625,-95.677068&sspn=73.579623,100.371094&vpsrc=0&hnear=" + 
      location + 
      "&t=m&z=11" 

msg.send mapUrl 
msg.send url 

最初にurl、次にmapUrl

私はthis hubot PRからurl

答えて

2

その後、mapUrlは、第1および得ることを期待Hubotは非同期あなたmsg.send秒を実行しますので、何の保証オーダーがないように、それが見えます。

リスナーは非同期で実行されるようになりました。 message.doneの周囲の動作 は同じままでなければなりません(message.doneが処理されるまでの処理は です)。

あなたがurlmapUrlをしたい場合は、注文した文字列のリストを受け付けsource codeにおける送信機能、見てみることができます。

// Public: Posts a message back to the chat source 
// 
// strings - One or more strings to be posted. The order of these strings 
//   should be kept intact. 
// 
// Returns nothing. 
send (/* ...strings */) { 
    const strings = [].slice.call(arguments) 
    this.runWithMiddleware.apply(this, ['send', { plaintext: true }].concat(strings)) 
} 
+0

恐ろしいですね!ありがとうございました!!!私はJSのプロではない。私はmsg.sen(mapUrl、url)を呼び出してみましたが、エラーが発生しました。助けてくれますか? –

関連する問題