Skip to content

osu-cascades/hackbot

Repository files navigation

hackbot

What Badge
Master Build Build Status
Staging Build Build Status
Maintainability Maintainability
Test Coverage Test Coverage
Snyk Known Vulnerabilities

A Discord bot for the Cascades Tech Club Discord server. To add a command, see the Commands section below.

Setup

To work on hackbot, you should:

  1. Clone this repository: git clone https://github.com/osu-cascades/hackbot.git
  2. Install the latest node.js.
  3. Install the dependencies: cd hackbot && npm install
  4. Log in to Discord, visit the Developer resources interface, and navigate to the My Apps screen.
  5. Add a new app and give it a name, eg. hackbot-myname-dev.
  6. Click the Create a Bot User button.
  7. Notice the Client ID, reveal your app's Token, and record them both for later.
  8. Visit https://discordapp.com/oauth2/authorize?client_id=INSERT_CLIENT_ID_HERE&scope=bot&permissions=0, replacing the placeholder with your real Client ID.
  9. Select the server that you want the bot to join.
  10. Copy the hidden .env-example file to .env, and replace the placeholder values with your own.[1]
  11. Run the bot from the command line: npm start
  12. 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

Suggested Workflow

In a nutshell, work in the dev branch and don't merge to master unless:

  1. You've communicated your changes to others and given folks a little time to respond (or ideally, do a code review).
  2. 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

Commands

To enable hackbot to respond to a new command, all you need to do is:

  1. 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.
  2. In your new js file, replace occurrences of CommandName with your actual command name. Ensure that this js file contains a class definition that extends Command and implements the static description and execute methods. See add.js or say.js for some simple examples.

Deploying

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.

  1. Get a Heroku account.
  2. Install the Heroku CLI.
  3. Become a collaborator on the staging and production apps (ask others how).
  4. Add the remotes for staging and production: heroku git:remote -a osu-hackbot -r production && heroku git:remote -a osu-hackbot-staging -r staging
  5. Deploy to staging: git push staging or git push staging dev:master or git push staging feature-branch-name:master.
  6. Deploy to production: git push production.

References


©2018 All rights reserved.

Thanks to our contributors!