0

我有一个在 heroku 上运行的 hubot 实例。我不需要任何默认行为(例如帮助命令)。相反,我想选择我自己的命令,让用户输入带有命令的文本。在这种情况下,我只想运行pb每个用户输入。

因此,如果用户输入hello我希望 humbot 运行pb hello.

我正在尝试基于 mshish 建议的代码在/scripts/example.cofee

module.exports = (robot) ->
  robot.hear /.*/, (msg) ->
    pb msg
4

3 回答 3

1

你也可以用中间件来做到这一点。我写这篇文章是为了记录任何人说过的每一条信息以及他们在哪里说的。但你可以明白。你可以在我运行这些@robot.logger.info东西的地方运行任何代码

module.exports = (robot) ->
robot.listenerMiddleware (context, next, done) ->
if context.listener.regex.source is /(.+)/i.source
  @robot.logger.info("#{context.response.message.user.name} said: \"#{context.response.message.text}\" in Channel: #{context.response.message.room}")
next()
于 2016-04-28T19:59:16.363 回答
1

听起来你想听“任何东西”。使用 Hubot 的听到和响应功能(听到不响应会做你想要的)并使用匹配所有内容的正则表达式,.*

要关闭默认脚本,请使用npm uninstall --save PACKAGE_NAME从 repo 的根目录中删除它们。PACKAGE_NAME 应该与您要从中删除的脚本包匹配package.json。您可能还需要从external-scripts.json和手动删除脚本hubot-scripts.json

于 2016-04-10T15:46:27.327 回答
1

所以要回答你问题的第一部分,删除你不需要的部分。只需编辑您的 package.json 并删除您不需要的命令的行。相对不言自明,应该可以安全地删除以下内容:

  • “hubot-诊断”:“0.0.1”,
  • "hubot-google-images": "^0.1.2",
  • "hubot-帮助": "^0.1.1",
  • “hubot-maps”:“0.0.1”,
  • "hubot-pugme": "^0.1.0",
  • "hubot-rules": "^0.1.0",
  • "hubot-scripts": "^2.5.16",
  • "hubot-shipit": "^0.1.1",

然后对于第二部分,你部分正确。

  robot.hear /.*/, (msg) ->
    pb msg

应该是这种格式:

  robot.hear /.*/, (msg) ->
    msg.send "pb #{msg.match[0]}"

msg.send 是用于实际向聊天室发送消息的命令。并且 msg.match[0] 包含用户作为消息输入的任何内容。

编辑:另外,需要从“external-scripts.json”中删除条目。

于 2016-04-12T19:59:34.737 回答