diff --git a/.dockerignore b/.dockerignore index eaecf905..082450d8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -10,9 +10,9 @@ config/local.json # Ignore all md files *.md -# Ignore all hidden files(git, travis, docker, etc) +# Ignore all hidden files (git, travis, docker, etc) .* # Ignore all docker files Dockerfile -docker-compose*.yml \ No newline at end of file +docker-compose*.yml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 06384841..32ba1ebc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,7 +7,7 @@ To give a basic setup procedure: - Create a personal bot here: (you will need multiple for sub-bots) https://discordapp.com/developers/applications/ - Update your config files with the parameters you have created with your bots and servers - Install and run docker -- Run the project using `docker-compose up --build` +- Run the project using `npm run up` # Installing Docker @@ -19,61 +19,11 @@ We **HIGHLY** recommend the use of Docker in order to run DIGBot. This will ensu # Your local config files -You need a file at config/envConfig.js, this should be git Ignored. You will need to change all parameters in the config/envConfig.js and config/development/\*.js files to ensure they match your personal development discord server and bot API keys and such. It is **CRITICAL** that you keep these files out of the commit history by use of a command such as `git update-index --assume-unchanged config/envConfig.js` if necessary to keep private keys secure +You need a file at config/local.json, this should be git Ignored. You will need to change all parameters in the config/local.json file to ensure they match your personal development discord server and bot API keys and such, to accomplish this you may use config.local.json.example as a guide. It is **CRITICAL** that you keep these files out of the commit history by use of a command such as `git update-index --assume-unchanged config/local.json` if necessary to keep private keys secure. # Code style Guide -### Control structures - -``` -// Functions -function { - ... -} - -// IF statements -if (! ) { - ... -} else if () { - ... -} else { - ... -} - -// For loops -for (let count = 0; count > ; count++) { - ... -} - -// While loops -while (something !== something) { - ... -} - -``` -### Module variables declarations - -``` -"use strict"; - -const someVar = something; -let someGlobalVar = something; - -modules.exports = { - someFunction: function () { - ... - }, - someOtherFunction: someNonModularFunction // Pointing to a normal function -} - -function someNonModularFunction { - ... -} - -``` -### Module organization - -- Comply with Atom JSLinter and JSCS plugins. Added the .jscsrc file to master so it can be consistent across all developers. (This will soon change to a CI process) +- Comply with the .jscsrc file, you may use a linter in your IDE to assist you in this however how this is accomplished will depend on your IDE. Style is automatically reviewed in PRs through our CI process. - Leave a summary comment at the top of each module explaining its purpose - Sort functions alphabetically unless using getter and setter functions, example: ``` @@ -83,12 +33,15 @@ setSomething() getSomethingElse() setSomethingElse() ``` -- If the purpose of a function is not immediately apparent leave a short comment -- Ensure promise resolutions/rejections are handled -- Embed promise structures, see code for examples +- If the purpose of a function is not immediately apparent leave a short comment. Please keep in mind our comments are intended to be read by recreational developers, not professsionals. +- Ensure promise resolutions/rejections are always handled +- Please keep in mind due to API ping a lot of our code must be designed with asynchronicity in mind +- Where possible guard against common errors and handle them through our logger (src/lib.logger.js) ### Module testing +If it can be tested it should be tested, test coverage should be as high as possible. Tests are conducted automatically on all PRs by Travis. + For testing this codebase uses Chai and Sinon with Mocha as runner. Mocha allows organisation of tests by means of describing testable code blocks and tests that needs passing. Most tests use the `should` variant of Chai, with diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 00000000..4340c33c --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 DIG Development Team + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 2ead5a8a..f33f1de1 100644 --- a/README.md +++ b/README.md @@ -105,15 +105,17 @@ Some channels the community would prefer to always have a free version of. This The bot uses docker 1.13.0+. Installation instructions can be found here: https://docs.docker.com/install/ -### From Docker Hub +### Deployment via Docker Hub -It is possible to pull the latest image from Docker Hub using `docker pull dignityofwar/digbot`. Check the readme file in config to configure the bot correctly. +Docker Hub automatically builds and stores docker images of staging and master (our production branch). We deploy the bot using the latest docker images from Docker Hub using `docker pull dignityofwar/digbot`. ### From the repository -To run the bot locally use `npm run docker:start`, to check the logs use `npm run docker:logs`, and to stop the container and remove it use `npm run docker:stop`. To quickly run the container and view it's logs use `npm run up`, and for taking it down use `npm run down`. The local.json config file will be automatically linked to the container. It is possible to run the bot without docker using `npm start`, but this is not recommended. +To run the bot locally use `npm run up`, and to stop the container and remove it use `npm run down`. The local.json config file will be automatically linked to the container. -To run the tests you use `npm test` (this will also link the local.json config file). It is possible to run it without docker using `npm run mocha`, but this is not recommended. +To run the tests you use `npm test` (this will also link the local.json config file). + +It is of course possible to run it without docker, but this is not recommended. ## Development @@ -123,11 +125,11 @@ See the [contribution guidelines](CONTRIBUTING.md) file for information on how t ### Code Usage -The project is in the process of being open sourced however as of this moment no usage licence is provided. +The project is open-sourced under the [MIT license](LICENSE.md). ### Acknowledgements -This repository was created from an [existing private codebase](https://github.com/JamesLongman/DIGBot/releases/tag/0.0.1) for DIGBot which can be found. The previous project was headed by Maelstromeous who was ultimately responsible for code review, design decisions and deployment. +This repository was created from an [existing private codebase](https://github.com/JamesLongman/DIGBot/releases/tag/0.0.1). The previous project was headed by Maelstromeous who was ultimately responsible for code review, design decisions and deployment. File contributions were as follows Maelstromeous: 510 commits, 7,623 additions, 6,378 deletions diff --git a/src/lib/commands/stats.js b/src/lib/commands/stats.js index a139b85b..0b576b85 100644 --- a/src/lib/commands/stats.js +++ b/src/lib/commands/stats.js @@ -5,9 +5,9 @@ // !stats module const config = require('config'); -const pjson = require('../../../package'); const logger = require('../logger.js'); const performance = require('../tools/performance.js'); +const pjson = require('../../../package'); const server = require('../server/server.js'); const TAG = '!stats'; diff --git a/src/lib/discord/bot-events.js b/src/lib/discord/bot-events.js index 3f995925..84d4fe87 100644 --- a/src/lib/discord/bot-events.js +++ b/src/lib/discord/bot-events.js @@ -11,6 +11,7 @@ const directMessage = require('./direct-message.js'); const crashHandler = require('../crash-handling.js'); const logger = require('../logger.js'); const nameCheck = require('../welcomepack/namecheck.js'); +const pjson = require('../../../package.json'); const server = require('../server/server.js'); const subBots = require('../sub-bots/sub-bots.js'); const welcome = require('../welcomepack/welcomepack.js'); @@ -185,7 +186,7 @@ module.exports = { if (server.getBooted() === false) { if (server.getChannel('developers') !== null) { - server.getChannel('developers').sendMessage(`DIGBot, reporting for duty! Environment: ${config.util.getEnv('NODE_ENV')}`) + server.getChannel('developers').sendMessage(`DIGBot, reporting for duty! Environment: ${config.util.getEnv('NODE_ENV')}, Version: ${pjson.version}`) .then( logger.debug(TAG, 'Succesfully sent message') )