Hubot可以支持Shell / IRC / XMPP等不同的适配器。
如果在环境变量HUBOT_ADAPTER
中设置了适配器,则可以检查process.env.HUBOT_ADAPTER
。
if process.env.HUBOT_ADAPTER is "shell"
msg.send "This is Shell adapater"
但它也支持使用选项--adapter
,如何在hubot脚本中检测到这一点。
我想基于适配器编写不同的逻辑,如chat-room,userid。
否则我需要为不同的适配器准备单独的脚本。
答案 0 :(得分:2)
从github问题https://github.com/github/hubot/issues/647
得到两条建议 [更新]此问题已在源代码robot.coffee
中修复,添加了adapterName
,因此您可以检查自版本2.7.2以来的robot.adapterName
,请参阅{ {3}}
嗅探,可以使用adapter
中的特殊信息进行检查,并在shell
,xmpp
,{{1}下查看我的环境的可能检查情况}
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"
中添加额外参数,它需要一个补丁,它是内部代码,请参阅上面的更新
到目前为止,我选择嗅探