繁体   English   中英

如何拦截/捕捉Hubot响应

[英]How to intercept/hook into Hubot responses

有没有办法全局拦截所有Hubot触发器/响应? 拦截应该能够在发送之前检查,修改,转发或拒绝Hubot响应。

我想实现的一些目标:

  • 限制Hubot发送的所有消息(来自所有插件/脚本),以防止泛洪。
  • 应用某种ACL(访问控制列表)来限制谁可以使用命令。
  • 等等

我在Hubot的官方文档中找不到它。 我错过了一些东西吗?

要控制对监听器的访问,请查看监听器中间件: https : //hubot.github.com/docs/scripting/#listener-middleware https://hubot.github.com/docs/patterns/#restricting-access-to-命令

要执行速率限制命令,请查看hubot-rate-limit: https : //github.com/michaelansel/hubot-rate-limit

为了控制响应,请关注响应中间件PR: https : //github.com/github/hubot/pull/1021

这是我编写的简单中间件,用于记录针对机器人的消息。 根据用户名或房间名或其他名称,可以轻松对其进行修改以执行其他操作。

module.exports = (robot) ->
  robot.listenerMiddleware (context, next, done) ->
    #create a regex with the robots name in it
    robotName = new RegExp("#{context.listener.robot.name}", "i")
    #only log messages meant for the robot
    if robotName.test("#{context.response.message.text}")
      #only log messages once with the "everything" listener context
      if context.listener.regex.source is /(.+)/i.source
        console.log "User: #{context.response.message.user.name} asked me to \"#{context.response.message.text}\" in Channel: #{context.response.message.room}"
        #your code goes here
    next()

这个东西可以让你限制速率

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM