Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aynonomous option #15

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
npm-debug.log
31 changes: 29 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,6 +16,9 @@ const aliases = {
begin: start,
summary,
sum: summary,
anonymous,
incognito: anonymous,
hide: anonymous,
version: require('../package.json').version,
};

Expand All @@ -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 = {};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand All @@ -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.');
Expand Down