简体   繁体   English

如何动态定义hubot命令的帮助?

[英]How do I dynamically define help for a hubot command?

Hubot generally expects scripts to have headers of the form: Hubot通常期望脚本具有以下形式的标题:

# Commands:
#   hubot foo - Hubot says foo.

However, what if I want to dynamically define the text trigger for my command? 但是,如果要动态定义命令的文本触发器怎么办? Eg if I have a command: 例如,如果我有一条命令:

fooCommandText = process.env.HUBOT_FOO_COMMAND || 'foo'

module.exports = (robot) ->
  robot.respond ///#{fooCommandText}///, (response) ->
    response.send 'foo'

I still want hubot help to work, but I can't use a static header to define what my command looks like. 我仍然希望hubot help起作用,但是我无法使用静态标头来定义命令的外观。

Looking at robot.coffee in Hubot itself, I can see parseHelp explicitly reads the script file and parses the header. 查看Hubot本身中的robot.coffee,我可以看到parseHelp显式读取脚本文件并解析标头。

How can I make hubot help work for a command whose text trigger is dynamic? 如何使hubot help对文本触发器是动态的命令起作用?

You can append to robot.commands instead of defining a help block: 您可以追加到robot.commands而不是定义帮助块:

module.exports = (robot) ->
  robot.commands.push "hubot #{fooCommandText} - Hubot says foo."

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

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