Skip to content
This repository has been archived by the owner on Apr 2, 2022. It is now read-only.
/ habitica-bot Public archive

⚒ A Cloudflare Worker that makes use of the Habitica API and Discord Webhooks

Notifications You must be signed in to change notification settings

mornir/habitica-bot

Repository files navigation

🤖 Discord Habitica Bot

A Cloudflare Worker that makes use of the Habitica API and Discord Webhooks

I blogged about it, but since then I moved to using Wrangler, which offers much more features:

  • Modules
  • TypeScript
  • npm packages

How things work

The reason the worker returns messages as JSON is only for testing purposes, so that I can make assertions on the response.

Deployments to Cloudflare (dev + production) is done via GitHub Actions

Commands

Environments

test

This is environment is only for E2E testing with Cypress running against localhost. It sets the ENVIRONMENT variable to "test" and prevents real API calls (to Discord or Habitica) to be made. This environment is listed as habitica-bot-test in wrangler.toml, but it is NOT deployed to Cloudflare.

Command: yarn test-server (with hot reloading!) Testing (with UI): yarn test Testing (without UI, faster): yarn test:ci

dev (staging)

This is the default environment: when no argument is provided to the wrangler CLI, it assumes dev. The corresponding branch on GitHub is named staging. Standard staging environment. Deployed to Cloudflare worker as habitica-bot-dev. Messages are posted to a dedicated Discord server for testing.

Command: yarn dev (with hot reloading!)

production

Production worker. Messages are posted to the Habitica Discord server. The corresponding branch on GitHub is named master.

Exception and Error Handling

The worker always returns a 200 success code, even if errors are thrown. The reason is:

Best practice is to respond to the Habitica server as soon as you receive a request with a 200 HTTP code and a non-empty response https://habitica.fandom.com/wiki/Webhooks

However, errors thrown are sent to Sentry.io before the success code is returned.

GIFs

Damage

Damage dealt > 40

That's a lot of damage

Damage dealt 20-40

That's quite a bit of damage

Damage sustained > 8

I'm hit!

Quest

Quest invitation

Gandalf Looking For Adventure

Quest starting

Adventure Hobbit

Gandalf Prepare for Battle

Quest finished

Hobbits clapping

About

⚒ A Cloudflare Worker that makes use of the Habitica API and Discord Webhooks

Topics

Resources

Stars

Watchers

Forks