2

Hubot 可以支持不同的适配器,如 Shell/IRC/XMPP。

如果在环境变量中设置了适配器HUBOT_ADAPTER,则process.env.HUBOT_ADAPTER可以检查。

if process.env.HUBOT_ADAPTER is "shell"
   msg.send "This is Shell adapater"

但它也支持使用 options --adapter,以及如何在 hubot 脚本中检测到这一点。

我想根据适配器(如聊天室、用户 ID)编写不同的逻辑。

否则我需要为不同的适配器准备单独的脚本。

4

1 回答 1

2

从 github 问题中得到了两个建议https://github.com/github/hubot/issues/647

[更新] 这个问题在源代码中robot.coffee通过添加修复adapterName,所以你可以robot.adapterName从 2.7.2 版本开始检查,查看更改

嗅探,可以使用特殊信息进行检查,adapter并可能在下面检查我的环境shellxmppirc

robot.respond /adapter$/i, (msg) ->
    #console.log "adapter", robot.adapter
    if robot.adapter.client?
        if robot.adapter.client.preferredSaslMechanism?
            msg.send "this is xmpp adapter"
    if robot.adapter.bot?
        if robot.adapter.bot.opt?
            msg.send "this is irc adapter"
        #if robot.adapter.bot?
            #   msg.send "this is campfire ?"
    if robot.adapter.repl?
        if robot.adapter.repl.terminal?
            msg.send "this is shell adapter"

添加额外的参数robot.coffee它需要一个补丁,它在里面的代码见上面的更新

到目前为止我选择嗅探

于 2014-02-17T02:58:26.247 回答