Reputation: 101
I've just started using Hubot recently.
I'd like to know if a command is used, but no arguments have been entered.
robot.respond(/dothis (.*)/i, function(res) { ... };
This doesn't return anything if no arguments have been entered, even though it accepts 0 or more arguments.
robot.respond(/dothis/i, function(res) { ... };
This doesn't accept any arguments, but responds when called.
Not quite sure how to go about this, is it possible?
Upvotes: 0
Views: 439
Reputation: 70153
I think you'd need a regular expression engine that handled positive look-behinds to do this in a straightforward way, and I don't think V8 (which is what Node is using under the hood) has that as of this writing.
There are lots of other workarounds, though. Here's one using \b
which checks for a word-boundary:
robot.respond(/dothis\b(.*)/i, function(res) {
if (res.match[1]) {
res.send('We got the paramater: ' + res.match[1].trim());
} else {
res.send('Command called with no parameter.');
}
});
Upvotes: 1
Reputation: 101
robot.respond(/dothis(.*)/i, function(res) { ... };
This works, that space makes all the difference. It will now take an empty string as an argument.
Upvotes: 0