如何在Hubot脚本中获取适配器名称?

Larry Cai

Hubot可以支持其他适配器,例如Shell / IRC / XMPP。

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

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

但它也支持使用options --adapter,以及如何在hubot脚本中检测到这一点。

我想基于适配器(如聊天室,用户ID)编写不同的逻辑。

否则,我需要为不同的调整器准备单独的脚本。

Larry Cai

从github问题获得了两个建议https://github.com/github/hubot/issues/647

[更新]robot.coffee通过添加在源代码中已解决此问题adapterName,因此您可以检查robot.adapterName从2.7.2版开始的情况,查看更改

,它可以用在特殊的信息进行检查adapter,并低于我的环境中可能的检查shellxmppirc

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,它需要这个补丁,它是内部代码参见上面的更新

到目前为止,我选择嗅探

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Linux Mint中更改适配器名称

如何获取内部蓝牙适配器的名称

如何在 RecyclerView 适配器中获取 SharedPreferences 浮点值?

如何在WEC2013中获取适配器的网络掩码和默认网关

如何在回收者视图适配器中获取上下文

如何在Android中获取适配器内最后可见项目的位置

如何在DirectX12中获取适配器驱动程序版本?

如何在Xamarin android Array适配器中获取可见列表项计数

我如何在适配器中获取权限回调

如何在另一个活动中获取阵列适配器的位置

如何在SailsJS / Waterline适配器方法中获取数据库对象?

如何从Android中的RecyclerView适配器获取物品

片段的ViewPager中的Listview适配器-如何获取活动

如何从Android Kotlin中的RecyclerView适配器获取arraylist

如何从wifi适配器中获取信息?

如何在 ChartJS 中包含适配器和插件

如何在片段中调用RecyclerView适配器的方法

addAll如何在Android List适配器中工作?

如何在适配器中启动活动

如何在 recyclerview 适配器中与 Viewmodel 交互?

如何在适配器中启动Activity?

如何在recyclerView的适配器中调用scrollToPosition(position)?

如何在Android中自定义适配器?

如何在分段适配器(Android)中获得位置?

如何在Android的适配器中设置数据

如何在回收器适配器中添加片段?

如何在活动中更新适配器的文本视图

如何在RecyclerView适配器的onBindViewHolder中声明overridePendingTransition?

如何在其适配器的onBindViewHolder中更新recyclerView?