diff --git a/.gitignore b/.gitignore index 3c3629e..93f1361 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +npm-debug.log diff --git a/lib/index.js b/lib/index.js index b42f5f3..b6471a7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -5,6 +5,7 @@ const dict = require('./dict'); const stop = 'stop'; const start = 'start'; const summary = 'summary'; +const anonymous = 'anonymous'; const aliases = { stop, end: stop, @@ -15,6 +16,9 @@ const aliases = { begin: start, summary, sum: summary, + anonymous, + incognito: anonymous, + hide: anonymous, version: require('../package.json').version, }; @@ -28,6 +32,7 @@ const types = { let bot; const token = process.env.SLACK_TOKEN; let inRetro = false; +let isAnonymous = false; let guid = 0; let dms = {}; @@ -152,7 +157,7 @@ function handleMessage(message) { if (isDM(message)) { debug('> got retrospective message: %s', message.text); - // capture the rerto data + // capture the retro data return captureRetrospective(message); } else if (isToBot(text)) { debug('> got potential command: %s', message.text); @@ -182,6 +187,10 @@ function captureRetrospective(message) { return reply(message, `I've ignored \`${line}\` only because it didn't start with a \`+/-\``); } + + if (isAnonymous){ + message.user = bot.self.id; + } retrospective[type][message.ts] = { user: message.user, @@ -214,7 +223,9 @@ function getRetroParticipants(token, channel, callback) { function command(message) { let [me, cmd, ...rest] = message.text.split(' '); - cmd = cmd.toLowerCase().replace(/\W/g, ''); + if (cmd){ // make sure there is something in cmd before doing .toLowerCase + cmd = cmd.toLowerCase().replace(/\W/g, ''); + } debug('command: %s', cmd); @@ -236,6 +247,22 @@ function command(message) { return; } + if (cmd === anonymous) { + if (isAnonymous){ + isAnonymous = false; + return reply(message, ':male-detective: anonymous retrospective mode disabled'); + } + else{ + if(inRetro){ + isAnonymous = true; + return reply(message, 'The remaining items for this retro will be taken and reported anonymously.'); + } + isAnonymous = true; + let msg = ':male-detective: anonymous retrospective mode enabled'; + return reply(message, msg); + } + } + if (aliases[cmd] === start) { if (inRetro) { return reply(message, 'Another channel is currently using your friendly neighbourhood retrobot. Please try again later.');