简体   繁体   中英

How do I dynamically define help for a hubot command?

Hubot generally expects scripts to have headers of the form:

# 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.

Looking at robot.coffee in Hubot itself, I can see parseHelp explicitly reads the script file and parses the header.

How can I make hubot help work for a command whose text trigger is dynamic?

You can append to robot.commands instead of defining a help block:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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