Skip to content
This repository was archived by the owner on Dec 10, 2022. It is now read-only.

Commit 20f464f

Browse files
committed
Merge branch 'dev'
* dev: (39 commits) Use the Slack bot's configured name for the web template title Add simple default message on receiving an unknown command Add 'help' and 'thankyou' commands' Update CHANGELOG after merge of feature/leaderboard Minor: remove empty tests that weren't supposed to make it in yet Hotfix: prevent missing request data in events test Minor cleanups, incl docs Rename leaderboard retrieval functions + simplify HTML rendering by only requiring template filename to be passed Rename 'send' functions to 'slack' because they now do more than just sending Minor tweaks and cleanups Leaderboard: complete web-viewable leaderboard with user name retrieval Hotfix: ensure token on verification is an integer to avoid concatenation WIP: Minor tweaks and fixes for web leaderboard WIP: Templates and structure for full web-viewable leaderboard Leaderboard: split ranking into separate function Leaderboard: extract URL + token building functionality + add tests WIP: Leaderboard functionality (working, no tests, no 'full leaderboard') Minor docs Simplify integration tests to not actually partially be end-to-end tests Add function to retrieve top scores from the DB ...
2 parents 646ad49 + 94d43ba commit 20f464f

33 files changed

+2265
-716
lines changed

CHANGELOG.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
# Changelog
2-
All notable changes to this project will be documented in this file.
2+
All notable changes to this project will be documented in this file.
33
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
44

55
## [Unreleased]
66

