Skip to content
Browse files

Bot responds to PM's

  • Loading branch information...
1 parent bc589bf commit e84676aa0188d81a1aece9456fa48a8db0bb6acc @rehandalal rehandalal committed
Showing with 38 additions and 26 deletions.
  1. +6 −4 api.js
  2. +13 −22 standup-irc.js
  3. +19 −0 utils.js
View
10 api.js
@@ -8,15 +8,17 @@ exports.status = {
* - `content`: The text of the status.
*/
create: function(user, project, content) {
- if (project[0] === '#') {
- project = project.slice(1);
- }
var data = {
user: user,
- project: project,
content: content,
api_key: config.standup.api_key
};
+ if (project !== null) {
+ if (project[0] === '#') {
+ project = project.slice(1);
+ }
+ data.project = project;
+ }
return utils.request('/api/v1/status/', 'POST', data);
},
View
35 standup-irc.js
@@ -27,8 +27,6 @@ var defaults = {
blacklist: []
};
-
-
var existsSync = fs.existsSync || path.existsSync;
// Global config.
@@ -167,23 +165,7 @@ irc_client.on('message', function(user, channel, message) {
if (match) {
message = match[1].trim();
-
- if (message[0] === '!') {
- // message = "!cmd arg1 arg2 arg3"
- var cmd_name = message.split(' ')[0].slice(1);
- var args = message.split(' ').slice(1);
- args = utils.parseArgs(args);
- var cmd = commands[cmd_name] || commands['default'];
- cmd.func(user, channel, message, args);
- } else {
- if (message.toLowerCase() === 'botsnack') {
- // Special case for botsnack
- commands.botsnack.func(user, channel, message, []);
- } else {
- // If they didn't ask for a specific command, post a status.
- commands.status.func(user, channel, message, [channel, message]);
- }
- }
+ utils.respond(message, user, channel, commands);
}
});
@@ -201,6 +183,11 @@ irc_client.on('notice', function(from, to, text) {
}
});
+// React to private messages
+irc_client.on('pm', function(user, message) {
+ utils.respond(message, user, user, commands);
+});
+
var commands = {
/* Post a message in all channels */
'announce': {
@@ -394,9 +381,13 @@ var commands = {
usage: "<project> status message",
func: function(user, channel, message, args) {
utils.ifAuthorized(user, channel, function() {
- var project = args[0];
- if (project[0] === '#') {
- project = project.slice(1);
+ var project = null;
+
+ if (user !== channel) {
+ project = args[0];
+ if (project[0] === '#') {
+ project = project.slice(1);
+ }
}
var status = args.slice(1).join(' ');
View
19 utils.js
@@ -123,6 +123,25 @@ exports.parseArgs = function(argList) {
return args;
};
+exports.respond = function(message, user, channel, commands) {
+ if (message[0] === '!') {
+ // 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);
+ } else {
+ if (message.toLowerCase() === 'botsnack') {
+ // Special case for botsnack
+ commands.botsnack.func(user, channel, message, []);
+ } else {
+ // If they didn't ask for a specific command, post a status.
+ commands.status.func(user, channel, message, [channel, message]);
+ }
+ }
+}
+
exports.talkback = function(channel, user, message) {
if (channelSetting(channel, 'talkback') === 'quiet') {
channel = user;

0 comments on commit e84676a

Please sign in to comment.
Something went wrong with that request. Please try again.