【发布时间】:2015-10-01 00:45:09
【问题描述】:
有什么方法可以在全局范围内拦截所有 Hubot 触发器/响应? 拦截应该能够在发送之前检查、修改、转发或拒绝 Hubot 响应。
我想实现的一些目标:
- 限制 Hubot 发送的所有消息(来自所有插件/脚本)以防止泛滥。
- 应用某种 ACL(访问控制列表)来限制谁可以使用命令。
- 等
我在 Hubot 官方文档中找不到它。我错过了一些东西吗?
【问题讨论】:
标签: coffeescript hubot chatbot
有什么方法可以在全局范围内拦截所有 Hubot 触发器/响应? 拦截应该能够在发送之前检查、修改、转发或拒绝 Hubot 响应。
我想实现的一些目标:
我在 Hubot 官方文档中找不到它。我错过了一些东西吗?
【问题讨论】:
标签: coffeescript hubot chatbot
要控制对侦听器的访问,请查看侦听器中间件:https://hubot.github.com/docs/scripting/#listener-middleware https://hubot.github.com/docs/patterns/#restricting-access-to-commands
有关限速命令的执行,请查看 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()
this 的东西会让你限制速率
【讨论】: