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 脚本中检测到这一点。
我想根据适配器编写不同的逻辑,例如聊天室、用户ID。
否则我需要为不同的适配器准备单独的脚本。
最佳答案
从github问题中得到了两个建议https://github.com/github/hubot/issues/647
[更新]此问题已在源代码 robot.coffee
中修复通过添加adapterName
,所以你可以检查robot.adapterName
自版本 2.7.2 起,请参阅 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
中添加额外参数 ,它需要一个补丁,它在代码内部,请参阅上面的更新
到目前为止我选择嗅探
关于hubot - 如何在 hubot 脚本中获取适配器名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21746880/