【问题标题】:response.send understanding? (hubot-script)response.send 理解? (hubot脚本)
【发布时间】:2018-03-26 05:51:58
【问题描述】:

我最近安装了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

为什么我会收到这样的回复

我先在哪里得到url,然后是mapUrl

我希望先得到mapUrl,然后是url

【问题讨论】:

    标签: javascript node.js coffeescript hubot


    【解决方案1】:

    来自this hubot PR,看起来Hubot 异步运行你的msg.sends,所以没有保证顺序。

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

    如果您希望在url 之前使用mapUrl,可以查看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))
    }
    

    【讨论】:

    • 太棒了!谢谢!!!我在JS方面不是很专业。我尝试只调用 msg.sen(mapUrl,url) 但出现错误。你能帮我吗?
    猜你喜欢
    • 2017-04-20
    • 2017-01-21
    • 2018-09-12
    • 1970-01-01
    • 2013-12-17
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多