7+
### Added
8+
- Leaderboard functionality when `@WorkingPlusPlus leaderboard` is sent (requires additional app permissions - see step 6 of the installation instructions), including a link to a full web-based leaderboard with a time-based token to protect your team's data
9+
- Help message when `@WorkingPlusPlus help` is sent (requires the same additional app permissions as above)
10+
- Contributors: a raft of new helper functions including `isUser`, `isPlural` and many more
11+
- Contributors: additional tests to cover all previously added functionality (leaderboard functionality is not covered yet)
12+
13+
### Changed
14+
- Contributors: another set of significant structural re-organisations to set the app up for handling more 'direct commands' in future
15+
16+
### Fixed
17+
- Prevented +- or -+ from being interpreted as valid commands ([`005b69c`](https://github.com/tdmalone/working-plusplus/commit/005b69c6b297abf5c1014fd2dedc7db9e54b2900))
18+
719
## [0.0.3] - 2018-08-11
820

921
### Added
@@ -26,7 +38,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
2638
- Contributors: quite a bit of reorganising to make it easier both to grow and to test the app
2739

2840
### Fixed
29-
- Scores of -1 are now referred to as -1 point, rather than -1 points
41+
- Scores of -1 are now referred to as -1 point, rather than -1 points ([`d7d92be`](https://github.com/tdmalone/working-plusplus/commit/d7d92be0cd31aed26afcac1d189d17381330f418))
3042

3143
## [0.0.1] - 2018-08-06
3244

CONTRIBUTING.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ You can run just a subset of tests:
5353
- Integration tests with `yarn integration-tests`
5454
- End-to-end tests with `yarn e2e-tests`
5555

56-
It is normal to see _some_ errors while running the integration and end-to-end tests, but keep an eye on the exit code of the process to determine if it is successful (run `echo $?` immediately after running `yarn test` - you're looking for an exit code of `0` for a pass).
57-
5856
You can modify the default testing behaviour by adjusting the relevant `scripts` in [`package.json`](package.json) or in some cases by passing additional [Jest configuration parameters](https://jestjs.io/docs/en/configuration.html) at the end of the test commands above.
5957

6058
If you come across annoying *stylistic* linting rules, feel free to [change them](https://eslint.org/docs/rules/) in [`.eslintrc.js`](.eslintrc.js) as part of your pull request, providing they don't cause an adverse effect on existing code.

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build Status](https://travis-ci.com/tdmalone/working-plusplus.svg?branch=master)](https://travis-ci.com/tdmalone/working-plusplus)
44
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d0d9b6c1d1c4430e9fad61bb60b5dc4e)](https://www.codacy.com/project/tdmalone/working-plusplus/dashboard)
5-
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/d0d9b6c1d1c4430e9fad61bb60b5dc4e)](https://www.codacy.com/project/tdmalone/working-plusplus/files)
5+
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/d0d9b6c1d1c4430e9fad61bb60b5dc4e)](https://www.codacy.com/app/tdmalone/working-plusplus/files)
66

77
Like [plusplus.chat](https://plusplus.chat/), except this one actually works - because you can host it yourself! 😉
88

@@ -68,16 +68,40 @@ Completely open source, so do with it what you like. Or if you don't want to mak
6868

6969
Via *Event Subscriptions* in the left menu. After switching on, enter your new Heroku app address - eg. `https://my-plusplus.herokuapp.com` - as the request URL.
7070

71-
Scroll down and, under *Subscribe to Bot Events*, add the `message.channels` and `message.groups` events, then click *Save Changes*.
71+
Scroll down and, under *Subscribe to Bot Events*, select the relevant events for the features you want the app to support:
72+
73+
* Select `message.channels` to support all general features in _public_ channels it is invited to
74+
* Select `message.groups` to support all general features in _private_ channels it is invited to
75+
* Select `app_mention` to support extended features such as leaderboards
76+
77+
Finally, click *Save Changes*. If you wish, you can come back to this screen later and add or change the events the app handles.
7278

7379
1. **Invite your new bot to any channel in your Slack team.**
7480

7581
1. **Think of someone who's been awesome lately and send `@Someone++`!**
7682

77-
## Detailed Instructions
83+
### More Information
7884

7985
Further instructions, such as hosting elsewhere, upgrading, etc. are coming soon.
8086

87+
## Usage
88+
89+
**Working PlusPlus++** will listen out for messages, in channels it has been invited to, for valid commands. Commands are accepted anywhere in a message - at the beginning, middle, or end - and are currently limited to one command per message (if multiple commands are sent, only the first one found will be handled).
90+
91+
Currently supported general commands are:
92+
93+
* `@Someone++`: Adds points to a user or a thing
94+
* `@Someone--`: Subtracts points from a user or a thing
95+
96+
Currently supported extended commands are:
97+
98+
* `@WorkingPlusPlus leaderboard`: Displays the leaderboard for your Slack workspace
99+
* `@WorkingPlusPlus help`: Displays a help message showing these commands
100+
101+
If you set a different name for your bot when adding the app to your Slack workspace, use that name instead.
102+
103+
ℹ️ _Extended commands are supported if you've subscribed to the `app_mentions` event in your Slack app settings. See **Step 6** in the installation instructions above for further details._
104+
81105
## Contributing
82106

83107
Your contributions are welcome! [Create an issue](https://github.com/tdmalone/working-plusplus/issues/new) if there's something you'd like to see or [send a pull request](https://github.com/tdmalone/working-plusplus/compare) if you can implement it yourself.
@@ -89,18 +113,19 @@ For full details on contributing, including getting a local environment set up,
89113
Although it works, it's very basic. Potential enhancements include:
90114

91115
* A way to retrieve the current version/git hash from Slack, for sanity-checking of deployments
92-
* Leaderboard functionality (either, or both, via a full leaderboard on the web - with some sort of token or oauth - and a shorter leaderboard via a command in Slack)
93116
* The ability to customise the messages the bot sends back at runtime (eg. via environment variables)
94117
* Move to the newer, more secure method of calculating signatures for incoming Slack hooks
95118
* A way to look up someone's karma without necessarily `++`'ing or `--`'ing them (eg. `@username==`)
96119
* Support for posting back messages within threads, rather than automatically jumping back out to the channel
97-
* Support for detecting multiple actions within one message
120+
* Support for detecting multiple commands within one message
98121
* Natural language processing to figure out positive and negative sentiment automatically
99122
* Option to deduct karma instead of adding karma when someone tries to give themselves karma
100123
* Option to deduct karma automatically for swearing (with customisable word list?)
101124
* Record and make accessible how many karma points someone has _given_
102125
* Set up a Dockerfile to make local development easier (i.e. to not require Node, Yarn or Postgres)
103126
* Improve error handling
127+
* The ability to customise some of the leaderboard web functionality, such as colours and perhaps imagery as well
128+
* Additional linting tools for CSS and HTML
104129

105130
## License
106131

index.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99

1010
'use strict';
1111

12-
const express = require( 'express' ),
13-
slack = require( '@slack/client' ),
12+
const app = require( './src/app' ),
13+
slack = require( './src/slack' );
14+
15+
const fs = require( 'fs' ),
16+
mime = require( 'mime' ),
17+
express = require( 'express' ),
1418
bodyParser = require( 'body-parser' ),
15-
app = require( './src/app' );
19+
slackClient = require( '@slack/client' );
1620

1721
/* eslint-disable no-process-env, no-magic-numbers */
1822
const PORT = process.env.PORT || 80; // Let Heroku set the port.
@@ -33,18 +37,30 @@ const bootstrap = ( options = {}) => {
3337

3438
// Allow alternative implementations of both Express and Slack to be passed in.
3539
const server = options.express || express();
36-
app.setSlackClient( options.slack || new slack.WebClient( SLACK_OAUTH_ACCESS_TOKEN ) );
40+
slack.setSlackClient( options.slack || new slackClient.WebClient( SLACK_OAUTH_ACCESS_TOKEN ) );
3741

3842
server.use( bodyParser.json() );
3943
server.enable( 'trust proxy' );
4044
server.get( '/', app.handleGet );
4145
server.post( '/', app.handlePost );
4246

47+
// Static assets.
48+
server.get( '/assets/*', ( request, response ) => {
49+
const path = 'src/' + request._parsedUrl.path,
50+
type = mime.getType( path );
51+
52+
response.setHeader( 'Content-Type', type );
53+
response.send( fs.readFileSync( path ) );
54+
});
55+
56+
// Additional routes.
57+
server.get( '/leaderboard', app.handleGet );
58+
4359
return server.listen( PORT, () => {
4460
console.log( 'Listening on port ' + PORT + '.' );
4561
});
4662

47-
};
63+
}; // Bootstrap.
4864

4965
// If module was called directly, bootstrap now.
5066
if ( require.main === module ) {

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
const config = {
1010
collectCoverage: true,
11-
setupTestFrameworkScriptFile: 'jest-chain',
11+
setupTestFrameworkScriptFile: './jest.plugins',
1212
testEnvironment: 'node',
1313

1414
testMatch: [

jest.plugins.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Defines plugins for use with Jest.
3+
*
4+
* @see https://jestjs.io/docs/en/configuration.html#setuptestframeworkscriptfile-string
5+
*/
6+
7+
'use strict';
8+
9+
// Allows assertions to be chained together, to reduce repetition.
10+
// @see https://github.com/mattphillips/jest-chain#usage
11+
require( 'jest-chain' );
12+
13+
// Adds a bunch of additional matchers to Jest.
14+
// @see https://github.com/jest-community/jest-extended#api
15+
require( 'jest-extended' );

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lint": "eslint --color --ignore-pattern '/coverage/' --ignore-pattern '!.*.js' \"**/*.js\"",
1111
"fix": "yarn lint --fix",
1212
"test": "jest --forceExit --runInBand",
13-
"unit-tests": "SKIP_INTEGRATION_TESTS=true SKIP_E2E_TESTS=true jest",
13+
"unit-tests": "SKIP_INTEGRATION_TESTS=true SKIP_E2E_TESTS=true jest --forceExit",
1414
"integration-tests": "SKIP_E2E_TESTS=true jest --forceExit integration-tests",
1515
"e2e-tests": "SKIP_INTEGRATION_TESTS=true jest --forceExit e2e-tests",
1616
"report-coverage": "codecov && cat ./coverage/lcov.info | codacy-coverage"
@@ -29,6 +29,9 @@
2929
"@slack/client": "^4.3.1",
3030
"body-parser": "^1.18.3",
3131
"express": "^4.16.3",
32+
"handlebars": "^4.0.11",
33+
"lodash.camelcase": "^4.3.0",
34+
"mime": "^2.3.1",
3235
"pg": "^7.4.3"
3336
},
3437
"devDependencies": {
@@ -39,6 +42,7 @@
3942
"eslint-plugin-jest": "^21.18.0",
4043
"jest": "^23.4.2",
4144
"jest-chain": "^1.0.3",
45+
"jest-extended": "^0.8.1",
4246
"object-assign-deep": "^0.4.0"
4347
}
4448
}

0 commit comments

Comments
 (0)