Skip to content

Latest commit

 

History

History
65 lines (51 loc) · 3.03 KB

CONTRIBUTING.md

File metadata and controls

65 lines (51 loc) · 3.03 KB

Contributing

Setting up the bot

  1. Create a new Discord bot in the developer portal
  2. Fork the repository
  3. Clone your fork to your computer
    1. If you'd like to get a tour of the codebase and a second pair of eyes during setup, snag a slot on the calendar
  4. Copy .env.example to .env
  5. Configure env variable
    1. From the General Information page:
      1. discord-general-settings
      2. Copy the Application ID as DISCORD_APP_ID
      3. Copy the Public Key as DISCORD_PUBLIC_KEY
    2. From the Bot page:
      1. discord-bot-settings
      2. Reset the bot's token and paste the new one as DISCORD_HASH
      3. discord-token
    3. (optional) Request access token for Amplitude metrics from vcarl#7694 and paste the token as AMPLITUDE_KEY
  6. From the Bot page: 3 settings off, 2 settings on
    1. Public Bot off
    2. Requires Oauth2 Code Grant off
    3. Presence Intent off
    4. Server Members Intent on
    5. Message Content Intent on
  7. npm install
  8. npm run dev
  9. Look for the following message in the logs, and open the URL in a browser where you're logged into Discord.
    • Bot started. If necessary, add it to your test server:

Implementation notes

There are subtle issues when making some chaings. These are notes for steps to take to make sure it's done correctly when needed.

Environment variables

Adding a new environment variable needs to be done in several places to work corectly and be predictable for new developers:

  • Add a suitable example to .env.example
  • Add to your own .env (and restart the dev server)
  • Add to the action in .github/workflows/node.js.yml
  • Add to the Kubernetes config under `cluster/deployment.yml

Useful DevOps commands

This bot runs on a managed Kubernetes cluster on DigitalOcean. It's possible (tho beyond the scope of this document) to configure a local kubectl environment to access and control this cluster. What follows are reference commands for performing common tasks:

# Tail the logs of the production instance
kubectl logs -f mod-bot-set-0

# Force a restart without merging a PR (as of 2024-09 only 1 replica is in use)
kubectl scale statefulset mod-bot-set --replicas 0
kubectl scale statefulset mod-bot-set --replicas 1

# Copy out the production database (for backups!)
kubectl cp mod-bot-set-0:data/mod-bot.sqlite3 ./mod-bot-prod.sqlite3

# Execute a command on the production instance.
# Rarely necessary, but useful for diagnostics if something's gone sideways.
kubectl exec mod-bot-set-0 -- npm run start:migrate

# Extract production secrets (in base64)
kubectl get secret modbot-env -o json