2014-02-13 96 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添加額外的參數,它需要這個補丁,它裏面的代碼看到更新以上

我選擇到目前爲止