Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add the comment command

  • Loading branch information...
commit 6beff89e3f79976c31868e63ff7ab01b680b2b78 1 parent e84676a
@rehandalal rehandalal authored
Showing with 40 additions and 4 deletions.
  1. +5 −1 api.js
  2. +28 −0 standup-irc.js
  3. +7 −3 utils.js
View
6 api.js
@@ -6,13 +6,17 @@ exports.status = {
* - `user`: The user that submitted the status.
* - `project`: The project associated with the status.
* - `content`: The text of the status.
+ * - `reply_to`: The ID of the status being replied to
*/
- create: function(user, project, content) {
+ create: function(user, project, content, reply_to) {
var data = {
user: user,
content: content,
api_key: config.standup.api_key
};
+ if (reply_to) {
+ data.reply_to = reply_to;
+ }
if (project !== null) {
if (project[0] === '#') {
project = project.slice(1);
View
28 standup-irc.js
@@ -269,6 +269,31 @@ var commands = {
}
},
+ 'comment': {
+ func: function(user, channel, message, reply_to) {
+ utils.ifAuthorized(user, channel, function() {
+ var project = null;
+
+ if (user !== channel) {
+ project = args[0];
+ if (project[0] === '#') {
+ project = project.slice(1);
+ }
+ }
+
+ var response = api.status.create(user, project, message, reply_to);
+
+ response.once('ok', function(data) {
+ utils.talkback(channel, user, 'Ok, commented on #' + reply_to + ' with #' + data.id);
+ });
+
+ response.once('error', function(err, data) {
+ utils.talkback(channel, user, 'Uh oh, something went wrong.');
+ });
+ });
+ }
+ },
+
/* Delete a status by id number. */
'delete': {
help: "Delete a status by id.",
@@ -348,6 +373,8 @@ var commands = {
irc_client.say(user, 'Available commands:');
+ irc_client.say(user, '!<id> <comment> - Comment on a particular status.')
+
_.each(_.keys(commands).sort(), function(command) {
help = commands[command].help;
usage = commands[command].usage;
@@ -515,6 +542,7 @@ var commands = {
/* The default action. Return an error. */
'default': {
func: function(user, channel, message) {
+ logger.info('Invalid command: ' + message);
irc_client.say(channel, user + ': Huh? Try !help.');
}
}
View
10 utils.js
@@ -128,9 +128,13 @@ exports.respond = function(message, user, channel, commands) {
// message = "!cmd arg1 arg2 arg3"
var cmd_name = message.split(' ')[0].slice(1);
var args = message.split(' ').slice(1);
- args = this.parseArgs(args);
- var cmd = commands[cmd_name] || commands['default'];
- cmd.func(user, channel, message, args);
+ if (_.isFinite(parseInt(cmd_name)) && (parseInt(cmd_name) == cmd_name)) {
+ commands['comment'].func(user, channel, args.join(' '), cmd_name);
+ } else {
+ args = this.parseArgs(args);
+ var cmd = commands[cmd_name] || commands['default'];
+ cmd.func(user, channel, message, args);
+ }
} else {
if (message.toLowerCase() === 'botsnack') {
// Special case for botsnack
Please sign in to comment.
Something went wrong with that request. Please try again.