2017-10-14 76 views
0

我最近安装了hubot并进行了测试。response.send谅解? (hubot脚本)

现在我看到了某事。我不明白:

鉴于此代码(的hubot-maps部分 - maps.coffee file

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 

为什么我得到这样的

enter image description here

在那里我得到回应第一个url然后mapUrl

我期望能获得mapUrlurl

回答

2

this hubot PR,它看起来像Hubot运行您msg.send小号异步,所以没有保证的顺序。

作为副作用,侦听器现在异步执行。在message.done周围的行为 应该保持不变(直到message.done 为真)。

如果你想mapUrlurl之前,你可以看看在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),但得到错误。你能帮我吗? –