1

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

我想实现的一些目标:

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

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

4

2 回答 2

1

要控制对侦听器的访问,请查看侦听器中间件: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

于 2015-09-29T18:13:25.330 回答
1

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

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()

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

于 2015-09-30T16:45:09.523 回答