Skip to content

Commit

Permalink
re-adding the plusplus with and without pretext/conjunction but manag…
Browse files Browse the repository at this point in the history
…ing false positives on -- or em
  • Loading branch information
O-Mutt committed Sep 24, 2021
1 parent da91544 commit 099e339
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Individual run:
`npm run test`

Tdd:
`npm run tdd`
`npm run test:watch`

## Known issue
As of now there is an issue that has shown up a couple times without a root cause. The `$setOnInsert` excludes the `reasons: {}` object. The fix, currently, is to identify the bad document in mongo `db.scores.find({ "reasons: null"});` and update them `db.scores.updateMany({ "reasons: null"}, { $set: { "reasons": {} });`
2 changes: 1 addition & 1 deletion package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hubot-plusplus-expanded",
"version": "3.1.7",
"version": "3.2.0",
"description": "A hubot script for micro praise",
"main": "index.js",
"engines": {
Expand All @@ -13,7 +13,7 @@
},
"scripts": {
"test": "mocha --timeout 35000 **/*.test.* --exit",
"tdd": "mocha --watch **/*.test.*",
"test:watch": "mocha --watch **/*.test.*",
"lint": "eslint src --fix",
"snyk-protect": "snyk protect",
"prepare": "npm run snyk-protect"
Expand Down
7 changes: 7 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const moment = require('moment');
const regexp = require('./regexp');

function getEsOnEndOfWord(number) {
if (number === -1 || number === 1) {
Expand Down Expand Up @@ -173,6 +174,11 @@ function isPrivateMessage(room) {
return room[0] === 'D' || room === 'Shell';
}

function isKnownFalsePositive(premessage, conjunction, reason, operator) {
const falsePositive = premessage && !conjunction && reason && operator.match(regexp.negativeOperators);
return falsePositive;
}

module.exports = {
getMessageForNewScore,
getMessageForTokenTransfer,
Expand All @@ -184,4 +190,5 @@ module.exports = {
getEsOnEndOfWord,
isPrivateMessage,
capitalizeFirstLetter,
isKnownFalsePositive,
};
5 changes: 3 additions & 2 deletions src/plusplus.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ module.exports = function plusPlus(robot) {
*/
async function upOrDownVote(msg) {
const [fullText, premessage, name, operator, conjunction, reason] = msg.match;
if (premessage || (!conjunction && reason)) {

if (helpers.isKnownFalsePositive(premessage, conjunction, reason, operator)) {
// circuit break a plus plus
robot.emit('plus-plus-failure', {
notificationMessage: `False positive detected in <#${msg.message.room}> from <@${msg.message.user.id}>:\nPre-Message text: [${!!premessage}].\nMissing Conjunction: [${!!(!conjunction && reason)}]\n\n${fullText}`,
Expand Down Expand Up @@ -215,7 +216,7 @@ module.exports = function plusPlus(robot) {
if (!names) {
return;
}
if (premessage || (!conjunction && reason)) {
if (helpers.isKnownFalsePositive(premessage, conjunction, reason, operator)) {
// circuit break a plus plus
robot.emit('plus-plus-failure', {
notificationMessage: `False positive detected in <#${msg.message.room}> from <@${msg.message.user.id}>:\nPre-Message text: [${!!premessage}].\nMissing Conjunction: [${!!(!conjunction && reason)}]\n\n${fullText}`,
Expand Down
40 changes: 32 additions & 8 deletions test/plusplus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ describe('PlusPlus', function () {
expect(user.score).to.equal(1);
});

it('shouldn\'t add a point when a user is ++\'d with pre-text', async function () {
it('should add a point when a user is ++\'d with pre-text', async function () {
const emitSpy = sinon.spy(room.robot, 'emit');
room.user.say('matt.erickson', 'where are you d00d @derp++');
await new Promise((resolve) => setTimeout(resolve, 50));
expect(emitSpy).to.have.been.calledWith('plus-plus-failure', {
expect(room.messages[1][1]).to.match(/derp has 1 point\.\n:birthday: Today is derp's hubotday! :birthday:/);
expect(emitSpy).not.to.have.been.calledWith('plus-plus-failure', {
notificationMessage: 'False positive detected in <#room1> from <@matt.erickson>:\n'
+ 'Pre-Message text: [true].\n'
+ 'Missing Conjunction: [false]\n'
Expand All @@ -67,14 +68,16 @@ describe('PlusPlus', function () {
});

const user = await db.collection('scores').findOne({ name: 'derp' });
expect(user).to.equal(undefined);
expect(user).not.to.equal(undefined);
expect(user.score).to.equal(1);
});

it('shouldn\'t add a point when a user is ++\'d without a conjunction', async function () {
it('should add a point when a user is ++\'d without a conjunction', async function () {
const emitSpy = sinon.spy(room.robot, 'emit');
room.user.say('matt.erickson', '@derp++ winning the business');
await new Promise((resolve) => setTimeout(resolve, 50));
expect(emitSpy).to.have.been.calledWith('plus-plus-failure', {
expect(room.messages[1][1]).to.match(/derp has 1 point for winning the business\.\n:birthday: Today is derp's hubotday! :birthday:/);
expect(emitSpy).not.to.have.been.calledWith('plus-plus-failure', {
notificationMessage: 'False positive detected in <#room1> from <@matt.erickson>:\n'
+ 'Pre-Message text: [false].\n'
+ 'Missing Conjunction: [true]\n'
Expand All @@ -84,7 +87,8 @@ describe('PlusPlus', function () {
});

const user = await db.collection('scores').findOne({ name: 'derp' });
expect(user).to.equal(undefined);
expect(user).not.to.equal(undefined);
expect(user.score).to.equal(1);
});

it('should add a point when a user is :clap:\'d', async function () {
Expand Down Expand Up @@ -147,11 +151,14 @@ describe('PlusPlus', function () {
);
});

it('shouldn\'t add a point to user with (sans) conjunction reason', async function () {
it('should add a point to user with (sans) conjunction reason', async function () {
const emitSpy = sinon.spy(room.robot, 'emit');
room.user.say('derp', '@matt.erickson++ gawd you\'re awesome');
await new Promise((resolve) => setTimeout(resolve, 60));
expect(emitSpy).to.have.been.calledWith('plus-plus-failure', {
expect(room.messages[1][1]).to.match(
/<@matt\.erickson> has 228 points, 1 of which is for gawd you're awesome./,
);
expect(emitSpy).not.to.have.been.calledWith('plus-plus-failure', {
notificationMessage: 'False positive detected in <#room1> from <@derp>:\n'
+ 'Pre-Message text: [false].\n'
+ 'Missing Conjunction: [true]\n'
Expand Down Expand Up @@ -182,6 +189,23 @@ describe('PlusPlus', function () {
const user = await db.collection('scores').findOne({ name: 'derp' });
expect(user.score).to.equal(-1);
});

it('shouldn\'t remove a point when a user is ++\'d with pre-text and no conjunction', async function () {
const emitSpy = sinon.spy(room.robot, 'emit');
room.user.say('matt.erickson', 'hello, @derp -- i have no idea what you are doing');
await new Promise((resolve) => setTimeout(resolve, 50));
expect(emitSpy).to.have.been.calledWith('plus-plus-failure', {
notificationMessage: 'False positive detected in <#room1> from <@matt.erickson>:\n'
+ 'Pre-Message text: [true].\n'
+ 'Missing Conjunction: [true]\n'
+ '\n'
+ 'hello, @derp -- i have no idea what you are doing',
room: 'room1',
});

const user = await db.collection('scores').findOne({ name: 'derp' });
expect(user).to.equal(undefined);
});
});
});

Expand Down

0 comments on commit 099e339

Please sign in to comment.