From 0fdc7f632e12e732c8e3e753891016f81321fd67 Mon Sep 17 00:00:00 2001 From: Riley Childs Date: Tue, 11 Dec 2018 20:31:35 -0600 Subject: [PATCH 01/42] Update app.json --- app.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.json b/app.json index c9f38dc..e3da633 100644 --- a/app.json +++ b/app.json @@ -2,7 +2,7 @@ "name": "Working PlusPlus++", "description": "Like plusplus.chat, but one that actually works, because you can host it yourself 😉", "website": "https://github.com/tdmalone/working-plusplus", - "repository": "https://github.com/tdmalone/working-plusplus", + "repository": "https://github.com/rowdychildren/working-plusplus", "keywords": [ "slack", "karma" From 70aec76d515ddc450b9afa6815776bb1b40f29f9 Mon Sep 17 00:00:00 2001 From: Riley Childs Date: Tue, 11 Dec 2018 20:41:31 -0600 Subject: [PATCH 02/42] Update messages.js --- src/messages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/messages.js b/src/messages.js index c0245ff..fbb481b 100644 --- a/src/messages.js +++ b/src/messages.js @@ -96,7 +96,7 @@ const getRandomMessage = ( operation, item, score = 0 ) => { switch ( operation ) { case operations.MINUS: case operations.PLUS: - format = ' ** is now on point.'; + format = ' ** has point.'; break; case operations.SELF: From 1a01a51f14c39dc6bcdbb64d804de8452b033060 Mon Sep 17 00:00:00 2001 From: Riley Childs Date: Tue, 11 Dec 2018 20:46:09 -0600 Subject: [PATCH 03/42] Update events.js --- src/events.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/events.js b/src/events.js index 1611268..6e64a35 100644 --- a/src/events.js +++ b/src/events.js @@ -98,8 +98,8 @@ const sendHelp = ( event ) => { '• `<@' + botUserID + '> help`: Display this message\n\n' + 'You\'ll need to invite me to a channel before I can recognise ' + '`++` and `--` commands in it.\n\n' + - 'If you\'re a developer, you can teach me new things! ' + - 'See to get started.' + 'If you\'re a developer, you can teach me new things! :awwww_yeah: ' + ); return slack.sendMessage( message, event.channel ); From 48b8296c4262da64460f4a6e7f7158bed0c28342 Mon Sep 17 00:00:00 2001 From: Riley Childs Date: Tue, 11 Dec 2018 20:47:16 -0600 Subject: [PATCH 04/42] Update leaderboard.js --- src/leaderboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/leaderboard.js b/src/leaderboard.js index 0389360..a232011 100644 --- a/src/leaderboard.js +++ b/src/leaderboard.js @@ -92,7 +92,7 @@ const rankItems = async( topScores, itemType = 'users', format = 'slack' ) => { // If this is the first item, it's the winner! if ( ! items.length ) { - output += ' ' + ( isUser ? ':muscle:' : ':tada:' ); + output += ' ' + ( isUser ? ':hotdogs:' : ':pepe:' ); } break; From 1a611694c4836734fe50d329fc4340e14d8e0067 Mon Sep 17 00:00:00 2001 From: Riley Childs Date: Tue, 11 Dec 2018 21:25:00 -0600 Subject: [PATCH 05/42] Update points.js --- src/points.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/points.js b/src/points.js index abc201b..2af1a33 100644 --- a/src/points.js +++ b/src/points.js @@ -75,14 +75,14 @@ const updateScore = async( item, operation ) => { // Atomically record the action. // TODO: Fix potential SQL injection issues here, even though we know the input should be safe. await dbClient.query( '\ - INSERT INTO ' + scoresTableName + ' VALUES (\'' + item + '\', ' + operation + '1) \ + INSERT INTO ' + scoresTableName + ' VALUES (\'' + item.toLowerCase() + '\', ' + operation + '1) \ ON CONFLICT (item) DO UPDATE SET score = ' + scoresTableName + '.score ' + operation + ' 1; \ ' ); // Get the new value. // TODO: Fix potential SQL injection issues here, even though we know the input should be safe. const dbSelect = await dbClient.query( '\ - SELECT score FROM ' + scoresTableName + ' WHERE item = \'' + item + '\'; \ + SELECT score FROM ' + scoresTableName + ' WHERE item = \'' + item.toLowerCase() + '\'; \ ' ); await dbClient.release(); From fc95a3c41180a5ffd61be16cc5d64d1ebc618efc Mon Sep 17 00:00:00 2001 From: Riley Childs Date: Tue, 11 Dec 2018 22:46:43 -0600 Subject: [PATCH 06/42] whoops --- src/points.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/points.js b/src/points.js index 2af1a33..d00a5f7 100644 --- a/src/points.js +++ b/src/points.js @@ -75,14 +75,14 @@ const updateScore = async( item, operation ) => { // Atomically record the action. // TODO: Fix potential SQL injection issues here, even though we know the input should be safe. await dbClient.query( '\ - INSERT INTO ' + scoresTableName + ' VALUES (\'' + item.toLowerCase() + '\', ' + operation + '1) \ + INSERT INTO ' + scoresTableName + ' VALUES (\'' + item.toUpperCase() + '\', ' + operation + '1) \ ON CONFLICT (item) DO UPDATE SET score = ' + scoresTableName + '.score ' + operation + ' 1; \ ' ); // Get the new value. // TODO: Fix potential SQL injection issues here, even though we know the input should be safe. const dbSelect = await dbClient.query( '\ - SELECT score FROM ' + scoresTableName + ' WHERE item = \'' + item.toLowerCase() + '\'; \ + SELECT score FROM ' + scoresTableName + ' WHERE item = \'' + item.toUpperCase() + '\'; \ ' ); await dbClient.release(); From c9b3f951c6eb60766bfc36a6f27d4ce32c646100 Mon Sep 17 00:00:00 2001 From: Riley Childs Date: Wed, 12 Dec 2018 11:48:26 -0600 Subject: [PATCH 07/42] added support for emojji --- src/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers.js b/src/helpers.js index b5dfeed..e881125 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -61,7 +61,7 @@ const extractCommand = ( message, commands ) => { * (i.e. + or -). */ const extractPlusMinusEventData = ( text ) => { - const data = text.match( /@([A-Za-z0-9]+?)>?\s*(\+{2}|-{2}|—{1})/ ); + const data = text.match( /@([A-Za-z0-9:-_]+?)>?\s*(\+{2}|-{2}|—{1})/ ); if ( ! data ) { return false; From 6e82a1e996ed352a87fc00d20219fe8b8b59d3ba Mon Sep 17 00:00:00 2001 From: Riley Childs Date: Wed, 12 Dec 2018 17:31:29 -0600 Subject: [PATCH 08/42] Update helpers.js --- src/helpers.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/helpers.js b/src/helpers.js index e881125..d9b844a 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -60,6 +60,16 @@ const extractCommand = ( message, commands ) => { * 'operation' being done on it - expressed as a valid mathematical operation * (i.e. + or -). */ +const extractAllEventData = ( text ) => { + const data = text.match( /@([A-Za-z0-9:-_]+?)>?\s*(\+{2}|-{2}|—{1})/g ); + + if ( ! data ) { + return false; + } + + return data; + +}; // ExtractPlusMinusEventData. const extractPlusMinusEventData = ( text ) => { const data = text.match( /@([A-Za-z0-9:-_]+?)>?\s*(\+{2}|-{2}|—{1})/ ); From cc720b2976011e86fe15c84dbc791b781b0b108f Mon Sep 17 00:00:00 2001 From: Riley Childs Date: Wed, 12 Dec 2018 17:38:59 -0600 Subject: [PATCH 09/42] Update events.js --- src/events.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/events.js b/src/events.js index 6e64a35..d0d5ada 100644 --- a/src/events.js +++ b/src/events.js @@ -122,7 +122,8 @@ const handlers = { message: ( event ) => { // Extract the relevant data from the message text. - const { item, operation } = helpers.extractPlusMinusEventData( event.text ); + for (let theitem of helpers.extractAllEventData(event.text)) { + const { item, operation } = helpers.extractPlusMinusEventData( theitem ); if ( ! item || ! operation ) { return false; @@ -136,7 +137,7 @@ const handlers = { // Otherwise, let's go! return handlePlusMinus( item, operation, event.channel ); - + } }, // Message event. /** From 3df78b2cedb8d9ec9fe71f93b04323d9c3f1639e Mon Sep 17 00:00:00 2001 From: Riley Childs Date: Wed, 12 Dec 2018 17:47:51 -0600 Subject: [PATCH 10/42] Update helpers.js --- src/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers.js b/src/helpers.js index d9b844a..05618cf 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -67,7 +67,7 @@ const extractAllEventData = ( text ) => { return false; } - return data; + return Object.values(data); }; // ExtractPlusMinusEventData. const extractPlusMinusEventData = ( text ) => { From 0df6fe723b8ce9ec025c712c93c3e57b962c665f Mon Sep 17 00:00:00 2001 From: Riley Childs Date: Wed, 12 Dec 2018 17:49:32 -0600 Subject: [PATCH 11/42] Update helpers.js --- src/helpers.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/helpers.js b/src/helpers.js index 05618cf..bc10a18 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -242,5 +242,6 @@ module.exports = { isTimeBasedTokenStillValid, isUser, maybeLinkItem, - render + render, + extractAllEventData }; From c3d3f63f80277f6ace6189601b26c151c2b65586 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 11:56:26 -0500 Subject: [PATCH 12/42] added = --- src/messages.js | 4 ++++ src/operations.js | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/messages.js b/src/messages.js index c0245ff..74767cb 100644 --- a/src/messages.js +++ b/src/messages.js @@ -102,6 +102,10 @@ const getRandomMessage = ( operation, item, score = 0 ) => { case operations.SELF: format = ' '; break; + + case operations.equal: + format = '** is currently at point.'; + break; default: throw Error ( 'Invalid operation: ' + operation ); diff --git a/src/operations.js b/src/operations.js index 6805aa1..3b81fe1 100644 --- a/src/operations.js +++ b/src/operations.js @@ -8,6 +8,7 @@ const operations = { PLUS: 'plus', MINUS: 'minus', SELF: 'selfPlus' + EQUAL: 'equal' }; /** @@ -23,6 +24,7 @@ const getOperationName = ( operation ) => { switch ( operation ) { case '+': operationName = operations.PLUS; break; case '-': operationName = operations.MINUS; break; + case '=': operationName = operations.EQUAL; break; } /* eslint-enable max-statements-per-line */ From 5150f5402d952df55ba589eca56f29eaa44973c6 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 11:57:29 -0500 Subject: [PATCH 13/42] added , --- src/operations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operations.js b/src/operations.js index 3b81fe1..3abcf2d 100644 --- a/src/operations.js +++ b/src/operations.js @@ -7,7 +7,7 @@ const operations = { PLUS: 'plus', MINUS: 'minus', - SELF: 'selfPlus' + SELF: 'selfPlus', EQUAL: 'equal' }; From ffbc86db972c6a0448a33483076b8550e75910fa Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 12:01:26 -0500 Subject: [PATCH 14/42] updated handler --- src/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers.js b/src/helpers.js index b5dfeed..a1c1211 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -61,7 +61,7 @@ const extractCommand = ( message, commands ) => { * (i.e. + or -). */ const extractPlusMinusEventData = ( text ) => { - const data = text.match( /@([A-Za-z0-9]+?)>?\s*(\+{2}|-{2}|—{1})/ ); + const data = text.match( /@([A-Za-z0-9]+?)>?\s*(\+{2}|-{2}|—{1}|={2})/ ); if ( ! data ) { return false; From 23658eacdd24214444737b367efaaca39be58ded Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 12:21:45 -0500 Subject: [PATCH 15/42] fix casing --- src/messages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/messages.js b/src/messages.js index 74767cb..c7d24d5 100644 --- a/src/messages.js +++ b/src/messages.js @@ -103,7 +103,7 @@ const getRandomMessage = ( operation, item, score = 0 ) => { format = ' '; break; - case operations.equal: + case operations.EQUAL: format = '** is currently at point.'; break; From 461c89897841be82a31201b96d6b39d4092cc976 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 13:18:48 -0500 Subject: [PATCH 16/42] added = --- src/events.js | 24 ++++++++++++++++++++++++ src/messages.js | 4 ++-- src/points.js | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/events.js b/src/events.js index 1611268..97e5cd9 100644 --- a/src/events.js +++ b/src/events.js @@ -50,6 +50,26 @@ const handlePlusMinus = async( item, operation, channel ) => { return slack.sendMessage( message, channel ); }; +/** + * Handles a = against a user, and then notifies the channel of the new score. + * + * @param {string} item The Slack user ID (if user) or name (if thing) of the item being + * operated on. + * @param {string} operation The mathematical operation performed on the item's score. + * @param {object} channel The ID of the channel (Cxxxxxxxx for public channels or Gxxxxxxxx for + * private channels - aka groups) that the message was sent from. + * @return {Promise} A Promise to send a Slack message back to the requesting channel after the + * points have been updated. + */ +const handlePlusEqual = async( item, operation, channel ) => { + const score = await points.GetScore( item, operation ), + operationName = operations.getOperationName( operation ), + message = messages.getRandomMessage( operationName, item, score ); + + return slack.sendMessage( message, channel ); +}; + + /** * Sends a random thank you message to the requesting channel. * @@ -133,6 +153,10 @@ const handlers = { handleSelfPlus( event.user, event.channel ); return false; } + + if ( '=' === operation ) { + return handlePlusEqual( item, operation, event.channel ); + } // Otherwise, let's go! return handlePlusMinus( item, operation, event.channel ); diff --git a/src/messages.js b/src/messages.js index c7d24d5..1ef8697 100644 --- a/src/messages.js +++ b/src/messages.js @@ -104,8 +104,8 @@ const getRandomMessage = ( operation, item, score = 0 ) => { break; case operations.EQUAL: - format = '** is currently at point.'; - break; + format = '** is currently at point.'; + break; default: throw Error ( 'Invalid operation: ' + operation ); diff --git a/src/points.js b/src/points.js index abc201b..0b48ddb 100644 --- a/src/points.js +++ b/src/points.js @@ -93,7 +93,44 @@ const updateScore = async( item, operation ) => { }; // UpdateScore. +/** + * Gets score + * into the database with an assumed initial score of 0. + * + * This function also sets up the database if it is not already ready, including creating the + * scores table and activating the Postgres case-insensitive extension. + * + * @param {string} item The Slack user ID (if user) or name (if thing) of the item being + * operated on. + * @param {string} operation The mathematical operation performed on the item's score. + * @return {int} The item's new score after the update has been applied. + */ +const GetScore = async( item, operation ) => { + + // Connect to the DB, and create a table if it's not yet there. + // We also set up the citext extension, so that we can easily be case insensitive. + const dbClient = await postgres.connect(); + await dbClient.query( '\ + CREATE EXTENSION IF NOT EXISTS citext; \ + CREATE TABLE IF NOT EXISTS ' + scoresTableName + ' (item CITEXT PRIMARY KEY, score INTEGER); \ + ' ); + + // Get the new value. + // TODO: Fix potential SQL injection issues here, even though we know the input should be safe. + const dbSelect = await dbClient.query( '\ + SELECT score FROM ' + scoresTableName + ' WHERE item = \'' + item + '\'; \ + ' ); + + await dbClient.release(); + const score = dbSelect.rows[0].score; + + console.log( item + ' now on ' + score ); + return score; + +}; // UpdateScore. + module.exports = { retrieveTopScores, - updateScore + updateScore, + GetScore }; From 407d1bd0f50a0504379c3f5c27bca4bfa1be0a7b Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 13:25:05 -0500 Subject: [PATCH 17/42] updated messages --- src/messages.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/messages.js b/src/messages.js index 1ef8697..b2f12de 100644 --- a/src/messages.js +++ b/src/messages.js @@ -62,6 +62,20 @@ messages[ operations.MINUS ] = [ } ]; +messages[ operations.EQUAL ] = [ + { + probability: 100, + set: [ + 'How is', + 'Why is' + ] + }, + { + probability: 1, + set: [ ':shifty:' ] + } +]; + messages[ operations.SELF ] = [ { probability: 100, @@ -104,7 +118,7 @@ const getRandomMessage = ( operation, item, score = 0 ) => { break; case operations.EQUAL: - format = '** is currently at point.'; + format = ' ** currently at point.'; break; default: From 2eb44ba8af817b6a37157f5fc08326f118abd982 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 13:38:08 -0500 Subject: [PATCH 18/42] removed spaces --- src/events.js | 1 - src/messages.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/events.js b/src/events.js index 97e5cd9..64159e2 100644 --- a/src/events.js +++ b/src/events.js @@ -69,7 +69,6 @@ const handlePlusEqual = async( item, operation, channel ) => { return slack.sendMessage( message, channel ); }; - /** * Sends a random thank you message to the requesting channel. * diff --git a/src/messages.js b/src/messages.js index b2f12de..4b5de5b 100644 --- a/src/messages.js +++ b/src/messages.js @@ -116,8 +116,8 @@ const getRandomMessage = ( operation, item, score = 0 ) => { case operations.SELF: format = ' '; break; - - case operations.EQUAL: + + case operations.EQUAL: format = ' ** currently at point.'; break; From 8991055231f902979fbcbd5ce674323d13386003 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 13:40:50 -0500 Subject: [PATCH 19/42] test remove operation --- src/events.js | 4 ++-- src/points.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/events.js b/src/events.js index 64159e2..410444f 100644 --- a/src/events.js +++ b/src/events.js @@ -152,9 +152,9 @@ const handlers = { handleSelfPlus( event.user, event.channel ); return false; } - + if ( '=' === operation ) { - return handlePlusEqual( item, operation, event.channel ); + return handlePlusEqual( item, event.channel ); } // Otherwise, let's go! diff --git a/src/points.js b/src/points.js index 0b48ddb..6dc914f 100644 --- a/src/points.js +++ b/src/points.js @@ -105,7 +105,7 @@ const updateScore = async( item, operation ) => { * @param {string} operation The mathematical operation performed on the item's score. * @return {int} The item's new score after the update has been applied. */ -const GetScore = async( item, operation ) => { +const GetScore = async( item ) => { // Connect to the DB, and create a table if it's not yet there. // We also set up the citext extension, so that we can easily be case insensitive. From 56bbf10870d3e37b8c250f01ef30bf08e9255c97 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 13:45:44 -0500 Subject: [PATCH 20/42] Revert "test remove operation" This reverts commit 8991055231f902979fbcbd5ce674323d13386003. --- src/events.js | 4 ++-- src/points.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/events.js b/src/events.js index 410444f..64159e2 100644 --- a/src/events.js +++ b/src/events.js @@ -152,9 +152,9 @@ const handlers = { handleSelfPlus( event.user, event.channel ); return false; } - + if ( '=' === operation ) { - return handlePlusEqual( item, event.channel ); + return handlePlusEqual( item, operation, event.channel ); } // Otherwise, let's go! diff --git a/src/points.js b/src/points.js index 6dc914f..0b48ddb 100644 --- a/src/points.js +++ b/src/points.js @@ -105,7 +105,7 @@ const updateScore = async( item, operation ) => { * @param {string} operation The mathematical operation performed on the item's score. * @return {int} The item's new score after the update has been applied. */ -const GetScore = async( item ) => { +const GetScore = async( item, operation ) => { // Connect to the DB, and create a table if it's not yet there. // We also set up the citext extension, so that we can easily be case insensitive. From 08fb59f4e6eb8c3765e4ce17e886ff65917133b4 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 14:18:28 -0500 Subject: [PATCH 21/42] test error fix when asking points of bot --- src/events.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/events.js b/src/events.js index 64159e2..784a3f5 100644 --- a/src/events.js +++ b/src/events.js @@ -125,6 +125,10 @@ const sendHelp = ( event ) => { }; // SendHelp. +const donothing = ( event ) => { + +}; // donothing + const handlers = { /** @@ -181,7 +185,10 @@ const handlers = { help: sendHelp, thx: sayThankyou, thanks: sayThankyou, - thankyou: sayThankyou + thankyou: sayThankyou, + ++: donothing, + --: donothing, + ==: donothing }; const validCommands = Object.keys( appCommandHandlers ), From 685a1aaa33785be507c2ababea29228880ac98d4 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 14:30:39 -0500 Subject: [PATCH 22/42] removed donothing --- src/events.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/events.js b/src/events.js index 784a3f5..f40317f 100644 --- a/src/events.js +++ b/src/events.js @@ -125,10 +125,6 @@ const sendHelp = ( event ) => { }; // SendHelp. -const donothing = ( event ) => { - -}; // donothing - const handlers = { /** @@ -186,9 +182,9 @@ const handlers = { thx: sayThankyou, thanks: sayThankyou, thankyou: sayThankyou, - ++: donothing, - --: donothing, - ==: donothing + ++: handlePlusMinus, + --: handlePlusMinus, + ==: handlePlusEqual }; const validCommands = Object.keys( appCommandHandlers ), From 1533c3e776c6b565024864f2b86900d3806b863d Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 14:36:48 -0500 Subject: [PATCH 23/42] add quotes --- src/events.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/events.js b/src/events.js index f40317f..de73579 100644 --- a/src/events.js +++ b/src/events.js @@ -125,6 +125,10 @@ const sendHelp = ( event ) => { }; // SendHelp. +const donothing = ( event ) => { + +}; // donothing + const handlers = { /** @@ -182,9 +186,9 @@ const handlers = { thx: sayThankyou, thanks: sayThankyou, thankyou: sayThankyou, - ++: handlePlusMinus, - --: handlePlusMinus, - ==: handlePlusEqual + '++': handlePlusMinus, + '--': handlePlusMinus, + '==': handlePlusEqual }; const validCommands = Object.keys( appCommandHandlers ), From c9f1db850f41a832b21668a1c2c60ba7382c804a Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 14:56:28 -0500 Subject: [PATCH 24/42] rebase messages --- src/messages.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/messages.js b/src/messages.js index 4b5de5b..70006ab 100644 --- a/src/messages.js +++ b/src/messages.js @@ -33,7 +33,8 @@ messages[ operations.PLUS ] = [ 'Well, well!', 'Well played.', 'Sincerest congratulations.', - 'Delicious.' + 'Delicious.', + 'SOMEONE GET THIS PATRIOT A COAT' ] }, { @@ -53,7 +54,8 @@ messages[ operations.MINUS ] = [ 'Ouch.', 'Oh là là.', 'Oh.', - 'Condolences.' + 'Condolences.', + 'THE WALL JUST GOT 10 FEET HIGHER' ] }, { @@ -110,7 +112,7 @@ const getRandomMessage = ( operation, item, score = 0 ) => { switch ( operation ) { case operations.MINUS: case operations.PLUS: - format = ' ** is now on point.'; + format = ' ** has point.'; break; case operations.SELF: @@ -165,4 +167,4 @@ const getRandomMessage = ( operation, item, score = 0 ) => { module.exports = { messages, getRandomMessage -}; +}; \ No newline at end of file From cf86fb732fe2c90bb886a3edb39e38f27397f92c Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 14:59:48 -0500 Subject: [PATCH 25/42] moved text --- src/messages.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/messages.js b/src/messages.js index 70006ab..df42e39 100644 --- a/src/messages.js +++ b/src/messages.js @@ -18,6 +18,9 @@ messages[ operations.PLUS ] = [ { probability: 100, set: [ + 'Sincerest congratulations.', + 'Delicious.', + 'SOMEONE GET THIS PATRIOT A COAT', 'Congrats!', 'Got it!', 'Bravo.', From b1b52d7f2a2a4fe048637c7b5ec86bfceed10763 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 15:02:29 -0500 Subject: [PATCH 26/42] undo last --- src/messages.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/messages.js b/src/messages.js index df42e39..70006ab 100644 --- a/src/messages.js +++ b/src/messages.js @@ -18,9 +18,6 @@ messages[ operations.PLUS ] = [ { probability: 100, set: [ - 'Sincerest congratulations.', - 'Delicious.', - 'SOMEONE GET THIS PATRIOT A COAT', 'Congrats!', 'Got it!', 'Bravo.', From 14cf312d42c018d8d9bc209a68b9c518d3efd912 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 15:05:45 -0500 Subject: [PATCH 27/42] added one line --- src/messages.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/messages.js b/src/messages.js index 70006ab..d75d3bd 100644 --- a/src/messages.js +++ b/src/messages.js @@ -55,7 +55,8 @@ messages[ operations.MINUS ] = [ 'Oh là là.', 'Oh.', 'Condolences.', - 'THE WALL JUST GOT 10 FEET HIGHER' + 'THE WALL JUST GOT 10 FEET HIGHER', + 'oh.' ] }, { From c08de6563156a38f17baa75e7dab5a835ae8c404 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 15:09:53 -0500 Subject: [PATCH 28/42] revert others --- src/messages.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/messages.js b/src/messages.js index d75d3bd..2f86f71 100644 --- a/src/messages.js +++ b/src/messages.js @@ -33,8 +33,7 @@ messages[ operations.PLUS ] = [ 'Well, well!', 'Well played.', 'Sincerest congratulations.', - 'Delicious.', - 'SOMEONE GET THIS PATRIOT A COAT' + 'Delicious.' ] }, { @@ -54,9 +53,7 @@ messages[ operations.MINUS ] = [ 'Ouch.', 'Oh là là.', 'Oh.', - 'Condolences.', - 'THE WALL JUST GOT 10 FEET HIGHER', - 'oh.' + 'Condolences.' ] }, { From f85f8472e80296e89f50040e3baee1e807d8a075 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 15:22:14 -0500 Subject: [PATCH 29/42] changed to creater/master --- app.json | 2 +- src/events.js | 7 ++----- src/helpers.js | 13 +------------ 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/app.json b/app.json index e3da633..c9f38dc 100644 --- a/app.json +++ b/app.json @@ -2,7 +2,7 @@ "name": "Working PlusPlus++", "description": "Like plusplus.chat, but one that actually works, because you can host it yourself 😉", "website": "https://github.com/tdmalone/working-plusplus", - "repository": "https://github.com/rowdychildren/working-plusplus", + "repository": "https://github.com/tdmalone/working-plusplus", "keywords": [ "slack", "karma" diff --git a/src/events.js b/src/events.js index 0217a53..6169132 100644 --- a/src/events.js +++ b/src/events.js @@ -117,7 +117,8 @@ const sendHelp = ( event ) => { '• `<@' + botUserID + '> help`: Display this message\n\n' + 'You\'ll need to invite me to a channel before I can recognise ' + '`++` and `--` commands in it.\n\n' + - 'If you\'re a developer, you can teach me new things! :awwww_yeah: ' + 'If you\'re a developer, you can teach me new things! ' + + 'See to get started.' ); @@ -125,10 +126,6 @@ const sendHelp = ( event ) => { }; // SendHelp. -const donothing = ( event ) => { - -}; // donothing - const handlers = { /** diff --git a/src/helpers.js b/src/helpers.js index 1066546..d50c09a 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -60,16 +60,6 @@ const extractCommand = ( message, commands ) => { * 'operation' being done on it - expressed as a valid mathematical operation * (i.e. + or -). */ -const extractAllEventData = ( text ) => { - const data = text.match( /@([A-Za-z0-9:-_]+?)>?\s*(\+{2}|-{2}|—{1})/g ); - - if ( ! data ) { - return false; - } - - return Object.values(data); - -}; // ExtractPlusMinusEventData. const extractPlusMinusEventData = ( text ) => { const data = text.match( /@([A-Za-z0-9:-_]+?)>?\s*(\+{2}|-{2}|—{1})/ ); @@ -244,6 +234,5 @@ module.exports = { isTimeBasedTokenStillValid, isUser, maybeLinkItem, - render, - extractAllEventData + render }; From 9980aafe35eb42cc34238ace873bc218e5c90f9a Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 15:25:04 -0500 Subject: [PATCH 30/42] further rebase --- src/events.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/events.js b/src/events.js index 6169132..f99e2a8 100644 --- a/src/events.js +++ b/src/events.js @@ -119,7 +119,6 @@ const sendHelp = ( event ) => { '`++` and `--` commands in it.\n\n' + 'If you\'re a developer, you can teach me new things! ' + 'See to get started.' - ); return slack.sendMessage( message, event.channel ); @@ -142,8 +141,7 @@ const handlers = { message: ( event ) => { // Extract the relevant data from the message text. - for (let theitem of helpers.extractAllEventData(event.text)) { - const { item, operation } = helpers.extractPlusMinusEventData( theitem ); + const { item, operation } = helpers.extractPlusMinusEventData( event.text ); if ( ! item || ! operation ) { return false; From dd6b91f64686ba3a2e9bf6eb25ec5ecdcb44d210 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 15:37:11 -0500 Subject: [PATCH 31/42] fixing some "errors" --- src/messages.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/messages.js b/src/messages.js index 2f86f71..b3322f1 100644 --- a/src/messages.js +++ b/src/messages.js @@ -117,9 +117,9 @@ const getRandomMessage = ( operation, item, score = 0 ) => { format = ' '; break; - case operations.EQUAL: - format = ' ** currently at point.'; - break; + case operations.EQUAL: + format = ' ** currently at point.'; + break; default: throw Error ( 'Invalid operation: ' + operation ); @@ -165,4 +165,4 @@ const getRandomMessage = ( operation, item, score = 0 ) => { module.exports = { messages, getRandomMessage -}; \ No newline at end of file +}; From 6e00348210a037b4314a74bdc02e653b74a86a77 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 15:48:56 -0500 Subject: [PATCH 32/42] extra } --- src/events.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/events.js b/src/events.js index f99e2a8..c587f87 100644 --- a/src/events.js +++ b/src/events.js @@ -159,8 +159,7 @@ const handlers = { // Otherwise, let's go! return handlePlusMinus( item, operation, event.channel ); - } - }, // Message event. + } // Message event. /** * Handles 'app_mention' events sent from Slack, primarily by looking for known app commands, and From 64d28afe72d64ccb91e6b0e122d8691232bba86f Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 13 Dec 2018 16:28:22 -0500 Subject: [PATCH 33/42] missing comma --- src/events.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events.js b/src/events.js index c587f87..733c6fb 100644 --- a/src/events.js +++ b/src/events.js @@ -159,7 +159,7 @@ const handlers = { // Otherwise, let's go! return handlePlusMinus( item, operation, event.channel ); - } // Message event. + }, // Message event. /** * Handles 'app_mention' events sent from Slack, primarily by looking for known app commands, and From ce8a96b3c9c0d548cdba28855a977b126847d65d Mon Sep 17 00:00:00 2001 From: MattLParker Date: Thu, 13 Dec 2018 18:13:40 -0500 Subject: [PATCH 34/42] changed to uppercase --- src/helpers.js | 2 +- src/points.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index d50c09a..e014558 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -70,7 +70,7 @@ const extractPlusMinusEventData = ( text ) => { } return { - item: data[1], + item: data[1].toUpperCase(), operation: data[2].substring( 0, 1 ).replace( '—', '-' ) }; diff --git a/src/points.js b/src/points.js index e610495..0b48ddb 100644 --- a/src/points.js +++ b/src/points.js @@ -75,14 +75,14 @@ const updateScore = async( item, operation ) => { // Atomically record the action. // TODO: Fix potential SQL injection issues here, even though we know the input should be safe. await dbClient.query( '\ - INSERT INTO ' + scoresTableName + ' VALUES (\'' + item.toUpperCase() + '\', ' + operation + '1) \ + INSERT INTO ' + scoresTableName + ' VALUES (\'' + item + '\', ' + operation + '1) \ ON CONFLICT (item) DO UPDATE SET score = ' + scoresTableName + '.score ' + operation + ' 1; \ ' ); // Get the new value. // TODO: Fix potential SQL injection issues here, even though we know the input should be safe. const dbSelect = await dbClient.query( '\ - SELECT score FROM ' + scoresTableName + ' WHERE item = \'' + item.toUpperCase() + '\'; \ + SELECT score FROM ' + scoresTableName + ' WHERE item = \'' + item + '\'; \ ' ); await dbClient.release(); From da1509346357c98ba6bf33c07986989bfa93df91 Mon Sep 17 00:00:00 2001 From: MattLParker Date: Thu, 13 Dec 2018 18:16:51 -0500 Subject: [PATCH 35/42] Check without uppercase --- src/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers.js b/src/helpers.js index e014558..d50c09a 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -70,7 +70,7 @@ const extractPlusMinusEventData = ( text ) => { } return { - item: data[1].toUpperCase(), + item: data[1], operation: data[2].substring( 0, 1 ).replace( '—', '-' ) }; From 15a0098b9379be5ed15df9b8c04e2e89cd0a9ed4 Mon Sep 17 00:00:00 2001 From: MattLParker Date: Thu, 13 Dec 2018 19:02:18 -0500 Subject: [PATCH 36/42] added = --- src/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers.js b/src/helpers.js index d50c09a..a09bd09 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -62,7 +62,7 @@ const extractCommand = ( message, commands ) => { */ const extractPlusMinusEventData = ( text ) => { - const data = text.match( /@([A-Za-z0-9:-_]+?)>?\s*(\+{2}|-{2}|—{1})/ ); + const data = text.match( /@([A-Za-z0-9:-_]+?)>?\s*(\+{2}|-{2}|—{1}|={2})/ ); if ( ! data ) { From cc3e4b1f9119e2ea5419059b9857d523ee332d36 Mon Sep 17 00:00:00 2001 From: MattLParker Date: Thu, 13 Dec 2018 19:35:42 -0500 Subject: [PATCH 37/42] fixed spaces --- src/events.js | 2 +- src/helpers.js | 1 - src/messages.js | 4 ++-- src/points.js | 1 + 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/events.js b/src/events.js index 733c6fb..209eca5 100644 --- a/src/events.js +++ b/src/events.js @@ -152,7 +152,7 @@ const handlers = { handleSelfPlus( event.user, event.channel ); return false; } - + if ( '=' === operation ) { return handlePlusEqual( item, operation, event.channel ); } diff --git a/src/helpers.js b/src/helpers.js index a09bd09..e579655 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -64,7 +64,6 @@ const extractPlusMinusEventData = ( text ) => { const data = text.match( /@([A-Za-z0-9:-_]+?)>?\s*(\+{2}|-{2}|—{1}|={2})/ ); - if ( ! data ) { return false; } diff --git a/src/messages.js b/src/messages.js index b3322f1..d96f500 100644 --- a/src/messages.js +++ b/src/messages.js @@ -118,8 +118,8 @@ const getRandomMessage = ( operation, item, score = 0 ) => { break; case operations.EQUAL: - format = ' ** currently at point.'; - break; + format = ' ** currently at point.'; + break; default: throw Error ( 'Invalid operation: ' + operation ); diff --git a/src/points.js b/src/points.js index 0b48ddb..7adc168 100644 --- a/src/points.js +++ b/src/points.js @@ -109,6 +109,7 @@ const GetScore = async( item, operation ) => { // Connect to the DB, and create a table if it's not yet there. // We also set up the citext extension, so that we can easily be case insensitive. + operation = operation; const dbClient = await postgres.connect(); await dbClient.query( '\ CREATE EXTENSION IF NOT EXISTS citext; \ From ab34559324bb5c5cab22d2733b02f4596921e1f1 Mon Sep 17 00:00:00 2001 From: MattLParker Date: Thu, 13 Dec 2018 19:44:09 -0500 Subject: [PATCH 38/42] remove operation --- src/points.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/points.js b/src/points.js index 7adc168..6dc914f 100644 --- a/src/points.js +++ b/src/points.js @@ -105,11 +105,10 @@ const updateScore = async( item, operation ) => { * @param {string} operation The mathematical operation performed on the item's score. * @return {int} The item's new score after the update has been applied. */ -const GetScore = async( item, operation ) => { +const GetScore = async( item ) => { // Connect to the DB, and create a table if it's not yet there. // We also set up the citext extension, so that we can easily be case insensitive. - operation = operation; const dbClient = await postgres.connect(); await dbClient.query( '\ CREATE EXTENSION IF NOT EXISTS citext; \ From afa61a8eac561a81f971e68e8bcdbc4e1321d1c4 Mon Sep 17 00:00:00 2001 From: MattLParker Date: Thu, 13 Dec 2018 19:48:34 -0500 Subject: [PATCH 39/42] one last stupid space --- src/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers.js b/src/helpers.js index e579655..3ffd840 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -233,5 +233,5 @@ module.exports = { isTimeBasedTokenStillValid, isUser, maybeLinkItem, - render + render` }; From 37c8d2c6b018d98527bff5b2f2f32e5c065b662e Mon Sep 17 00:00:00 2001 From: MattLParker Date: Thu, 13 Dec 2018 19:48:59 -0500 Subject: [PATCH 40/42] oops --- src/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers.js b/src/helpers.js index 3ffd840..b638eaf 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -233,5 +233,5 @@ module.exports = { isTimeBasedTokenStillValid, isUser, maybeLinkItem, - render` + render }; From 5994f1da6ec2e2ebed02d6fb73ac04c627dc9eee Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 14 Dec 2018 08:28:35 -0500 Subject: [PATCH 41/42] added help, refactored to lowercase g in getScore --- src/events.js | 3 ++- src/points.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/events.js b/src/events.js index 209eca5..6f31095 100644 --- a/src/events.js +++ b/src/events.js @@ -62,7 +62,7 @@ const handlePlusMinus = async( item, operation, channel ) => { * points have been updated. */ const handlePlusEqual = async( item, operation, channel ) => { - const score = await points.GetScore( item, operation ), + const score = await points.getScore( item, operation ), operationName = operations.getOperationName( operation ), message = messages.getRandomMessage( operationName, item, score ); @@ -113,6 +113,7 @@ const sendHelp = ( event ) => { 'Sure, here\'s what I can do:\n\n' + '• `@Someone++`: Add points to a user or a thing\n' + '• `@Someone--`: Subtract points from a user or a thing\n' + + '• `@Someone==`: Gets current points from a user or a thing\n' + '• `<@' + botUserID + '> leaderboard`: Display the leaderboard\n' + '• `<@' + botUserID + '> help`: Display this message\n\n' + 'You\'ll need to invite me to a channel before I can recognise ' + diff --git a/src/points.js b/src/points.js index 6dc914f..a76f820 100644 --- a/src/points.js +++ b/src/points.js @@ -105,7 +105,7 @@ const updateScore = async( item, operation ) => { * @param {string} operation The mathematical operation performed on the item's score. * @return {int} The item's new score after the update has been applied. */ -const GetScore = async( item ) => { +const getScore = async( item ) => { // Connect to the DB, and create a table if it's not yet there. // We also set up the citext extension, so that we can easily be case insensitive. @@ -132,5 +132,5 @@ const GetScore = async( item ) => { module.exports = { retrieveTopScores, updateScore, - GetScore + getScore }; From 0f0d952c6a5912f43fb8043837309e5ed5c60559 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 14 Dec 2018 08:33:47 -0500 Subject: [PATCH 42/42] removed Site specific --- src/leaderboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/leaderboard.js b/src/leaderboard.js index a232011..0389360 100644 --- a/src/leaderboard.js +++ b/src/leaderboard.js @@ -92,7 +92,7 @@ const rankItems = async( topScores, itemType = 'users', format = 'slack' ) => { // If this is the first item, it's the winner! if ( ! items.length ) { - output += ' ' + ( isUser ? ':hotdogs:' : ':pepe:' ); + output += ' ' + ( isUser ? ':muscle:' : ':tada:' ); } break;