hubot-command-mapper
Version:
Helps with mapping tools and commands to Hubot.
19 lines (18 loc) • 712 B
JavaScript
import NamedRegExp from "named-regexp-groups";
import { convertCommandIntoRegexString } from "../../utils/regex.mjs";
export function getValues(robotName, robotAlias, tool, command, message) {
let collection = {};
if (command.parameters) {
let r = convertCommandIntoRegexString(robotName, robotAlias, tool, command, true);
let nr = new NamedRegExp(r, "si");
let answer = nr.exec(message).groups;
for (let parameter of command.parameters) {
let value = answer[parameter.name];
if (value == null) {
value = parameter.defaultValue;
}
collection[parameter.name] = value;
}
}
return collection;
}