简体   繁体   English

如何将 2 个或更多参数传递给 Hubot

[英]how to pass 2 or more arguments to Hubot

I'm trying to make hubot work with powershell.我正在尝试使 hubot 与 powershell 一起工作。 Hubot listens to the command (get service 'servicename' in this example), parces input and sends it to powershell. Hubot 侦听命令(在本例中为 get service 'servicename'),解析输入并将其发送到 powershell。

module.exports = (robot) ->
 robot.respond /get service (.*)$/i, (msg) ->
    serviceName = msg.match[1]

    psObject = {
      serviceName: serviceName
    }

    callPowerShell = (psObject, msg) 

This code works fine with one argument, but I don't know how to pass two arguments to hubot, for example, servicename and compname (get service 'servicename' 'compname').此代码使用一个参数可以正常工作,但我不知道如何将两个参数传递给 hubot,例如 servicename 和 compname(获取服务 'servicename' 'compname')。

You should add one more brackets (.*) in respond or listen command.您应该在 response 或 listen 命令中再添加一个括号 (.*)。 You can add as many as you wish, and also you can add brackets inside brackets.您可以根据需要添加任意数量,也可以在括号内添加括号。 Just count them from the left and count them as 1st, 2nd ... and so on.只需从左边数起它们,并将它们计算为第 1、第 2 ......等等。

module.exports = (robot) ->
    robot.respond /get service (.*) (.*)$/i, (msg) ->
        serviceName = msg.match[1]
        paramTwo = msg.match[2]

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

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