2014-02-13 3 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 스크립트에서이를 감지 할 수있는 방법.

chatroom, userid와 같은 어댑터를 기반으로 다른 로직을 작성하고 싶습니다.

그렇지 않으면 다른 adapater에 대해 별도의 스크립트를 준비해야합니다.

답변

1

은 GitHub의에서이 개 제안

[갱신이 문제는이 버전 2.7.2 이후 robot.adapterName을 확인할 수 있도록 adapterName를 추가하여 소스 코드 robot.coffee에서 해결을 참조 https://github.com/github/hubot/issues/647를 발행있어 changes

스 니프, 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에 추가 매개 변수를 추가 지금까지

관련 문제