What | Badge |
---|---|
Master Build | |
Staging Build | |
Maintainability | |
Test Coverage | |
GreenKeeper |
A Discord bot for the Cascades Tech Club Discord server. To add a command, see the Commands section below.
To work on hackbot, you should:
- Clone this repository:
git clone https://github.com/osu-cascades/hackbot.git
- Install the latest node.js.
- Install the dependencies:
cd hackbot && npm install
- Log in to Discord, visit the Developer resources interface, and navigate to the My Apps screen.
- Add a new app and give it a name, eg. hackbot-myname-dev.
- Click the Create a Bot User button.
- Notice the Client ID, reveal your app's Token, and record them both for later.
- Visit https://discordapp.com/oauth2/authorize?client_id=INSERT_CLIENT_ID_HERE&scope=bot&permissions=0, replacing the placeholder with your real Client ID.
- Select the server that you want the bot to join.
- Copy the hidden .env-example file to .env, and replace the placeholder values with your own.[1]
- Run the bot from the command line:
npm start
- Hack...
[1] The !search command requires a Google API key from the Google API Console and the !weather command requires an API key from OpenWeather.org
In a nutshell, work in the dev branch and don't merge to master unless:
- You've communicated your changes to others and given folks a little time to respond (or ideally, do a code review).
- Your changes are innocuous.
In all cases, be sure to run the test suite to make sure all tests pass. All tests should be passing before you merge dev to master.
You should embrace testing. hackbot uses the Jest test framework. Have two console panes open: one for running and watching the test suite, and the other for everything else you need to do. You can run the test suite once with npm test
. Once you get tired of running npm test
manually, use the watcher by running npm run test:watch
. It is sweet and people will think you are a super hacker. Look at __tests__/commands/add.test.ts
for an example of how to test commands and their channel messages. If you use VSCode for your IDE there's a Jest extension that will run a watcher and give you inline updates on your tests, as well as a few other awesome features!
Please refer to airbnb's style guide while coding.
For now try to keep the linter happy. You can see any lint issues by running npm run lint
. Some issues can be auto-fixed with npm run lint:fix
To enable hackbot to respond to a new command, all you need to do is:
- Copy the existing src/commands/_template.js to a new, well-named js file in the commands directory:
cp src/commands/_template.ts src/commands/foo.ts
. - In your new js file, replace occurrences of
CommandName
with your actual command name. Ensure that this js file contains a class definition that extendsCommand
and implements the staticdescription
andexecute
methods. See add.js or say.js for some simple examples.
Hackbot is hosted on Heroku as two worker-based applications:
- osu-hackbot
- osu-hackbot-staging
Once you're happy with your new hackbot feature running on your development environment, deploy it to staging so that the bot stays running and other people can try it out. This bot is always named hackbot-staging. Once you're happy, you can deploy it to production; this bot is always named hackbot.
- Get a Heroku account.
- Install the Heroku CLI.
- Become a collaborator on the staging and production apps (ask others how).
- Add the remotes for staging and production:
heroku git:remote -a osu-hackbot -r production && heroku git:remote -a osu-hackbot-staging -r staging
- Deploy to staging:
git push staging
orgit push staging dev:master
orgit push staging feature-branch-name:master
. - Deploy to production:
git push production
.
- Creating a Discord bot and getting a token
- Tutorial: Creating a Simple Discord Bot
- Video Series: Creating a Discord bot with Discord.js!
- Deploying a Bot on Heroku
- discord.js Documentation
©2018 All rights reserved.
Thanks to our contributors!