如何拦截/钩入Hubot响应

问题描述:

有什么方法可以全局拦截所有Hubot触发器/响应吗?拦截应能够在发送之前检查,修改,转发或拒绝Hubot响应。如何拦截/钩入Hubot响应

我想一些目标的实现:

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

我不能正式Hubot文档中找到它。我错过了一些东西吗?

控制访问听众,请收听中间件:https://hubot.github.com/docs/scripting/#listener-middleware https://hubot.github.com/docs/patterns/#restricting-access-to-commands

对于限速命令执行,检查出hubot速率限制: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() 

this事情可以让你进行速率限制