Skip to content
Linna La edited this page May 24, 2020 · 7 revisions

Follow these instructions to get Siero running on your local machine for development purposes.


Just a second!

This guide assumes you're using a Mac for development. If you're using Linux, you can probably follow along, but Windows users are out of luck for now. Sorry!


Dependencies

Let's start by making sure you have the project dependencies installed. Siero requires Node.js, NPM and Postgres to run.

Homebrew is a dependency manager that will help us install the actual project dependencies

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Next, we'll use Homebrew to install the aforementioned dependencies. Node.js will automatically install NPM for us.

brew install node postgresql

Make sure you have the repository cloned. Then from the root folder, we're going to install all of the project's node dependencies. After installing, the JS files will go through the build process.

npm install

Setting up your database

There's a few post-install steps for configuring your Postgres database.

First, we'll set Homebrew to start Postgres when you log in to your machine. This is taken from Terminal after installation. If your Terminal says something different, follow those instructions instead of Siero's for this step.

brew services start postgresql

Next, we're going to create the database for Siero.

# Enter the interactive Postgres terminal
psql

# Create a new database for Siero
CREATE DATABASE siero_bot;

# Exit the interactive Postgres terminal
\q

Now, we're going to create the tables on our new database.

# Before executing, make sure you've pointed your Terminal to the place you cloned this repo
psql -d siero_bot -a -f resources/startup.pgsql

Finally, we'll import all of the gacha items into the database.

# Enter the interactive Postgres terminal
psql

# Connect to the newly created database
/connect siero_bot

# Import all of the items from resources/gacha.csv to the database
# Make sure to replace <path_to_csv> with the absolute path on your machine!
COPY gacha(name, rarity, item_type, recruits, premium, flash, legend, valentine, summer, halloween, holiday) FROM <path_to_csv> DELIMITER ',' CSV HEADER;

# Exit the interactive Postgres terminal
\q

Get a test server goin'

In order to test Siero, you need to create a server to add her to.

Next, you'll need to spin up your own Siero bot. Start a Discord app and in the Bot tab, create a bot.

In the OAuth2 tab, add the bot scope with Manage Messages permissions. Copy the generated URL into a browser window and select your test server to invite your new Siero into.

Lastly, go back to the Bot tab and click to copy your bot's secret token; you will need it in the next step.

Final setup

Finally, we have to fill out our environment variables in .env. Create a .env file in the project root folder (touch .env) and add the following to the file:

# This tells the bot to connect to the database with development credentials.
NODE_ENV = development

# This is your Discord bot's secret token, instructions above.
DISCORD_SECRET = <your secret token>

# This is your Postgres database information.
# By default, the username and password should be empty.
PG_USER = 
PG_HOST = localhost
PG_DB = siero_bot
PG_PASSWORD = 

Running Siero

Finally, you can run Siero with this handy npm script.

npm run start

The command runs nodemon alongside the TypeScript compiler in watch mode. nodemon will automatically restart your bot when it detects changes, so you don't have to constantly stop and start the bot while you're working.

Available Scripts

Here are some helpful npm scripts you can use in case something goes wrong.

# Clear the current build files and recompile when things are wonky.
# Note: this also runs automatically after doing npm install.
npm run build-ts

# Start up your bot for development. The server will pick up changes on save.
npm run start

# Serve your bot with the current build files.
npm run serve

# Run tests.
npm run test