2014-02-13 49 views
1

Hubot可以支持不同的适配器,如Shell/IRC/XMPP。如何在hubot脚本中获得适配器名称?

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

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

但它也支持使用选项--adapter,我怎么可以检测到这种在hubot脚本。

我想根据像聊天室,用户标识符这样的适配器编写不同的逻辑。

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

回答

1

得到了GitHub上的两个建议发出https://github.com/github/hubot/issues/647

[更新]这个问题是通过添加adapterName,这样你就可以检查robot.adapterName因为2.7.2版本固定在源代码robot.coffee,看到changes

sniff,可以用adapter中的特殊信息进行检查,以及对我的环境可能在shell,xmpp,irc

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添加额外的参数,它需要这个补丁,它里面的代码看到更新以上

我选择到目前为止