Skip to content

Commit

Permalink
fix bug with sending spam notifications that shouldn't be sent
Browse files Browse the repository at this point in the history
  • Loading branch information
O-Mutt committed Sep 21, 2021
1 parent 34e0934 commit 7001b0b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hubot-plusplus-expanded",
"version": "3.1.5",
"version": "3.1.6",
"description": "A hubot script for micro praise",
"main": "index.js",
"engines": {
Expand Down
45 changes: 26 additions & 19 deletions src/scorekeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,31 @@ class ScoreKeeper {

isSendingToSelf(to, from) {
this.robot.logger.debug(`Checking if is to self. To [${to.name}] From [${from.name}], Valid: ${to.name !== from.name}`);
this.robot.emit('plus-plus-spam', {
to,
from,
message: this.spamMessage,
reason: 'Looks like you may be trying to send a point to yourself.',
});
return to.name === from.name;
const isToSelf = to.name === from.name;
if (isToSelf) {
this.robot.emit('plus-plus-spam', {
to,
from,
message: this.spamMessage,
reason: 'Looks like you may be trying to send a point to yourself.',
});
}
return isToSelf;
}

async isSpam(to, from) {
const toId = to.slackId || to.name;
const fromId = from.slackId || from.name;
this.robot.logger.debug(`Checking spam to [${to.name}] from [${from.name}]`);
const isSpam = await this.databaseService.isSpam(toId, fromId);
this.robot.emit('plus-plus-spam', {
to,
from,
message: this.spamMessage,
reason: `You recently sent <@${toId}> a point.`,
});
if (isSpam) {
this.robot.emit('plus-plus-spam', {
to,
from,
message: this.spamMessage,
reason: `You recently sent <@${toId}> a point.`,
});
}
return isSpam;
}

Expand All @@ -163,12 +168,14 @@ class ScoreKeeper {
isBot = true;
this.robot.logger.error('A bot is sending points in DM');
}
this.robot.emit('plus-plus-spam', {
to: undefined,
from,
message: this.spamMessage,
reason: 'You can\'t have a bot do the dirty work.',
});
if (isBot) {
this.robot.emit('plus-plus-spam', {
to: undefined,
from,
message: this.spamMessage,
reason: 'You can\'t have a bot do the dirty work.',
});
}
return isBot;
}
}
Expand Down
1 change: 1 addition & 0 deletions test/scorekeeper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ describe('ScoreKeeper', function scorekeeperTest() {
expect(r).to.be.an('object');
expect(r.score).to.equal(1);
expect(r.reasons['because points']).to.equal(1);
expect(emitSpy.called).to.equal(false);

// score added
const afterUser = await scoreKeeper.getUser(to);
Expand Down

0 comments on commit 7001b0b

Please sign in to comment.