Skip to content

Latest commit

 

History

History
59 lines (47 loc) · 2.92 KB

README.md

File metadata and controls

59 lines (47 loc) · 2.92 KB

ThoughtBot

About

A Discord bot made using TypeScript and Node.js that uses the Twitter API to request and store tweets at a specified interval, then processes those tweets using a Markov chain to generate a tweet of its own.

Usage

  • Looks for environment variables for initialisation it’s easiest to just place these into a .env file at the root of the project or modify the host’s environment variables through the provided interface (e.g. Heroku Config vars).
  • These are:
Name Description
BOT_CLIENT_ID The client id for the bot provided by Discord
DISCORD_TOKEN Token provided by Discord
TWITTER_CONSUMER_KEY Consumer key provided by Twitter
TWITTER_CONSUMER_SECRET Twitter consumer secret key provided by Twitter
TWITTER_BEARER_TOKEN Generated by the user
COMMAND_PREFIX The desired command prefix e.g. % command
DB_LOCATION Expected path of the sqlite database
NUMBER_OF_HASHTAGS Number of hashtags to grab at each cycle
UPDATE_INTERVAL_MINS Delay between grab cycles

To start just run npm start or make it your container's entry point.

Commands

The prefix will change depending on the one you specified however for the following examples we will use %.

Command Description
% help Retrieve a list of all registered commands.
% randomtweet [query] Grab a random tweet matching provided query
% trendinghashtags [woeid] Get the trending tweets in a provided woeid (can be found at http://woeid.rosselliot.co.nz/)
% register (Requires admin role or equivalent) Registers current channel to receive the daily digest for the pointed to location (Defaults to LA)
% unregister (Requires admin role or equivalent) Unregister channel from target channels

Adding a command

To add a command simply ensure that it extends AbstractCommand and is found in the commands directory, if there are no errors it should be automatically loaded on startup.

What I've learnt

  • TypeScript
  • Async/await and callbacks
  • Node.js and npm (including writing debug and prod scripts in package.json)
  • Dynamic Modules (Loading all commands in a given directory at runtime instead of manually importing them)
  • Simple SQL and migrations (SQLite)
  • API consumption (twitter and discord)
  • Timed events via javascript (using setInterval and setTimeout)
  • Managing and loading environment variables to keep secrets (API keys, database credentials...)
  • Dealing with commercial cloud hosted virtual production environments e.g. Heorku

Future of ThoughtBot

I am not planning to continue adding features to ThoughtBot, however I would like to continue to fix existing issues and polish existing features. Some of these goals are:

  • Create my own Markov chain implementation in C++ and compile to wasm.
  • Move to a hosted database (MongoDB or PostgreSQL)

Feel free to make a pull request or issue if you feel you have anything to contribute.

Licence

This project is licensed under GNU GPL3!