Skip to content

bclingan/metric_units_reddit_bot

 
 

Repository files navigation

Build status

What does the bot do?

The bot finds comments with imperial units, and replies with metric units. See ./test/converter-test.js for what conversions are currently supported, and see Pivotal Tracker for what's coming up next.

There is a chance it will reply to certain triggers like "good bot". See personality-test.js for what the triggers are.

How does the code work?

This is a javascript app built with Node.js, and all of the app code is in the src directory.

The app starts in bot.js, and it polls the Reddit servers in an infinite loop. The app has two major components:

converter.js and conversion_helper.js are responsible for converting imperial units to metric units.

personality.js create sassy responses to certain trigger words

Running the code (in Production)

Create your bot's reddit account.

Create a reddit script app through your reddit preferences. (Use http://localhost as your redirect url, we don't need it.) From there, you should be able to get your OAuth username and secret

Download the bot's code, and create a file ./private/environment.yaml that looks like sample-environment.yaml

run npm install then node ./src/bot.js and you should have the bot up and running!

Note: The bot sometimes "skips" comments during polling. To reduce the changes of this happening when testing, you can limit the bot to look a single subreddit instead of "r/all" by changing the line network.getRedditComments("all") in bot.js. I recommend running it in r/test (network.getRedditComments("test"))!

Running the tests

run npm test

To run a single spec, add .only

Git hooks

The pre-commit hook will run before each commit. It will only allow code to be committed if the following preconditions are met:

  • There are no failing tests
  • All tests are run (no .only() statements isolating tests)
  • There are no unnecessary console.log statements

To enable git hooks, copy the file pre-commit into your ./.git/hooks/ directory

Questions or Comments?

Feel free to message me on reddit or open a github issue

Contribute

Metric Units Bot is participating in Hacktoberfest! See a list of things we need help with and win free T-shirts! You can also take a look at what's in Pivotal Tracker or come up with your own improvements

Feedback & code reviews are always welcome.

License

This source is distributed under GNU GPLv3

Pull requests or derivative works welcome. but please don't make a freedom_units_bot just to spite me D:

About

Reddit bot converting imperial units to metric units

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.2%
  • Shell 0.8%